* <code>null</code>.
*/
public Object authenticate(String userName, String password) {
final Credentials creds = new SimpleCredentials(userName,
(password == null) ? new char[0] : password.toCharArray());
Session session = null;
try {
session = repository.login(creds);
if (session instanceof JackrabbitSession) {
UserManager umgr = ((JackrabbitSession) session).getUserManager();
String userId = session.getUserID();
Authorizable a = umgr.getAuthorizable(userId);
if (a instanceof User) {
// check users
if (users.contains(userId)) {
return true;
}
// check groups
@SuppressWarnings("unchecked")
Iterator<Group> gi = a.memberOf();
while (gi.hasNext()) {
if (groups.contains(gi.next().getID())) {
return userName;
}
}
logger.debug(
"authenticate: User {} is denied Web Console access",
userName);
} else {
logger.error(
"authenticate: Expected user ID {} to refer to a user",
userId);
}
} else {
logger.info(
"authenticate: Jackrabbit Session required to grant access to the Web Console for {}; got {}",
userName, session.getClass());
}
} catch (final LoginException re) {
logger.info(
"authenticate: User "
+ userName
+ " failed to authenticate with the repository for Web Console access",
re);
} catch (final Exception re) {
logger.info("authenticate: Generic problem trying grant User "
+ userName + " access to the Web Console", re);
} finally {
if (session != null) {
session.logout();
}
}
// no success (see log)
return null;