Examples of UsernamePasswordAuthenticationToken


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

Examples of org.acegisecurity.providers.UsernamePasswordAuthenticationToken

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

Examples of org.acegisecurity.providers.UsernamePasswordAuthenticationToken

      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

Examples of org.acegisecurity.providers.UsernamePasswordAuthenticationToken

    /**
     * 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

Examples of org.acegisecurity.providers.UsernamePasswordAuthenticationToken

        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

Examples of org.acegisecurity.providers.UsernamePasswordAuthenticationToken

     * @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

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

                        user.getCipherAlgorithm(),
                        user.getPassword());
            }
        }

        UsernamePasswordAuthenticationToken token;

        if (authenticated) {
            token = new UsernamePasswordAuthenticationToken(
                    authentication.getPrincipal(),
                    null,
                    userDetailsService.loadUserByUsername(authentication.getPrincipal().toString()).getAuthorities());

            token.setDetails(authentication.getDetails());

            auditManager.audit(Category.authentication, AuthenticationSubCategory.login, Result.success,
                    "Successfully authenticated, with roles: " + token.getAuthorities());

            LOG.debug("User {} successfully authenticated, with roles {}",
                    authentication.getPrincipal(), token.getAuthorities());

            if (user != null) {
                user.setLastLoginDate(new Date());
                user.setFailedLogins(0);
                userDAO.save(user);
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        }

        final UserDetails userDetails = new User("admin", "FAKE_PASSWORD", true, true, true, true, authorities);

        SecurityContextHolder.getContext().setAuthentication(
                new UsernamePasswordAuthenticationToken(userDetails, "FAKE_PASSWORD", authorities));

        try {
            return executeWithSecurityContext(dryRun);
        } finally {
            // POST: clean up the SecurityContextHolder
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

            return new LoginStatus(false, null, auth.getAuthorities());
        }
    }

    public LoginStatus login(String username, String password) {
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
        logger.debug("Attempting login.");
        try {
            Authentication auth = authenticationManager.authenticate(token);
            logger.debug("Login succeeded!");
            SecurityContextHolder.getContext().setAuthentication(auth);
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        public boolean validate(PasswordValidationCallback.Request request)
                throws PasswordValidationCallback.PasswordValidationException {
            PasswordValidationCallback.PlainTextPasswordRequest plainTextRequest =
                    (PasswordValidationCallback.PlainTextPasswordRequest) request;
            try {
                Authentication authResult = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(
                        plainTextRequest.getUsername(), plainTextRequest.getPassword()));
                if (logger.isDebugEnabled()) {
                    logger.debug("Authentication success: " + authResult.toString());
                }
                SecurityContextHolder.getContext().setAuthentication(authResult);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.