diff --git a/docker.md b/docker.md index 2f0b60f..4d707a5 100644 --- a/docker.md +++ b/docker.md @@ -1,5 +1,6 @@ mvn clean package docker build -t idm . +docker compose up -d --build --force-recreate docker run -it -d -p 8080:8080 --name idm idm docker run -it -d -p 8080:8080 --entrypoint=/bin/bash --name idm idm diff --git a/keycloak.md b/keycloak.md new file mode 100644 index 0000000..c5d29f2 --- /dev/null +++ b/keycloak.md @@ -0,0 +1,9 @@ +keycloak + +gruppi: +* dev: gcube +* pre: +* prod: + + +segnare che bisogna registrarsi su https://next.dev.d4science.org/home \ No newline at end of file diff --git a/src/main/java/org/gcube/idm/rest/UsersRest.java b/src/main/java/org/gcube/idm/rest/UsersRest.java index 335bf8e..943a2a0 100644 --- a/src/main/java/org/gcube/idm/rest/UsersRest.java +++ b/src/main/java/org/gcube/idm/rest/UsersRest.java @@ -13,8 +13,8 @@ import javax.ws.rs.core.Response.Status; import org.gcube.common.authorization.library.policies.Users; import org.gcube.common.security.Owner; import org.gcube.common.security.providers.SecretManagerProvider; -import org.gcube.keycloack.KeycloackApiClient; -import org.gcube.keycloack.KeycloakAPIFactory; +import org.gcube.keycloak.KeycloakApiClient; +import org.gcube.keycloak.KeycloakAPIFactory; import org.gcube.rest.ResponseBean; import org.gcube.smartgears.ContextProvider; import org.gcube.smartgears.context.application.ApplicationContext; @@ -51,9 +51,9 @@ public class UsersRest { List usernames = new ArrayList(); try { String ctx = SecretManagerProvider.instance.get().getContext(); - KeycloackApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx); + KeycloakApiClient keycloakApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx); - List users = searchByRole(keycloackApiClient, roleName); + List users = searchByRole(keycloakApiClient, roleName); if (users != null) { for (UserRepresentation user : users) { usernames.add(user.getUsername()); @@ -71,11 +71,11 @@ public class UsersRest { } - private static List searchByRole(KeycloackApiClient keycloackApiClient, String roleName) { + private static List searchByRole(KeycloakApiClient keycloakApiClient, String roleName) { logger.info("Searching by role: {}", roleName); - List clients = keycloackApiClient.kclient.realm(keycloackApiClient.realmName) - .clients().findByClientId(keycloackApiClient.clientIdContext); + List clients = keycloakApiClient.kclient.realm(keycloakApiClient.realmName) + .clients().findByClientId(keycloakApiClient.clientIdContext); String id = ""; for (ClientRepresentation client : clients) { @@ -84,7 +84,7 @@ public class UsersRest { id = client.getId(); } - List users = keycloackApiClient.kclient.realm(keycloackApiClient.realmName) + List users = keycloakApiClient.kclient.realm(keycloakApiClient.realmName) .clients() .get(id).roles().get(roleName) .getUserMembers(0, 100000); @@ -104,7 +104,7 @@ public class UsersRest { .getCredentials(); String ctx = SecretManagerProvider.instance.get().getContext(); - KeycloackApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx); + KeycloakApiClient keycloakApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx); return null; } diff --git a/src/main/java/org/gcube/keycloack/ErrorMessages.java b/src/main/java/org/gcube/keycloak/ErrorMessages.java similarity index 98% rename from src/main/java/org/gcube/keycloack/ErrorMessages.java rename to src/main/java/org/gcube/keycloak/ErrorMessages.java index 538dcdc..31e965e 100644 --- a/src/main/java/org/gcube/keycloack/ErrorMessages.java +++ b/src/main/java/org/gcube/keycloak/ErrorMessages.java @@ -1,4 +1,4 @@ -package org.gcube.keycloack; +package org.gcube.keycloak; public class ErrorMessages { diff --git a/src/main/java/org/gcube/keycloack/KeycloakAPIFactory.java b/src/main/java/org/gcube/keycloak/KeycloakAPIFactory.java similarity index 95% rename from src/main/java/org/gcube/keycloack/KeycloakAPIFactory.java rename to src/main/java/org/gcube/keycloak/KeycloakAPIFactory.java index 8ea513e..9d44f46 100644 --- a/src/main/java/org/gcube/keycloack/KeycloakAPIFactory.java +++ b/src/main/java/org/gcube/keycloak/KeycloakAPIFactory.java @@ -1,4 +1,4 @@ -package org.gcube.keycloack; +package org.gcube.keycloak; import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; @@ -132,8 +132,7 @@ public class KeycloakAPIFactory { return realm; } - public KeycloackApiClient createtKeycloakInstance(String context) { - // String clientIdContext = KeycloackUtils.getClientIdContext(context); + public KeycloakApiClient createtKeycloakInstance(String context) { String realm = this.getRealm(); Keycloak keycloak = KeycloakBuilder.builder() .serverUrl(this.getServerURL()) @@ -141,7 +140,7 @@ public class KeycloakAPIFactory { .grantType(OAuth2Constants.CLIENT_CREDENTIALS) .clientId(this.getClientid()) // .clientSecret(this.getPassword()).build(); - return new KeycloackApiClient(keycloak, realm, context); + return new KeycloakApiClient(keycloak, realm, context); } } diff --git a/src/main/java/org/gcube/keycloack/KeycloackApiClient.java b/src/main/java/org/gcube/keycloak/KeycloakApiClient.java similarity index 79% rename from src/main/java/org/gcube/keycloack/KeycloackApiClient.java rename to src/main/java/org/gcube/keycloak/KeycloakApiClient.java index c9080ad..cdfee89 100644 --- a/src/main/java/org/gcube/keycloack/KeycloackApiClient.java +++ b/src/main/java/org/gcube/keycloak/KeycloakApiClient.java @@ -1,8 +1,8 @@ -package org.gcube.keycloack; +package org.gcube.keycloak; import org.keycloak.admin.client.Keycloak; -public class KeycloackApiClient { +public class KeycloakApiClient { public Keycloak kclient; public String realmName; public String clientIdContext; @@ -12,7 +12,7 @@ public class KeycloackApiClient { return context.replace("/", "%2F"); } - public KeycloackApiClient(Keycloak kclient, String realmName, String context) { + public KeycloakApiClient(Keycloak kclient, String realmName, String context) { this.clientIdContext = getClientIdContext(context); this.context = context; this.kclient = kclient; diff --git a/src/main/java/org/gcube/keycloack/KeycloackClientParams_UNUSED.java b/src/main/java/org/gcube/keycloak/KeycloakClientParams_UNUSED.java similarity index 92% rename from src/main/java/org/gcube/keycloack/KeycloackClientParams_UNUSED.java rename to src/main/java/org/gcube/keycloak/KeycloakClientParams_UNUSED.java index 738de48..e70f691 100644 --- a/src/main/java/org/gcube/keycloack/KeycloackClientParams_UNUSED.java +++ b/src/main/java/org/gcube/keycloak/KeycloakClientParams_UNUSED.java @@ -1,4 +1,4 @@ -package org.gcube.keycloack; +package org.gcube.keycloak; import java.io.InputStream; import java.net.URL; @@ -14,9 +14,9 @@ import org.gcube.common.keycloak.KeycloakClientException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class KeycloackClientParams_UNUSED { +public class KeycloakClientParams_UNUSED { - private static final Logger logger = LoggerFactory.getLogger(KeycloackClientParams_UNUSED.class); + private static final Logger logger = LoggerFactory.getLogger(KeycloakClientParams_UNUSED.class); public static final String CATALOGUE_NAME = "IDM"; @@ -32,7 +32,7 @@ public class KeycloackClientParams_UNUSED { protected static Entry getClientIdAndClientSecret(String context) { try { Properties properties = new Properties(); - ClassLoader classLoader = KeycloackClientParams_UNUSED.class.getClassLoader(); + ClassLoader classLoader = KeycloakClientParams_UNUSED.class.getClassLoader(); URL url = classLoader.getResource(CLIENT_ID_SECRET_FILENAME); logger.trace("Going to read {} at {}", CLIENT_ID_SECRET_FILENAME, url.toString()); InputStream input = classLoader.getResourceAsStream(CLIENT_ID_SECRET_FILENAME); @@ -90,7 +90,7 @@ public class KeycloackClientParams_UNUSED { return this.context; } - public KeycloackClientParams_UNUSED(String context) { + public KeycloakClientParams_UNUSED(String context) { this.context = context; Entry params = getClientIdAndClientSecret(context); this.clientId = params.getKey(); diff --git a/src/main/java/org/gcube/rest/utils/HTTPUtility.java b/src/main/java/org/gcube/rest/utils/HTTPUtility.java index 6b5f9e9..3d6bed2 100644 --- a/src/main/java/org/gcube/rest/utils/HTTPUtility.java +++ b/src/main/java/org/gcube/rest/utils/HTTPUtility.java @@ -13,7 +13,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response.Status; import org.gcube.common.gxhttp.request.GXHTTPStringRequest; -import org.gcube.keycloack.KeycloackClientParams_UNUSED; +import org.gcube.keycloak.KeycloakClientParams_UNUSED; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +39,7 @@ public class HTTPUtility { public static GXHTTPStringRequest createGXHTTPStringRequest(String url, String path, boolean post) throws UnsupportedEncodingException { GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(url); - gxhttpStringRequest.from(KeycloackClientParams_UNUSED.CATALOGUE_NAME); + gxhttpStringRequest.from(KeycloakClientParams_UNUSED.CATALOGUE_NAME); if(post) { gxhttpStringRequest.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); }