use of org.pac4j.core.exception.AccountNotFoundException in project cas by apereo.
the class BaseUseAttributesAuthorizationGenerator method generate.
@Override
public CommonProfile generate(final WebContext context, final CommonProfile profile) {
Assert.notNull(this.connectionFactory, "connectionFactory must not be null");
Assert.notNull(this.userSearchExecutor, "userSearchExecutor must not be null");
final String username = profile.getId();
final SearchResult userResult;
try {
LOGGER.debug("Attempting to get details for user [{}].", username);
final Response<SearchResult> response = this.userSearchExecutor.search(this.connectionFactory, Beans.newLdaptiveSearchFilter(this.userSearchExecutor.getSearchFilter().getFilter(), Beans.LDAP_SEARCH_FILTER_DEFAULT_PARAM_NAME, Arrays.asList(username)));
LOGGER.debug("LDAP user search response: [{}]", response);
userResult = response.getResult();
if (userResult.size() == 0) {
throw new RuntimeException(new AccountNotFoundException(username + " not found."));
}
if (userResult.size() > 1 && !this.allowMultipleResults) {
throw new IllegalStateException("Found multiple results for user which is not allowed (allowMultipleResults=false).");
}
final LdapEntry userEntry = userResult.getEntry();
return generateAuthorizationForLdapEntry(profile, userEntry);
} catch (final LdapException e) {
throw new RuntimeException("LDAP error fetching details for user.", e);
}
}
Aggregations