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();
}
};
}
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 });
}
});
}
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;
}
Aggregations