use of org.olat.basesecurity.Authentication in project openolat by klemens.
the class LDAPLoginManagerImpl method findIdentityByLdapAuthentication.
/**
* Searches for Identity in OLAT.
*
* @param uid Name of Identity
* @param errors LDAPError Object if user exits but not member of
* LDAPSecurityGroup
*
* @return Identity if it's found and member of LDAPSecurityGroup, null
* otherwise (if user exists but not managed by LDAP, error Object is
* modified)
*/
@Override
public Identity findIdentityByLdapAuthentication(Attributes attrs, LDAPError errors) {
if (attrs == null) {
errors.insert("findIdentyByLdapAuthentication: attrs::null");
return null;
}
String uid = getAttributeValue(attrs.get(syncConfiguration.getOlatPropertyToLdapAttribute(LDAPConstants.LDAP_USER_IDENTIFYER)));
String token = getAttributeValue(attrs.get(syncConfiguration.getLdapUserLoginAttribute()));
Identity identity = securityManager.findIdentityByNameCaseInsensitive(uid);
if (identity == null) {
return null;
} else {
SecurityGroup ldapGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
if (ldapGroup == null) {
log.error("Error getting user from OLAT security group '" + LDAPConstants.SECURITY_GROUP_LDAP + "' : group does not exist", null);
return null;
}
boolean inSecurityGroup = securityManager.isIdentityInSecurityGroup(identity, ldapGroup);
if (inSecurityGroup) {
Authentication ldapAuth = securityManager.findAuthentication(identity, LDAPAuthenticationController.PROVIDER_LDAP);
if (ldapAuth == null) {
// BUG Fixe: update the user and test if it has a ldap provider
securityManager.createAndPersistAuthentication(identity, LDAPAuthenticationController.PROVIDER_LDAP, token, null, null);
} else if (StringHelper.containsNonWhitespace(token) && !token.equals(ldapAuth.getAuthusername())) {
ldapAuth.setAuthusername(token);
ldapAuth = securityManager.updateAuthentication(ldapAuth);
}
return identity;
} else if (ldapLoginModule.isConvertExistingLocalUsersToLDAPUsers()) {
// Add user to LDAP security group and add the ldap provider
securityManager.createAndPersistAuthentication(identity, LDAPAuthenticationController.PROVIDER_LDAP, token, null, null);
securityManager.addIdentityToSecurityGroup(identity, ldapGroup);
log.info("Found identity by LDAP username that was not yet in LDAP security group. Converted user::" + uid + " to be an LDAP managed user");
return identity;
} else {
errors.insert("findIdentyByLdapAuthentication: User with username::" + uid + " exist but not Managed by LDAP");
return null;
}
}
}
use of org.olat.basesecurity.Authentication in project openolat by klemens.
the class OLATAuthManager method synchronizeOlatPasswordAndUsername.
public boolean synchronizeOlatPasswordAndUsername(Identity doer, Identity identity, String username, String newPwd) {
Authentication auth = securityManager.findAuthentication(identity, "OLAT");
if (auth == null) {
// create new authentication for provider OLAT
auth = securityManager.createAndPersistAuthentication(identity, "OLAT", username, newPwd, loginModule.getDefaultHashAlgorithm());
log.audit(doer.getName() + " created new authenticatin for identity: " + identity.getName());
} else {
// update credentials
if (!securityManager.checkCredentials(auth, newPwd)) {
auth = securityManager.updateCredentials(auth, newPwd, loginModule.getDefaultHashAlgorithm());
}
if (!username.equals(auth.getAuthusername())) {
auth.setAuthusername(username);
auth = securityManager.updateAuthentication(auth);
}
log.audit(doer.getName() + " set new password for identity: " + identity.getName());
}
if (identity != null && StringHelper.containsNonWhitespace(username) && webDAVAuthManager != null) {
webDAVAuthManager.changeDigestPassword(doer, identity, newPwd);
}
return true;
}
Aggregations