org.acegisecurity.GrantedAuthorityImpl Java Examples

The following examples show how to use org.acegisecurity.GrantedAuthorityImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DaoSupportImpl.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: GitLabAuthenticationToken.java    From gitlab-oauth-plugin with MIT License 6 votes vote down vote up
/**
 * @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;
}
 
Example #3
Source File: SecurityService.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: WCTDAOAuthenticationProvider.java    From webcurator with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: WCTAuthoritiesPopulator.java    From webcurator with Apache License 2.0 6 votes vote down vote up
/**
 * 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];
}
 
Example #6
Source File: Listener.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@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()]));
}
 
Example #7
Source File: OicUserProperty.java    From oic-auth-plugin with MIT License 5 votes vote down vote up
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;
}
 
Example #8
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
@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]));
}
 
Example #9
Source File: WCTDAOAuthenticationProvider.java    From webcurator with Apache License 2.0 5 votes vote down vote up
protected Object mapRow(ResultSet rs, int rownum)
    throws SQLException {
    String roleName = getRolePrefix() + rs.getString(1);
    GrantedAuthorityImpl authority = new GrantedAuthorityImpl(roleName);

    return authority;
}
 
Example #10
Source File: KualiUserDetailsServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * 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); 
}
 
Example #11
Source File: KualiUserDetailsServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: GitLabOAuthGroupDetails.java    From gitlab-oauth-plugin with MIT License 4 votes vote down vote up
public GrantedAuthority getAuth() {
    return new GrantedAuthorityImpl(getName());
}
 
Example #13
Source File: KualiTestAuthenticationProvider.java    From rice with Educational Community License v2.0 4 votes vote down vote up
private UsernamePasswordAuthenticationToken authenticateNow(Authentication authentication) throws AuthenticationException {
	return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_KUALI_USER")});
}