Add provider...
diff --git a/model/api/src/main/java/org/keycloak/models/UserFederationProviderFactory.java b/model/api/src/main/java/org/keycloak/models/UserFederationProviderFactory.java
index b723f3dd74..7b3c38835a 100755
--- a/model/api/src/main/java/org/keycloak/models/UserFederationProviderFactory.java
+++ b/model/api/src/main/java/org/keycloak/models/UserFederationProviderFactory.java
@@ -2,10 +2,13 @@ package org.keycloak.models;
import org.keycloak.provider.ProviderFactory;
+import java.util.List;
+
/**
* @author
Bill Burke
* @version $Revision: 1 $
*/
public interface UserFederationProviderFactory extends ProviderFactory
{
UserFederationProvider getInstance(KeycloakSession session, UserFederationProviderModel model);
+ List getConfigurationOptions();
}
diff --git a/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java b/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java
index 21765a347c..ec0c8442ba 100755
--- a/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java
+++ b/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java
@@ -51,6 +51,7 @@ public class ModelToRepresentation {
rep.setEnabled(user.isEnabled());
rep.setEmailVerified(user.isEmailVerified());
rep.setTotp(user.isTotp());
+ rep.setFederationLink(user.getFederationLink());
List reqActions = new ArrayList();
for (UserModel.RequiredAction ra : user.getRequiredActions()){
diff --git a/services/src/main/java/org/keycloak/services/resources/admin/UserFederationResource.java b/services/src/main/java/org/keycloak/services/resources/admin/UserFederationResource.java
index 7e7a0b27ac..e947b1ed6b 100755
--- a/services/src/main/java/org/keycloak/services/resources/admin/UserFederationResource.java
+++ b/services/src/main/java/org/keycloak/services/resources/admin/UserFederationResource.java
@@ -16,8 +16,10 @@ import org.keycloak.models.RoleModel;
import org.keycloak.models.SocialLinkModel;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserFederationProvider;
+import org.keycloak.models.UserFederationProviderFactory;
import org.keycloak.models.UserFederationProviderModel;
import org.keycloak.models.UserModel;
+import org.keycloak.models.UserProviderFactory;
import org.keycloak.models.UserSessionModel;
import org.keycloak.models.utils.ModelToRepresentation;
import org.keycloak.models.utils.RepresentationToModel;
@@ -28,6 +30,7 @@ import org.keycloak.representations.idm.CredentialRepresentation;
import org.keycloak.representations.idm.MappingsRepresentation;
import org.keycloak.representations.idm.RoleRepresentation;
import org.keycloak.representations.idm.SocialLinkRepresentation;
+import org.keycloak.representations.idm.UserFederationProviderFactoryRepresentation;
import org.keycloak.representations.idm.UserFederationProviderRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.representations.idm.UserSessionRepresentation;
@@ -96,19 +99,43 @@ public class UserFederationResource {
@GET
@Path("providers")
@Produces("application/json")
- public List> getProviders() {
+ public List getProviders() {
logger.info("get provider list");
auth.requireView();
- List> providers = new LinkedList>();
+ List providers = new LinkedList();
for (ProviderFactory factory : session.getKeycloakSessionFactory().getProviderFactories(UserFederationProvider.class)) {
- Map provider = new HashMap();
- provider.put("name", factory.getId());
- providers.add(provider);
+ UserFederationProviderFactoryRepresentation rep = new UserFederationProviderFactoryRepresentation();
+ rep.setId(factory.getId());
+ rep.setOptions(((UserFederationProviderFactory)factory).getConfigurationOptions());
+ providers.add(rep);
}
logger.info("provider list.size() " + providers.size());
return providers;
}
+ /**
+ * Get List of available provider factories
+ *
+ * @return
+ */
+ @GET
+ @Path("providers/{id}")
+ @Produces("application/json")
+ public UserFederationProviderFactoryRepresentation getProvider(@PathParam("id") String id) {
+ logger.info("get provider list");
+ auth.requireView();
+ for (ProviderFactory factory : session.getKeycloakSessionFactory().getProviderFactories(UserFederationProvider.class)) {
+ if (!factory.getId().equals(id)) {
+ continue;
+ }
+ UserFederationProviderFactoryRepresentation rep = new UserFederationProviderFactoryRepresentation();
+ rep.setId(factory.getId());
+ rep.setOptions(((UserFederationProviderFactory)factory).getConfigurationOptions());
+ return rep;
+ }
+ throw new NotFoundException("Could not find provider");
+ }
+
/**
* Create a provider
*
@@ -118,7 +145,7 @@ public class UserFederationResource {
@POST
@Path("instances")
@Consumes("application/json")
- public Response createProvider(UserFederationProviderRepresentation rep) {
+ public Response createProviderInstance(UserFederationProviderRepresentation rep) {
logger.info("createProvider");
auth.requireManage();
String displayName = rep.getDisplayName();
@@ -138,7 +165,7 @@ public class UserFederationResource {
@PUT
@Path("instances/{id}")
@Consumes("application/json")
- public void updateProvider(@PathParam("id") String id, UserFederationProviderRepresentation rep) {
+ public void updateProviderInstance(@PathParam("id") String id, UserFederationProviderRepresentation rep) {
logger.info("updateProvider");
auth.requireManage();
String displayName = rep.getDisplayName();
@@ -157,7 +184,7 @@ public class UserFederationResource {
@GET
@Path("instances/{id}")
@Consumes("application/json")
- public UserFederationProviderRepresentation getProvider(@PathParam("id") String id) {
+ public UserFederationProviderRepresentation getProviderInstance(@PathParam("id") String id) {
logger.info("getProvider");
auth.requireView();
for (UserFederationProviderModel model : realm.getUserFederationProviders()) {
@@ -175,7 +202,7 @@ public class UserFederationResource {
*/
@DELETE
@Path("instances/{id}")
- public void deleteProvider(@PathParam("id") String id) {
+ public void deleteProviderInstance(@PathParam("id") String id) {
logger.info("deleteProvider");
auth.requireManage();
UserFederationProviderModel model = new UserFederationProviderModel(id, null, null, -1, null);
@@ -192,8 +219,8 @@ public class UserFederationResource {
@GET
@Path("instances")
@Produces("application/json")
- public List getUserFederationProviders() {
- logger.info("getUserFederationProviders");
+ public List getUserFederationInstances() {
+ logger.info("getUserFederationInstances");
auth.requireManage();
List reps = new LinkedList();
for (UserFederationProviderModel model : realm.getUserFederationProviders()) {
diff --git a/testsuite/integration/src/main/java/org/keycloak/testutils/DummyUserFederationProvider.java b/testsuite/integration/src/main/java/org/keycloak/testutils/DummyUserFederationProvider.java
new file mode 100755
index 0000000000..5d2c36b738
--- /dev/null
+++ b/testsuite/integration/src/main/java/org/keycloak/testutils/DummyUserFederationProvider.java
@@ -0,0 +1,88 @@
+package org.keycloak.testutils;
+
+import org.keycloak.models.RealmModel;
+import org.keycloak.models.RoleModel;
+import org.keycloak.models.UserCredentialModel;
+import org.keycloak.models.UserFederationProvider;
+import org.keycloak.models.UserModel;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Bill Burke
+ * @version $Revision: 1 $
+ */
+public class DummyUserFederationProvider implements UserFederationProvider {
+ @Override
+ public UserModel proxy(UserModel local) {
+ return local;
+ }
+
+ @Override
+ public boolean isRegistrationSupported() {
+ return false;
+ }
+
+ @Override
+ public UserModel register(RealmModel realm, UserModel user) {
+ return user;
+ }
+
+ @Override
+ public boolean removeUser(RealmModel realm, UserModel user) {
+ return true;
+ }
+
+ @Override
+ public UserModel getUserByUsername(RealmModel realm, String username) {
+ return null;
+ }
+
+ @Override
+ public UserModel getUserByEmail(RealmModel realm, String email) {
+ return null;
+ }
+
+ @Override
+ public List searchByAttributes(Map attributes, RealmModel realm) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void preRemove(RealmModel realm) {
+
+ }
+
+ @Override
+ public void preRemove(RealmModel realm, RoleModel role) {
+
+ }
+
+ @Override
+ public boolean isValid(UserModel local) {
+ return false;
+ }
+
+ @Override
+ public Set getSupportedCredentialTypes() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public boolean validCredentials(RealmModel realm, UserModel user, List input) {
+ return false;
+ }
+
+ @Override
+ public boolean validCredentials(RealmModel realm, UserModel user, UserCredentialModel... input) {
+ return false;
+ }
+
+ @Override
+ public void close() {
+
+ }
+}
diff --git a/testsuite/integration/src/main/java/org/keycloak/testutils/DummyUserFederationProviderFactory.java b/testsuite/integration/src/main/java/org/keycloak/testutils/DummyUserFederationProviderFactory.java
new file mode 100755
index 0000000000..2314a67482
--- /dev/null
+++ b/testsuite/integration/src/main/java/org/keycloak/testutils/DummyUserFederationProviderFactory.java
@@ -0,0 +1,48 @@
+package org.keycloak.testutils;
+
+import org.keycloak.Config;
+import org.keycloak.models.KeycloakSession;
+import org.keycloak.models.UserFederationProvider;
+import org.keycloak.models.UserFederationProviderFactory;
+import org.keycloak.models.UserFederationProviderModel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Bill Burke
+ * @version $Revision: 1 $
+ */
+public class DummyUserFederationProviderFactory implements UserFederationProviderFactory {
+ @Override
+ public UserFederationProvider getInstance(KeycloakSession session, UserFederationProviderModel model) {
+ return new DummyUserFederationProvider();
+ }
+
+ @Override
+ public List getConfigurationOptions() {
+ List list = new ArrayList();
+ list.add("important.config");
+ return list;
+ }
+
+ @Override
+ public UserFederationProvider create(KeycloakSession session) {
+ return new DummyUserFederationProvider();
+ }
+
+ @Override
+ public void init(Config.Scope config) {
+
+ }
+
+ @Override
+ public void close() {
+
+ }
+
+ @Override
+ public String getId() {
+ return "dummy";
+ }
+}
diff --git a/testsuite/integration/src/main/resources/META-INF/services/org.keycloak.models.UserFederationProviderFactory b/testsuite/integration/src/main/resources/META-INF/services/org.keycloak.models.UserFederationProviderFactory
new file mode 100755
index 0000000000..82b852c8e0
--- /dev/null
+++ b/testsuite/integration/src/main/resources/META-INF/services/org.keycloak.models.UserFederationProviderFactory
@@ -0,0 +1 @@
+org.keycloak.testutils.DummyUserFederationProviderFactory
\ No newline at end of file