Search in sources :

Example 1 with User

use of net.sf.acegisecurity.providers.dao.User in project alfresco-repository by Alfresco.

the class AbstractAuthenticationComponent method setCurrentUserImpl.

/**
 * Explicitly set the current user to be authenticated.
 *
 * @param userName
 *            String
 * @return Authentication
 */
private Authentication setCurrentUserImpl(String userName) throws AuthenticationException {
    if (userName == null) {
        throw new AuthenticationException("Null user name");
    }
    if (isSystemUserName(userName)) {
        return setSystemUserAsCurrentUser(getUserDomain(userName));
    }
    try {
        UserDetails ud = null;
        if (isGuestUserName(userName)) {
            String tenantDomain = getUserDomain(userName);
            if (logger.isTraceEnabled()) {
                logger.trace("Setting the current user to the guest user of tenant domain \"" + tenantDomain + '"');
            }
            GrantedAuthority[] gas = new GrantedAuthority[0];
            ud = new User(userName, "", true, true, true, true, gas);
        } else {
            if (logger.isTraceEnabled()) {
                logger.trace("Setting the current user to \"" + AuthenticationUtil.maskUsername(userName) + '"');
            }
            ud = getUserDetails(userName);
            if (!userName.equals(ud.getUsername())) {
                ud = new User(userName, ud.getPassword(), ud.isEnabled(), ud.isAccountNonExpired(), ud.isCredentialsNonExpired(), ud.isAccountNonLocked(), ud.getAuthorities());
            }
        }
        return setUserDetails(ud);
    } catch (net.sf.acegisecurity.AuthenticationException ae) {
        throw new AuthenticationException(ae.getMessage(), ae);
    }
}
Also used : UserDetails(net.sf.acegisecurity.UserDetails) User(net.sf.acegisecurity.providers.dao.User) GrantedAuthority(net.sf.acegisecurity.GrantedAuthority)

Example 2 with User

use of net.sf.acegisecurity.providers.dao.User in project alfresco-repository by Alfresco.

the class AbstractAuthenticationComponent method getUserDetails.

/**
 * Default implementation that makes an ACEGI object on the fly
 *
 * @param userName String
 * @return UserDetails
 */
protected UserDetails getUserDetails(String userName) {
    GrantedAuthority[] gas = new GrantedAuthority[1];
    gas[0] = new GrantedAuthorityImpl("ROLE_AUTHENTICATED");
    UserDetails ud = new User(userName, "", true, true, true, true, gas);
    return ud;
}
Also used : UserDetails(net.sf.acegisecurity.UserDetails) User(net.sf.acegisecurity.providers.dao.User) GrantedAuthorityImpl(net.sf.acegisecurity.GrantedAuthorityImpl) GrantedAuthority(net.sf.acegisecurity.GrantedAuthority)

Example 3 with User

use of net.sf.acegisecurity.providers.dao.User in project alfresco-repository by Alfresco.

the class TestAuthenticationServiceImpl method getUserDetails.

/**
 * Default implementation that makes an ACEGI object on the fly
 *
 * @param userName
 * @return
 */
protected UserDetails getUserDetails(String userName) {
    GrantedAuthority[] gas = new GrantedAuthority[1];
    gas[0] = new GrantedAuthorityImpl("ROLE_AUTHENTICATED");
    UserDetails ud = new User(userName, "", true, true, true, true, gas);
    return ud;
}
Also used : UserDetails(net.sf.acegisecurity.UserDetails) User(net.sf.acegisecurity.providers.dao.User) GrantedAuthorityImpl(net.sf.acegisecurity.GrantedAuthorityImpl) GrantedAuthority(net.sf.acegisecurity.GrantedAuthority)

Example 4 with User

use of net.sf.acegisecurity.providers.dao.User in project alfresco-repository by Alfresco.

the class AuthenticationContextImpl method setSystemUserAsCurrentUser.

public Authentication setSystemUserAsCurrentUser(String tenantDomain) {
    GrantedAuthority[] gas = new GrantedAuthority[1];
    gas[0] = new GrantedAuthorityImpl("ROLE_SYSTEM");
    return setUserDetails(new User(getSystemUserName(tenantDomain), "", true, true, true, true, gas));
}
Also used : User(net.sf.acegisecurity.providers.dao.User) GrantedAuthorityImpl(net.sf.acegisecurity.GrantedAuthorityImpl) GrantedAuthority(net.sf.acegisecurity.GrantedAuthority)

Example 5 with User

use of net.sf.acegisecurity.providers.dao.User in project alfresco-repository by Alfresco.

the class PermissionServiceImpl method getCoreAuthorisations.

/**
 * Get the core authorisations for this {@code auth}. If {@code null} this
 * will be an empty set. Otherwise it will be a Lazy loaded Set of authorities
 * from the authority node structure PLUS any granted authorities.
 */
protected Set<String> getCoreAuthorisations(Authentication auth) {
    if (auth == null) {
        return Collections.<String>emptySet();
    }
    User user = (User) auth.getPrincipal();
    String username = user.getUsername();
    Set<String> auths = authorityService.getAuthoritiesForUser(username);
    auths.add(username);
    for (GrantedAuthority grantedAuthority : auth.getAuthorities()) {
        auths.add(grantedAuthority.getAuthority());
    }
    return auths;
}
Also used : User(net.sf.acegisecurity.providers.dao.User) GrantedAuthority(net.sf.acegisecurity.GrantedAuthority)

Aggregations

User (net.sf.acegisecurity.providers.dao.User)7 GrantedAuthority (net.sf.acegisecurity.GrantedAuthority)6 GrantedAuthorityImpl (net.sf.acegisecurity.GrantedAuthorityImpl)4 UserDetails (net.sf.acegisecurity.UserDetails)4 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 UsernamePasswordAuthenticationToken (net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken)1 DynamicAuthority (org.alfresco.repo.security.permissions.DynamicAuthority)1 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)1