Package org.acegisecurity.providers

Examples of org.acegisecurity.providers.UsernamePasswordAuthenticationToken


public class AcegiWorkflowContextHandlerInterceptorTests extends AbstractWorkflowContextHandlerInterceptorTests {


  protected MockHttpServletRequest getMockRequest(String userName) {
    User user = new User(userName, "dummy", true, true, true, true, new GrantedAuthority[]{});
    Authentication auth = new UsernamePasswordAuthenticationToken(user, null);
    SecurityContext context = new SecurityContextImpl();
    context.setAuthentication(auth);
    SecurityContextHolder.setContext(context);

    return new MockHttpServletRequest();
View Full Code Here


public class AcegiRoleConditionTests extends TestCase {

  public void setUp() {
    GrantedAuthority[] roles = new GrantedAuthority[]{new GrantedAuthorityImpl("manager"), new GrantedAuthorityImpl("vp")};

    Authentication authentication = new UsernamePasswordAuthenticationToken(new Object(), new Object(), roles);

    SecurityContext context = new SecurityContextImpl();
    context.setAuthentication(authentication);

    SecurityContextHolder.setContext(context);
View Full Code Here

      username = "";
    }
    if (password == null) {
      password = "";
    }
    UsernamePasswordAuthenticationToken authRequest = null;
    if (caid == null || caid.length() == 0) {
      if (StringUtils.isNotEmpty(aduser)) {
        // ad登录
        this.checkCodeValide(request);
        authRequest = new CustomUsernameAuthenticationToken(aduser);
        request.getSession().setAttribute(
            ACEGI_SECURITY_LAST_USERNAME_KEY, username);

      } else {
        if ((epdlh == null || epdlh.length() == 0)) {
          this.checkCodeValide(request);
        }
        authRequest = new UsernamePasswordAuthenticationToken(username, password);
        // Place the last username attempted into HttpSession for views
        request.getSession().setAttribute(ACEGI_SECURITY_LAST_USERNAME_KEY, username);
      }

    } else {
View Full Code Here

    /**
     * Lets the current user silently login as the given user and report back accordingly.
     */
    private void loginAndTakeBack(StaplerRequest req, StaplerResponse rsp, User u) throws ServletException, IOException {
        // ... and let him login
        Authentication a = new UsernamePasswordAuthenticationToken(u.getId(),req.getParameter("password1"));
        a = this.getSecurityComponents().manager.authenticate(a);
        SecurityContextHolder.getContext().setAuthentication(a);

        // then back to top
        req.getView(this,"success.jelly").forward(req,rsp);
View Full Code Here

        Jenkins h = Jenkins.getInstance();
        Secret userName = Secret.decrypt(props.getProperty(getPropertyKey()));
        if (userName==null) return Jenkins.ANONYMOUS; // failed to decrypt
        try {
            UserDetails u = h.getSecurityRealm().loadUserByUsername(userName.getPlainText());
            return new UsernamePasswordAuthenticationToken(u.getUsername(), "", u.getAuthorities());
        } catch (AuthenticationException e) {
            return Jenkins.ANONYMOUS;
        } catch (DataAccessException e) {
            return Jenkins.ANONYMOUS;
        }
View Full Code Here

     * @since 1.419
     */
    public Authentication impersonate() {
        try {
            UserDetails u = Jenkins.getInstance().getSecurityRealm().loadUserByUsername(id);
            return new UsernamePasswordAuthenticationToken(u.getUsername(), "", u.getAuthorities());
        } catch (AuthenticationException e) {
            // TODO: use the stored GrantedAuthorities
            return new UsernamePasswordAuthenticationToken(id, "",
                new GrantedAuthority[]{SecurityRealm.AUTHENTICATED_AUTHORITY});
        }
    }
View Full Code Here

            throw new AuthenticationException( "Unable to build authentication token, missing token '" + TOKEN_PASSWORD
                + "'" );
        }
        else
        {
            return new UsernamePasswordAuthenticationToken( username, password );
        }

    }
View Full Code Here

                if (password==null)
                    throw new BadCredentialsException("No password specified");

                UserDetails d = AbstractPasswordBasedSecurityRealm.this.authenticate(userName, password);
                return new UsernamePasswordAuthenticationToken(d, password, d.getAuthorities());
            }
        };
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    protected UserDetails authenticate(String username, String password) throws AuthenticationException {
        return (UserDetails) getSecurityComponents().manager.authenticate(
          new UsernamePasswordAuthenticationToken(username, password)).getPrincipal();
    }
View Full Code Here

            User u = locateUser();
            if (u!=null) {
                // login as this user
                UserDetails d = Jenkins.getInstance().getSecurityRealm().loadUserByUsername(u.getId());

                UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(d,"",d.getAuthorities());
                token.setDetails(d);
                SecurityContextHolder.getContext().setAuthentication(token);
                return u;
            } else {
                // Unassociated identity.
                throw new UnclaimedIdentityException(this);
View Full Code Here

TOP

Related Classes of org.acegisecurity.providers.UsernamePasswordAuthenticationToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.