import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.cms.CmsException;
+import org.argeo.api.NodeConstants;
+import org.argeo.api.security.CryptoKeyring;
import org.argeo.cms.internal.kernel.Activator;
import org.argeo.naming.LdapAttrs;
-import org.argeo.node.NodeConstants;
-import org.argeo.node.security.CryptoKeyring;
import org.argeo.osgi.useradmin.AuthenticatingUser;
import org.argeo.osgi.useradmin.IpaUtils;
-import org.argeo.osgi.useradmin.OsUserUtils;
import org.argeo.osgi.useradmin.TokenUtils;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.useradmin.User;
import org.osgi.service.useradmin.UserAdmin;
+/**
+ * Use the {@link UserAdmin} in the OSGi registry as the basis for
+ * authentication.
+ */
public class UserAdminLoginModule implements LoginModule {
private final static Log log = LogFactory.getLog(UserAdminLoginModule.class);
private Authorization bindAuthorization = null;
- private boolean singleUser = Activator.isSingleUser();
+// private boolean singleUser = Activator.isSingleUser();
@SuppressWarnings("unchecked")
@Override
this.callbackHandler = callbackHandler;
this.sharedState = (Map<String, Object>) sharedState;
} catch (Exception e) {
- throw new CmsException("Cannot initialize login module", e);
+ throw new IllegalStateException("Cannot initialize login module", e);
}
}
username = (String) sharedState.get(CmsAuthUtils.SHARED_STATE_NAME);
password = null;
preauth = true;
- } else if (singleUser) {
- username = OsUserUtils.getOsUsername();
- password = null;
+// } else if (singleUser) {
+// username = OsUserUtils.getOsUsername();
+// password = null;
+// // TODO retrieve from http session
+// locale = Locale.getDefault();
} else {
// ask for username and password
// TODO check CRLs/OSCP validity?
// NB: authorization in commit() will work only if an LDAP connection password
// is provided
- } else if (singleUser) {
- // TODO verify IP address?
+// } else if (singleUser) {
+// // TODO verify IP address?
} else if (preauth) {
// ident
} else {
@Override
public boolean commit() throws LoginException {
- if (locale == null)
- subject.getPublicCredentials().add(Locale.getDefault());
- else
+ if (locale != null)
subject.getPublicCredentials().add(locale);
- if (singleUser) {
- OsUserUtils.loginAsSystemUser(subject);
- }
+// if (singleUser) {
+// OsUserUtils.loginAsSystemUser(subject);
+// }
UserAdmin userAdmin = Activator.getUserAdmin();
Authorization authorization;
if (callbackHandler == null) {// anonymous
if (authenticatedUser == null) {
if (log.isTraceEnabled())
log.trace("Neither kerberos nor user admin login succeeded. Login failed.");
- return false;
+ throw new CredentialNotFoundException("Bad credentials.");
} else {
authenticatingUser = authenticatedUser;
}
public boolean logout() throws LoginException {
if (log.isTraceEnabled())
log.trace("Logging out from CMS... " + subject);
- // boolean httpSessionLogoutOk = CmsAuthUtils.logoutSession(bc,
- // subject);
CmsAuthUtils.cleanUp(subject);
return true;
}
Set<User> collectedUsers = new HashSet<>();
// try dn
User user = null;
+ user = null;
// try all indexes
for (String attr : indexedUserProperties) {
user = userAdmin.getUser(attr, providedUsername);
// return null;
// }
// }
- Authorization auth = userAdmin.getAuthorization(tokenGroup);
+ String userDn = TokenUtils.userDn(tokenGroup);
+ User user = (User) userAdmin.getRole(userDn);
+ Authorization auth = userAdmin.getAuthorization(user);
return auth;
}
}