Search in sources :

Example 1 with UsernamePasswordAuthenticationToken

use of org.acegisecurity.providers.UsernamePasswordAuthenticationToken in project hudson-2.x by hudson.

the class ClientAuthenticationCache method get.

/**
     * Gets the persisted authentication for this Hudson.
     *
     * @return {@link Hudson#ANONYMOUS} if no such credential is found, or if the stored credential is invalid.
     */
public Authentication get() {
    Hudson h = Hudson.getInstance();
    Secret userName = Secret.decrypt(props.getProperty(getPropertyKey()));
    // failed to decrypt
    if (userName == null)
        return Hudson.ANONYMOUS;
    try {
        UserDetails u = h.getSecurityRealm().loadUserByUsername(userName.toString());
        return new UsernamePasswordAuthenticationToken(u.getUsername(), u.getPassword(), u.getAuthorities());
    } catch (AuthenticationException e) {
        return Hudson.ANONYMOUS;
    } catch (DataAccessException e) {
        return Hudson.ANONYMOUS;
    }
}
Also used : Secret(hudson.util.Secret) UserDetails(org.acegisecurity.userdetails.UserDetails) AuthenticationException(org.acegisecurity.AuthenticationException) Hudson(hudson.model.Hudson) UsernamePasswordAuthenticationToken(org.acegisecurity.providers.UsernamePasswordAuthenticationToken) DataAccessException(org.springframework.dao.DataAccessException)

Example 2 with UsernamePasswordAuthenticationToken

use of org.acegisecurity.providers.UsernamePasswordAuthenticationToken in project hudson-2.x by hudson.

the class HudsonPrivateSecurityRealm method loginAndTakeBack.

/**
     * 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);
}
Also used : Authentication(org.acegisecurity.Authentication) UsernamePasswordAuthenticationToken(org.acegisecurity.providers.UsernamePasswordAuthenticationToken)

Aggregations

UsernamePasswordAuthenticationToken (org.acegisecurity.providers.UsernamePasswordAuthenticationToken)2 Hudson (hudson.model.Hudson)1 Secret (hudson.util.Secret)1 Authentication (org.acegisecurity.Authentication)1 AuthenticationException (org.acegisecurity.AuthenticationException)1 UserDetails (org.acegisecurity.userdetails.UserDetails)1 DataAccessException (org.springframework.dao.DataAccessException)1