Search in sources :

Example 6 with User

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

the class PermissionServiceImpl method getDynamicAuthorities.

protected Set<String> getDynamicAuthorities(Authentication auth, NodeRef nodeRef, PermissionReference required) {
    Set<String> dynAuths = new HashSet<String>(64);
    User user = (User) auth.getPrincipal();
    String username = user.getUsername();
    nodeRef = tenantService.getName(nodeRef);
    if (nodeRef != null) {
        if (dynamicAuthorities != null) {
            for (DynamicAuthority da : dynamicAuthorities) {
                Set<PermissionReference> requiredFor = da.requiredFor();
                if ((requiredFor == null) || (requiredFor.contains(required))) {
                    if (da.hasAuthority(nodeRef, username)) {
                        dynAuths.add(da.getAuthority());
                    }
                }
            }
        }
    }
    return dynAuths;
}
Also used : User(net.sf.acegisecurity.providers.dao.User) DynamicAuthority(org.alfresco.repo.security.permissions.DynamicAuthority) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with User

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

the class TestAuthenticationServiceImpl method setCurrentUser.

/**
 * Explicitly set the current user to be authenticated.
 *
 * @param userName
 *            String
 * @return Authentication
 */
public Authentication setCurrentUser(String userName) throws AuthenticationException {
    if (userName == null) {
        throw new AuthenticationException("Null user name");
    }
    try {
        UserDetails ud = null;
        if (userName.equals(SYSTEM_USER_NAME)) {
            GrantedAuthority[] gas = new GrantedAuthority[1];
            gas[0] = new GrantedAuthorityImpl("ROLE_SYSTEM");
            ud = new User(SYSTEM_USER_NAME, "", true, true, true, true, gas);
        } else if (userName.equalsIgnoreCase(AuthenticationUtil.getGuestUserName())) {
            GrantedAuthority[] gas = new GrantedAuthority[0];
            ud = new User(AuthenticationUtil.getGuestUserName().toLowerCase(), "", true, true, true, true, gas);
        } else {
            ud = getUserDetails(userName);
        }
        UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ud, "", ud.getAuthorities());
        auth.setDetails(ud);
        auth.setAuthenticated(true);
        return setCurrentAuthentication(auth);
    } 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) GrantedAuthorityImpl(net.sf.acegisecurity.GrantedAuthorityImpl) GrantedAuthority(net.sf.acegisecurity.GrantedAuthority) UsernamePasswordAuthenticationToken(net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken)

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