diff --git a/src/main/java/org/olat/ldap/LDAPLoginManager.java b/src/main/java/org/olat/ldap/LDAPLoginManager.java index cd9514479f1ab187100715bca7226a0addcc39e0..d4725afd8008ce67891669c799fd3834107a1106 100644 --- a/src/main/java/org/olat/ldap/LDAPLoginManager.java +++ b/src/main/java/org/olat/ldap/LDAPLoginManager.java @@ -69,6 +69,14 @@ public interface LDAPLoginManager { public void freeSyncLock(); public void doSyncSingleUser(Identity ident); + + /** + * A filter is build from the login attribute value and the resulting + * attributes are sync to the specified identity. + * + * @param ident The identity to synchronize + */ + public void doSyncSingleUserWithLoginAttribute(Identity ident); public void removeFallBackAuthentications(); diff --git a/src/main/java/org/olat/ldap/manager/LDAPLoginManagerImpl.java b/src/main/java/org/olat/ldap/manager/LDAPLoginManagerImpl.java index bf2addf8bc94bdc3855d84f98cf4f7cf44194531..f010eebf2890bf5984ff6527170b1dca0e9a3691 100644 --- a/src/main/java/org/olat/ldap/manager/LDAPLoginManagerImpl.java +++ b/src/main/java/org/olat/ldap/manager/LDAPLoginManagerImpl.java @@ -1430,6 +1430,35 @@ public class LDAPLoginManagerImpl implements LDAPLoginManager, GenericEventListe syncUser(olatProToSync, ident); } } + + @Override + public void doSyncSingleUserWithLoginAttribute(Identity ident) { + LdapContext ctx = bindSystem(); + if (ctx == null) { + log.error("could not bind to ldap", null); + } + + String ldapUserIDAttribute = syncConfiguration.getLdapUserLoginAttribute(); + String filter = ldapDao.buildSearchUserFilter(ldapUserIDAttribute, ident.getName()); + + List<Attributes> ldapUserAttrs = new ArrayList<>(); + ldapDao.searchInLdap(new LDAPVisitor() { + @Override + public void visit(SearchResult result) { + ldapUserAttrs.add(result.getAttributes()); + } + }, filter, syncConfiguration.getUserAttributes(), ctx); + + if(ldapUserAttrs.size() == 1) { + Attributes attrs = ldapUserAttrs.get(0); + Map<String, String> olatProToSync = prepareUserPropertyForSync(attrs, ident); + if (olatProToSync != null) { + syncUser(olatProToSync, ident); + } + } else { + log.error("Cannot sync the user because it was not found on LDAP server: " + ident); + } + } /** * @see org.olat.ldap.LDAPLoginManager#getLastSyncDate() diff --git a/src/main/java/org/olat/login/oauth/OAuthDispatcher.java b/src/main/java/org/olat/login/oauth/OAuthDispatcher.java index c8c2f65e072baa6271d2b2921038ace3fe660445..9ed4997dce0d1c40ab3e0a7f132a230b4f5fd482 100644 --- a/src/main/java/org/olat/login/oauth/OAuthDispatcher.java +++ b/src/main/java/org/olat/login/oauth/OAuthDispatcher.java @@ -150,9 +150,14 @@ public class OAuthDispatcher implements Dispatcher { OAuthRegistration registration = new OAuthRegistration(provider.getProviderName(), infos); login(infos, registration); - if(registration.getIdentity() == null && provider instanceof OAuthUserCreator) { + if(provider instanceof OAuthUserCreator) { + Identity newIdentity; OAuthUserCreator userCreator = (OAuthUserCreator)provider; - Identity newIdentity = userCreator.createUser(infos); + if(registration.getIdentity() == null) { + newIdentity = userCreator.createUser(infos); + } else { + newIdentity = userCreator.updateUser(infos, registration.getIdentity()); + } if(newIdentity != null) { registration.setIdentity(newIdentity); } diff --git a/src/main/java/org/olat/login/oauth/OAuthUserCreator.java b/src/main/java/org/olat/login/oauth/OAuthUserCreator.java index a5002ec4051c55182107d4178e1824ae7441e453..67bd052dfd708eee62bfca02747d9eecb703302a 100644 --- a/src/main/java/org/olat/login/oauth/OAuthUserCreator.java +++ b/src/main/java/org/olat/login/oauth/OAuthUserCreator.java @@ -34,5 +34,7 @@ import org.olat.login.oauth.model.OAuthUser; public interface OAuthUserCreator extends OAuthSPI { public Identity createUser(OAuthUser user); + + public Identity updateUser(OAuthUser user, Identity identity); }