Search in sources :

Example 1 with UserDetailsService

use of org.acegisecurity.userdetails.UserDetailsService 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)

Aggregations

Binding (groovy.lang.Binding)1 BeanBuilder (hudson.util.spring.BeanBuilder)1 AuthenticationManager (org.acegisecurity.AuthenticationManager)1 GrantedAuthority (org.acegisecurity.GrantedAuthority)1 User (org.acegisecurity.userdetails.User)1 UserDetails (org.acegisecurity.userdetails.UserDetails)1 UserDetailsService (org.acegisecurity.userdetails.UserDetailsService)1 UsernameNotFoundException (org.acegisecurity.userdetails.UsernameNotFoundException)1 UnixUser (org.jvnet.libpam.UnixUser)1 DataAccessException (org.springframework.dao.DataAccessException)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1