code formatting
This commit is contained in:
parent
c4786572ab
commit
9508b7329c
|
@ -11,6 +11,8 @@ This service allows any client to publish on the gCube Catalogue.
|
|||
|
||||
[Identity Manager Service](https://wiki.gcube-system.org/gcube/SmartGears)
|
||||
|
||||
configuration: inserte
|
||||
|
||||
## Change log
|
||||
|
||||
See [CHANGELOG.md](CHANGELOG.md).
|
||||
|
@ -18,7 +20,6 @@ See [CHANGELOG.md](CHANGELOG.md).
|
|||
## Authors
|
||||
|
||||
* **Alfredo Oliviero** [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
|
||||
* **Luca Frosini** ([ORCID](https://orcid.org/0000-0003-3183-2291)) - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
|
||||
|
||||
## How to Cite this Software
|
||||
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -108,7 +108,7 @@
|
|||
<!--
|
||||
usermanagement-core depends on older httpcommon and gives this error on keycloak client:
|
||||
java.lang.NoClassDefFoundError: org/apache/http/ssl/TrustStrategy
|
||||
https://stackoverflow.com/questions/44750124/classnotfoundexception-on-org-apache-http-ssl-truststrategy
|
||||
https://stackoverflow.com/questions/44750124/classnotfoundexception-on-org-apache-http-ssl-truststrategy
|
||||
|
||||
solution: bind version, or exclude them in usermanagement-core
|
||||
|
||||
|
@ -241,7 +241,7 @@ solution: bind version, or exclude them in usermanagement-core
|
|||
<!--
|
||||
usermanagement-core depends on older httpcommon and gives this error on keycloak client:
|
||||
java.lang.NoClassDefFoundError: org/apache/http/ssl/TrustStrategy
|
||||
https://stackoverflow.com/questions/44750124/classnotfoundexception-on-org-apache-http-ssl-truststrategy
|
||||
https://stackoverflow.com/questions/44750124/classnotfoundexception-on-org-apache-http-ssl-truststrategy
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.gcube.dvos</groupId>
|
||||
|
|
|
@ -7,7 +7,6 @@ public class ErrorMessages {
|
|||
|
||||
private static final String NO_RUNTIME_RESOURCE_TEMPLATE_NAME_CATEGORY = "There is no Runtime Resource having name %s and Category %s in this scope";
|
||||
|
||||
|
||||
public static final String MISSING_TOKEN = "Missing token.";
|
||||
public static final String MISSING_PARAMETERS = "Missing request parameters.";
|
||||
public static final String INVALID_TOKEN = "Invalid token.";
|
||||
|
|
|
@ -8,7 +8,7 @@ public class KeycloackApiClient {
|
|||
public String clientIdContext;
|
||||
public String context;
|
||||
|
||||
public static String getClientIdContext(String context){
|
||||
public static String getClientIdContext(String context) {
|
||||
return context.replace("/", "%2F");
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,8 @@ public class KeycloackApiClient {
|
|||
this.context = context;
|
||||
this.kclient = kclient;
|
||||
this.realmName = realmName;
|
||||
//ClientsResource clients = kclient.realm(realmName).clients().get*
|
||||
//clients.get(context);
|
||||
// ClientsResource clients = kclient.realm(realmName).clients().get*
|
||||
// clients.get(context);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.gcube.common.authorization.utils.secret.Secret;
|
||||
|
||||
|
||||
/***
|
||||
* from gcat implementation
|
||||
*
|
||||
|
@ -61,7 +60,7 @@ public class KeycloackClientGcatFactory {
|
|||
} catch (Exception e) {
|
||||
throw new InternalServerErrorException(
|
||||
"Unable to retrieve Application Token for context "
|
||||
/*+ SecretManagerProvider.instance.get().getContext() */,
|
||||
/* + SecretManagerProvider.instance.get().getContext() */,
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
@ -108,10 +107,11 @@ public class KeycloackClientGcatFactory {
|
|||
this.gcubeKeycloakClient = new DefaultKeycloakClient();
|
||||
}
|
||||
|
||||
private static TokenResponse getJWTAccessToken() throws Exception {
|
||||
private static TokenResponse getJWTAccessToken() throws Exception {
|
||||
String context = SecretManagerProvider.get().getContext();
|
||||
Entry<String,String> entry = getClientIdAndClientSecret(context);
|
||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(context, entry.getKey(), entry.getValue(), context, null);
|
||||
Entry<String, String> entry = getClientIdAndClientSecret(context);
|
||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(context, entry.getKey(), entry.getValue(),
|
||||
context, null);
|
||||
return tr;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,9 +22,6 @@ import org.keycloak.admin.client.KeycloakBuilder;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
|
||||
public class KeycloakClientFactory {
|
||||
private static final Logger logger = LoggerFactory.getLogger(KeycloakClientFactory.class);
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import jakarta.ws.rs.Produces;
|
|||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
|
||||
@ManagedBy(IdMManager.class)
|
||||
@Path("")
|
||||
public class KeycloakTestService {
|
||||
|
@ -51,8 +50,7 @@ public class KeycloakTestService {
|
|||
@QueryParam("realm") @DefaultValue("d4science") String realm,
|
||||
@QueryParam("role-name") @DefaultValue("Member") String roleName,
|
||||
@QueryParam("client_id") @DefaultValue("id.d4science.org") String clientId,
|
||||
@QueryParam("client_secret") @DefaultValue(CLIENT_SECRET) String client_secret
|
||||
) {
|
||||
@QueryParam("client_secret") @DefaultValue(CLIENT_SECRET) String client_secret) {
|
||||
|
||||
String client_contenxt = "/gcube";
|
||||
|
||||
|
@ -139,4 +137,3 @@ public class KeycloakTestService {
|
|||
return users_repr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,13 +25,15 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|||
public class ContextSerializator {
|
||||
private static ObjectMapper serializer = null;
|
||||
|
||||
protected static TypeReference<HashMap<String,Object>> typeRefHashmap = new TypeReference<HashMap<String,Object>>() {};
|
||||
protected static TypeReference<HashMap<String, Object>> typeRefHashmap = new TypeReference<HashMap<String, Object>>() {
|
||||
};
|
||||
|
||||
public static String decodeBase64String(String encodedString){
|
||||
public static String decodeBase64String(String encodedString) {
|
||||
return new String(Base64.getUrlDecoder().decode(encodedString), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> jsonStringToHasmap(String jsonString) throws JsonMappingException, JsonProcessingException {
|
||||
public static HashMap<String, Object> jsonStringToHasmap(String jsonString)
|
||||
throws JsonMappingException, JsonProcessingException {
|
||||
return getSerializer().readValue(jsonString, typeRefHashmap);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.gcube.common.authorization.library.ClientType;
|
|||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Tokens utils methods
|
||||
*/
|
||||
|
@ -14,19 +13,22 @@ public class TokensUtils {
|
|||
private static final String DEFAULT_QUALIFIER_USER_TOKEN = "TOKEN";
|
||||
// Logger
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TokensUtils.class);
|
||||
|
||||
/**
|
||||
* Check if it is a service token
|
||||
*
|
||||
* @return a boolean value
|
||||
*/
|
||||
public static boolean isServiceToken(Caller caller){
|
||||
public static boolean isServiceToken(Caller caller) {
|
||||
return caller.getClient().getType().equals(ClientType.SERVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is an application token
|
||||
*
|
||||
* @return a boolean value
|
||||
*/
|
||||
public static boolean isApplicationToken(Caller caller){
|
||||
public static boolean isApplicationToken(Caller caller) {
|
||||
String username = caller.getClient().getId();
|
||||
if (username.startsWith("service-account-")) {
|
||||
return true;
|
||||
|
@ -37,9 +39,10 @@ public class TokensUtils {
|
|||
|
||||
/**
|
||||
* Check if it is a container token
|
||||
*
|
||||
* @return a boolean value
|
||||
*/
|
||||
public static boolean isContainerToken(Caller caller){
|
||||
public static boolean isContainerToken(Caller caller) {
|
||||
|
||||
return caller.getClient().getType().equals(ClientType.CONTAINER);
|
||||
|
||||
|
@ -47,10 +50,12 @@ public class TokensUtils {
|
|||
|
||||
/**
|
||||
* Check if it is a user token
|
||||
*
|
||||
* @return a boolean value
|
||||
*/
|
||||
public static boolean isUserToken(Caller caller) {
|
||||
logger.debug("\n ****** \n isUserToken: caller.getClient().getType().equals(ClientType.USER) => " + caller.getClient().getType().equals(ClientType.USER));
|
||||
logger.debug("\n ****** \n isUserToken: caller.getClient().getType().equals(ClientType.USER) => "
|
||||
+ caller.getClient().getType().equals(ClientType.USER));
|
||||
String username = caller.getClient().getId();
|
||||
if (username.startsWith("service-account-")) {
|
||||
return false;
|
||||
|
@ -61,19 +66,22 @@ public class TokensUtils {
|
|||
|
||||
/**
|
||||
* Check if it is a user token (not qualified)
|
||||
*
|
||||
* @return a boolean value
|
||||
*/
|
||||
public static boolean isUserTokenDefault(Caller caller){
|
||||
public static boolean isUserTokenDefault(Caller caller) {
|
||||
return isUserToken(caller);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is a user token (qualified)
|
||||
*
|
||||
* @return a boolean value
|
||||
*/
|
||||
public static boolean isUserTokenQualified(Caller caller){
|
||||
public static boolean isUserTokenQualified(Caller caller) {
|
||||
|
||||
return caller.getClient().getType().equals(ClientType.USER) && !caller.getTokenQualifier().equals(DEFAULT_QUALIFIER_USER_TOKEN);
|
||||
return caller.getClient().getType().equals(ClientType.USER)
|
||||
&& !caller.getTokenQualifier().equals(DEFAULT_QUALIFIER_USER_TOKEN);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue