org.acegisecurity.userdetails.UserDetailsService Java Examples

The following examples show how to use org.acegisecurity.userdetails.UserDetailsService. 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: GitLabSecurityRealm.java    From gitlab-oauth-plugin with MIT License 5 votes vote down vote up
@Override
public SecurityComponents createSecurityComponents() {
    return new SecurityComponents(new AuthenticationManager() {

        @Override
        public Authentication authenticate(Authentication authentication) throws AuthenticationException {
            if (authentication instanceof GitLabAuthenticationToken) {
                return authentication;
            }
            if (authentication instanceof UsernamePasswordAuthenticationToken) {
                try {
                    UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
                    GitLabAuthenticationToken gitlab = new GitLabAuthenticationToken(token.getCredentials().toString(), getGitlabApiUri(), TokenType.PRIVATE_TOKEN);
                    SecurityContextHolder.getContext().setAuthentication(gitlab);
                    return gitlab;
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            throw new BadCredentialsException("Unexpected authentication type: " + authentication);
        }
    }, new UserDetailsService() {
        @Override
        public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
            return GitLabSecurityRealm.this.loadUserByUsername(username);
        }
    });
}
 
Example #2
Source File: OicSecurityRealm.java    From oic-auth-plugin with MIT License 5 votes vote down vote up
@Override
public SecurityComponents createSecurityComponents() {
    return new SecurityComponents(
            new AuthenticationManager() {
                public Authentication authenticate(Authentication authentication) throws AuthenticationException {
                    if (authentication instanceof AnonymousAuthenticationToken)
                        return authentication;
                    throw new BadCredentialsException("Unexpected authentication type: " + authentication);
                }
            },
            new UserDetailsService() {
	
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
		// Retrieve the OicUserProperty to get the list of groups that has to be set in the OicUserDetails object.
		LOGGER.fine("loadUserByUsername in createSecurityComponents called, username: " + username);
		User u = User.get(username, false, Collections.emptyMap());
		if (u == null) {
			LOGGER.fine("loadUserByUsername in createSecurityComponents called, no user '" + username + "' found");
			throw new UsernameNotFoundException(username);
		}
		LOGGER.fine("loadUserByUsername in createSecurityComponents called, user: " + u);
		List<UserProperty> props = u.getAllProperties();
		LOGGER.fine("loadUserByUsername in createSecurityComponents called, number of props: " + props.size());
		GrantedAuthority[] auths = new GrantedAuthority[0];
		for (UserProperty prop: props) {
			LOGGER.fine("loadUserByUsername in createSecurityComponents called, prop of type: " + prop.getClass().toString());
			if (prop instanceof OicUserProperty) {
				OicUserProperty oicProp = (OicUserProperty) prop;
				LOGGER.fine("loadUserByUsername in createSecurityComponents called, oic prop found with username: " + oicProp.getUserName());
				auths = oicProp.getAuthoritiesAsGrantedAuthorities();
				LOGGER.fine("loadUserByUsername in createSecurityComponents called, oic prop with auths size: " + auths.length);
			}
		}
		return new OicUserDetails(username, auths);
	}
}
    );
}
 
Example #3
Source File: UserDetailsServiceBasedAuthoritiesPopulator.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
public void setUserDetailsService(UserDetailsService userDetailsService) {
    this.userDetailsService = userDetailsService;
}
 
Example #4
Source File: KualiCasAuthoritiesPopulatorImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * @param userDetailsService the UserDetailsService to set
 */
public void setUserDetailsService(UserDetailsService userDetailsService) {
    this.userDetailsService = (KualiUserDetailsService)userDetailsService;
}