diff --git a/authentication/authentication-api/src/main/java/org/keycloak/authentication/AuthenticationProvider.java b/authentication/authentication-api/src/main/java/org/keycloak/authentication/AuthenticationProvider.java index 542c994d10..f4ed95ee6a 100644 --- a/authentication/authentication-api/src/main/java/org/keycloak/authentication/AuthenticationProvider.java +++ b/authentication/authentication-api/src/main/java/org/keycloak/authentication/AuthenticationProvider.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Map; import org.keycloak.models.RealmModel; +import org.keycloak.models.UserModel; import org.keycloak.provider.Provider; /** @@ -36,11 +37,11 @@ public interface AuthenticationProvider extends Provider { * * @param realm * @param configuration - * @param username + * @param user Keycloak user, which will be registered on authentication provider side * @return ID of newly created user (For example ID from LDAP) * @throws AuthenticationProviderException if user creation couldn't happen */ - String registerUser(RealmModel realm, Map configuration, String username) throws AuthenticationProviderException; + String registerUser(RealmModel realm, Map configuration, UserModel user) throws AuthenticationProviderException; /** * Standard Authentication flow diff --git a/authentication/authentication-api/src/main/java/org/keycloak/authentication/AuthenticationProviderManager.java b/authentication/authentication-api/src/main/java/org/keycloak/authentication/AuthenticationProviderManager.java index b0d485babb..d36cb24e65 100755 --- a/authentication/authentication-api/src/main/java/org/keycloak/authentication/AuthenticationProviderManager.java +++ b/authentication/authentication-api/src/main/java/org/keycloak/authentication/AuthenticationProviderManager.java @@ -118,7 +118,7 @@ public class AuthenticationProviderManager { + authUser.getProviderName() + " but is not linked with model user"); } } else { - String userIdInProvider = delegate.registerUser(realm, providerModel.getConfig(), user.getLoginName()); + String userIdInProvider = delegate.registerUser(realm, providerModel.getConfig(), user); authLink = new AuthenticationLinkModel(providerModel.getProviderName(), userIdInProvider); user.setAuthenticationLink(authLink); logger.infof("User '%s' registered in provider '%s' and linked", user.getLoginName(), providerModel.getProviderName()); @@ -143,7 +143,7 @@ public class AuthenticationProviderManager { String username = user.getLoginName(); - // Update just those, which support password update + // Update just if password update is supported if (providerModel.isPasswordUpdateSupported()) { try { AuthenticationProvider delegate = getProvider(providerName); diff --git a/authentication/authentication-model/src/main/java/org/keycloak/authentication/model/AbstractModelAuthenticationProvider.java b/authentication/authentication-model/src/main/java/org/keycloak/authentication/model/AbstractModelAuthenticationProvider.java index 730f3f44c7..ea20abcaba 100755 --- a/authentication/authentication-model/src/main/java/org/keycloak/authentication/model/AbstractModelAuthenticationProvider.java +++ b/authentication/authentication-model/src/main/java/org/keycloak/authentication/model/AbstractModelAuthenticationProvider.java @@ -30,11 +30,14 @@ public abstract class AbstractModelAuthenticationProvider implements Authenticat } @Override - public String registerUser(RealmModel currentRealm, Map config, String username) throws AuthenticationProviderException { + public String registerUser(RealmModel currentRealm, Map config, UserModel user) throws AuthenticationProviderException { RealmModel realm = getRealm(currentRealm, config); - UserModel user = currentRealm.addUser(username); - user.setEnabled(true); - return user.getId(); + UserModel newUser = realm.addUser(user.getLoginName()); + newUser.setFirstName(user.getFirstName()); + newUser.setLastName(user.getLastName()); + newUser.setEmail(user.getEmail()); + newUser.setEnabled(true); + return newUser.getId(); } @Override diff --git a/authentication/authentication-picketlink/src/main/java/org/keycloak/authentication/picketlink/PicketlinkAuthenticationProvider.java b/authentication/authentication-picketlink/src/main/java/org/keycloak/authentication/picketlink/PicketlinkAuthenticationProvider.java index b2310ede9c..772f6da6e0 100755 --- a/authentication/authentication-picketlink/src/main/java/org/keycloak/authentication/picketlink/PicketlinkAuthenticationProvider.java +++ b/authentication/authentication-picketlink/src/main/java/org/keycloak/authentication/picketlink/PicketlinkAuthenticationProvider.java @@ -7,6 +7,7 @@ import org.keycloak.authentication.AuthUser; import org.keycloak.authentication.AuthenticationProvider; import org.keycloak.authentication.AuthenticationProviderException; import org.keycloak.models.RealmModel; +import org.keycloak.models.UserModel; import org.keycloak.picketlink.IdentityManagerProvider; import org.picketlink.idm.IdentityManagementException; import org.picketlink.idm.IdentityManager; @@ -67,16 +68,15 @@ public class PicketlinkAuthenticationProvider implements AuthenticationProvider } @Override - public String registerUser(RealmModel realm, Map configuration, String username) throws AuthenticationProviderException { + public String registerUser(RealmModel realm, Map configuration, UserModel user) throws AuthenticationProviderException { IdentityManager identityManager = getIdentityManager(realm); try { - User picketlinkUser = new User(username); + User picketlinkUser = new User(user.getLoginName()); + picketlinkUser.setFirstName(user.getFirstName()); + picketlinkUser.setLastName(user.getLastName()); + picketlinkUser.setEmail(user.getEmail()); identityManager.add(picketlinkUser); - - // Hack needed due to ActiveDirectory bug in Picketlink TODO: Remove once https://issues.jboss.org/browse/PLINK-485 fixed and updated in keycloak master - picketlinkUser = BasicModel.getUser(identityManager, picketlinkUser.getLoginName()); - return picketlinkUser.getId(); } catch (IdentityManagementException ie) { throw convertIDMException(ie); diff --git a/examples/providers/authentication-properties/src/main/java/org/keycloak/examples/providers/authentication/PropertiesAuthenticationProvider.java b/examples/providers/authentication-properties/src/main/java/org/keycloak/examples/providers/authentication/PropertiesAuthenticationProvider.java index da10eddfce..9b83ec0de8 100644 --- a/examples/providers/authentication-properties/src/main/java/org/keycloak/examples/providers/authentication/PropertiesAuthenticationProvider.java +++ b/examples/providers/authentication-properties/src/main/java/org/keycloak/examples/providers/authentication/PropertiesAuthenticationProvider.java @@ -11,6 +11,7 @@ import org.keycloak.authentication.AuthUser; import org.keycloak.authentication.AuthenticationProvider; import org.keycloak.authentication.AuthenticationProviderException; import org.keycloak.models.RealmModel; +import org.keycloak.models.UserModel; /** * @author Marek Posolda @@ -45,9 +46,9 @@ public class PropertiesAuthenticationProvider implements AuthenticationProvider } @Override - public String registerUser(RealmModel realm, Map configuration, String username) throws AuthenticationProviderException { + public String registerUser(RealmModel realm, Map configuration, UserModel user) throws AuthenticationProviderException { // Registration ignored - return username; + return user.getLoginName(); } @Override diff --git a/pom.xml b/pom.xml index cd19d1607b..66927cb8ce 100755 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 2.3.7.Final 3.0.8.Final 1.0.15.Final - 2.6.0.CR2 + 2.6.0.CR5 1.0.2.Final 2.11.3 3.1.1.GA diff --git a/services/src/main/java/org/keycloak/services/managers/AuthenticationManager.java b/services/src/main/java/org/keycloak/services/managers/AuthenticationManager.java index 76b8876383..dd4197e64c 100755 --- a/services/src/main/java/org/keycloak/services/managers/AuthenticationManager.java +++ b/services/src/main/java/org/keycloak/services/managers/AuthenticationManager.java @@ -276,7 +276,7 @@ public class AuthenticationManager { user.setLastName(authUser.getLastName()); user.setEmail(authUser.getEmail()); user.setAuthenticationLink(new AuthenticationLinkModel(authUser.getProviderName(), authUser.getId())); - logger.info("User " + authUser.getUsername() + " created and linked with provider " + authUser.getProviderName()); + logger.info("User " + authUser.getUsername() + " created in Keycloak and linked with provider " + authUser.getProviderName()); } else { logger.warn("User " + username + " not found"); return AuthenticationStatus.INVALID_USER;