Java源码示例:org.acegisecurity.GrantedAuthorityImpl

示例1
@Override
public UserDetails loadUserByUsername(String username)
        throws UsernameNotFoundException, DataAccessException {
    com.ramussoft.net.common.User user = getUserFactory().getUser(username);

    if (user == null) {
        throw new UsernameNotFoundException(MessageFormat.format(
                "User {0} not found", username));
    }

    List<Group> list = user.getGroups();
    GrantedAuthority[] arrayAuths = new GrantedAuthority[list.size() + 1];
    for (int i = 0; i < list.size(); i++) {
        arrayAuths[i] = new GrantedAuthorityImpl("ROLE_"
                + list.get(i).getName().toUpperCase());
    }
    arrayAuths[list.size()] = new GrantedAuthorityImpl("ROLE_USER");

    return new User(user.getLogin(), user.getPassword(), true, true, true,
            true, arrayAuths);
}
 
示例2
/**
 * @since 0.21
 */
public GitLabOAuthUserDetails getUserDetails(String username) {
	GitlabUser user = loadUser(username);
	if (user != null) {
		// FIXME to implement
		List<GrantedAuthority> groups = new ArrayList<GrantedAuthority>();
		try {
			List<GitlabGroup> gitLabGroups = gitLabAPI.getGroups();
			for (GitlabGroup gitlabGroup : gitLabGroups) {
				groups.add(new GrantedAuthorityImpl(gitlabGroup.getName()));
			}
		} catch (IOException e) {
			LOGGER.log(Level.FINE, e.getMessage(), e);
		}
		return new GitLabOAuthUserDetails(user, groups.toArray(new GrantedAuthority[groups.size()]));
	}
	return null;
}
 
示例3
/**
 * Locates the user based on the username.
 *
 * @param username The username presented to the {@link DaoAuthenticationProvider}
 * @return A fully populated user record (never <code>null</code>)
 * @throws UsernameNotFoundException if the user could not be found or the user has no GrantedAuthority.
 * @throws DataAccessException       If user could not be found for a repository-specific reason.
 */
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    User user = getUserByName(username);
    if (user == null) {
        throw new UsernameNotFoundException("User \"" + username + "\" was not found.");
    }

    String[] roles = userDao.getRolesForUser(username);
    GrantedAuthority[] authorities = new GrantedAuthority[roles.length];
    for (int i = 0; i < roles.length; i++) {
        authorities[i] = new GrantedAuthorityImpl("ROLE_" + roles[i].toUpperCase());
    }

    // If user is LDAP authenticated, disable user. The proper authentication should in that case
    // be done by SubsonicLdapBindAuthenticator.
    boolean enabled = !user.isLdapAuthenticated();

    return new org.acegisecurity.userdetails.User(username, user.getPassword(), enabled, true, true, true, authorities);
}
 
示例4
protected Object mapRow(ResultSet rs, int rownum)
    throws SQLException {
    String username = rs.getString(1);
    String password = rs.getString(2);
    boolean enabled = rs.getBoolean(3);
    boolean credentialsNonExpired = rs.getBoolean(4);
    
    if (password == null) {
        //set the password to blank for users authenticated by an external Authentication source
        password = "";
    }
    UserDetails user = new User(username, password, enabled, true,
            !credentialsNonExpired, true,
            new GrantedAuthority[] {new GrantedAuthorityImpl("HOLDER")});

    return user;
}
 
示例5
/**
 * Select the granted authorities for the sepcified user and return and 
 * array of the authorities found.
 * @param username the user name to get the authorities for
 * @return the list of granted authorities
 * @throws LdapDataAccessException thrown if there is an error
 */
private GrantedAuthority[] getGrantedAuthorities(String username) throws LdapDataAccessException {
   
    List privileges = auth.getUserPrivileges(username);
    if (privileges != null) {
        int privSize = privileges.size();
        GrantedAuthority roles[] = new GrantedAuthority[privSize]; 
    
        int i=0;
        Iterator it = privileges.iterator();
        while (it.hasNext()) {
            RolePrivilege priv = (RolePrivilege) it.next();
            GrantedAuthority ga = new GrantedAuthorityImpl("ROLE_"+priv.getPrivilege());
            roles[i++] = ga;
        }
        
        return roles;
    }
    return new GrantedAuthority[0];
}
 
示例6
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException,
        DataAccessException {
    List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
    auths.add(AUTHENTICATED_AUTHORITY);
    Set<String> groups = groupsByUser.get(username);
    if (groups != null) {
        for (String g : groups) {
            auths.add(new GrantedAuthorityImpl(g));
        }
    }
    return new org.acegisecurity.userdetails.User(username,"",true,true,true,true, auths.toArray(new GrantedAuthority[auths.size()]));
}
 
示例7
public GrantedAuthority[] getAuthoritiesAsGrantedAuthorities() {
	GrantedAuthority[] authorities = new GrantedAuthority[this.authorities.size()];
	for(int i=0; i<authorities.length; i++) {
		authorities[i] = new GrantedAuthorityImpl(this.authorities.get(i));
	}
	return authorities;
}
 
示例8
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException,
        DataAccessException {
    List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
    auths.add(AUTHENTICATED_AUTHORITY);
    Set<String> groups = groupsByUser.get(username);
    if (groups != null) {
        for (String g : groups) {
            auths.add(new GrantedAuthorityImpl(g));
        }
    }
    return new org.acegisecurity.userdetails.User(username,"",true,true,true,true, auths.toArray(new GrantedAuthority[0]));
}
 
示例9
protected Object mapRow(ResultSet rs, int rownum)
    throws SQLException {
    String roleName = getRolePrefix() + rs.getString(1);
    GrantedAuthorityImpl authority = new GrantedAuthorityImpl(roleName);

    return authority;
}
 
示例10
/**
 * This overridden method appends the Distributed Session Ticket to the
 * granted authorities
 * 
 * @see org.kuali.rice.kim.client.acegi.KualiUserDetailsService#loadUserByTicketResponse(org.kuali.rice.kim.client.acegi.KualiTicketResponse)
 */
public UserDetails loadUserByTicketResponse(KualiTicketResponse response) {
    GrantedAuthority[] authorities = new GrantedAuthority[1];
    authorities[0]= new GrantedAuthorityImpl(response.getDistributedSessionToken());
    if (logger.isDebugEnabled()) {
        logger.debug("loadUserByTicketResponse:" + response.getDistributedSessionToken());
    }
    return loadUserByUsernameAndAuthorities(response.getUser(), authorities); 
}
 
示例11
/**
 * This method is necessary for loading users by the ticket response
 * 
 * @param username
 * @param authorities
 * @return the UserDetails
 */
public UserDetails loadUserByUsernameAndAuthorities(String username, GrantedAuthority[] authorities) {
    if (logger.isDebugEnabled()) {
        logger.debug("loadUserByUsernameAndAuthorities");
    }
    GrantedAuthority[] newAuthorities = new GrantedAuthority[authorities.length+1];
    System.arraycopy(authorities, 0, newAuthorities, 0, authorities.length);
    newAuthorities[authorities.length]= new GrantedAuthorityImpl("ROLE_KUALI_USER");
    logger.warn("setting granted authorities:" + newAuthorities.toString());
    UserDetails user = new User(username, "empty_password", true, true, true, true, newAuthorities);    
    return user;
}
 
示例12
public GrantedAuthority getAuth() {
    return new GrantedAuthorityImpl(getName());
}
 
示例13
private UsernamePasswordAuthenticationToken authenticateNow(Authentication authentication) throws AuthenticationException {
	return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_KUALI_USER")});
}