Search in sources :

Example 1 with UsernameNotFoundException

use of org.acegisecurity.userdetails.UsernameNotFoundException in project hudson-2.x by hudson.

the class LDAPSecurityRealm method loadGroupByGroupname.

/**
     * Lookup a group; given input must match the configured syntax for group names
     * in WEB-INF/security/LDAPBindSecurityRealm.groovy's authoritiesPopulator entry.
     * The defaults are a prefix of "ROLE_" and using all uppercase.  This method will
     * not return any data if the given name lacks the proper prefix and/or case. 
     */
@Override
public GroupDetails loadGroupByGroupname(String groupname) throws UsernameNotFoundException, DataAccessException {
    // Check proper syntax based on acegi configuration
    String prefix = "";
    boolean onlyUpperCase = false;
    try {
        AuthoritiesPopulatorImpl api = (AuthoritiesPopulatorImpl) ((LDAPUserDetailsService) getSecurityComponents().userDetails).authoritiesPopulator;
        prefix = api.rolePrefix;
        onlyUpperCase = api.convertToUpperCase;
    } catch (Exception ignore) {
    }
    if (onlyUpperCase && !groupname.equals(groupname.toUpperCase()))
        throw new UsernameNotFoundException(groupname + " should be all uppercase");
    if (!groupname.startsWith(prefix))
        throw new UsernameNotFoundException(groupname + " is missing prefix: " + prefix);
    groupname = groupname.substring(prefix.length());
    // TODO: obtain a DN instead so that we can obtain multiple attributes later
    String searchBase = groupSearchBase != null ? groupSearchBase : "";
    final Set<String> groups = (Set<String>) ldapTemplate.searchForSingleAttributeValues(searchBase, GROUP_SEARCH, new String[] { groupname }, "cn");
    if (groups.isEmpty())
        throw new UsernameNotFoundException(groupname);
    return new GroupDetails() {

        public String getName() {
            return groups.iterator().next();
        }
    };
}
Also used : UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) Set(java.util.Set) NamingException(javax.naming.NamingException) AuthenticationException(org.acegisecurity.AuthenticationException) LdapDataAccessException(org.acegisecurity.ldap.LdapDataAccessException) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) DataAccessException(org.springframework.dao.DataAccessException) AcegiSecurityException(org.acegisecurity.AcegiSecurityException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 2 with UsernameNotFoundException

use of org.acegisecurity.userdetails.UsernameNotFoundException in project hudson-2.x by hudson.

the class PAMSecurityRealm method createSecurityComponents.

public SecurityComponents createSecurityComponents() {
    Binding binding = new Binding();
    binding.setVariable("instance", this);
    BeanBuilder builder = new BeanBuilder();
    builder.parse(Hudson.getInstance().servletContext.getResourceAsStream("/WEB-INF/security/PAMSecurityRealm.groovy"), binding);
    WebApplicationContext context = builder.createApplicationContext();
    return new SecurityComponents(findBean(AuthenticationManager.class, context), new UserDetailsService() {

        public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
            if (!UnixUser.exists(username))
                throw new UsernameNotFoundException("No such Unix user: " + username);
            // return some dummy instance
            return new User(username, "", true, true, true, true, new GrantedAuthority[] { AUTHENTICATED_AUTHORITY });
        }
    });
}
Also used : Binding(groovy.lang.Binding) BeanBuilder(hudson.util.spring.BeanBuilder) AuthenticationManager(org.acegisecurity.AuthenticationManager) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) UserDetails(org.acegisecurity.userdetails.UserDetails) UnixUser(org.jvnet.libpam.UnixUser) User(org.acegisecurity.userdetails.User) GrantedAuthority(org.acegisecurity.GrantedAuthority) UserDetailsService(org.acegisecurity.userdetails.UserDetailsService) DataAccessException(org.springframework.dao.DataAccessException) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 3 with UsernameNotFoundException

use of org.acegisecurity.userdetails.UsernameNotFoundException in project hudson-2.x by hudson.

the class HudsonPrivateSecurityRealm method loadUserByUsername.

@Override
public Details loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    User u = User.get(username, false);
    Details p = u != null ? u.getProperty(Details.class) : null;
    if (p == null)
        throw new UsernameNotFoundException("Password is not set: " + username);
    if (p.getUser() == null)
        throw new AssertionError();
    return p;
}
Also used : UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) UserDetails(org.acegisecurity.userdetails.UserDetails)

Aggregations

UsernameNotFoundException (org.acegisecurity.userdetails.UsernameNotFoundException)3 UserDetails (org.acegisecurity.userdetails.UserDetails)2 DataAccessException (org.springframework.dao.DataAccessException)2 Binding (groovy.lang.Binding)1 BeanBuilder (hudson.util.spring.BeanBuilder)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 Set (java.util.Set)1 NamingException (javax.naming.NamingException)1 AcegiSecurityException (org.acegisecurity.AcegiSecurityException)1 AuthenticationException (org.acegisecurity.AuthenticationException)1 AuthenticationManager (org.acegisecurity.AuthenticationManager)1 GrantedAuthority (org.acegisecurity.GrantedAuthority)1 LdapDataAccessException (org.acegisecurity.ldap.LdapDataAccessException)1 User (org.acegisecurity.userdetails.User)1 UserDetailsService (org.acegisecurity.userdetails.UserDetailsService)1 UnixUser (org.jvnet.libpam.UnixUser)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1