code formatting

This commit is contained in:
Alfredo Oliviero 2024-03-26 17:41:10 +01:00
parent c4786572ab
commit 9508b7329c
9 changed files with 78 additions and 74 deletions

View File

@ -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) [Identity Manager Service](https://wiki.gcube-system.org/gcube/SmartGears)
configuration: inserte
## Change log ## Change log
See [CHANGELOG.md](CHANGELOG.md). See [CHANGELOG.md](CHANGELOG.md).
@ -18,7 +20,6 @@ See [CHANGELOG.md](CHANGELOG.md).
## Authors ## Authors
* **Alfredo Oliviero** [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience) * **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 ## How to Cite this Software

View File

@ -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"; 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_TOKEN = "Missing token.";
public static final String MISSING_PARAMETERS = "Missing request parameters."; public static final String MISSING_PARAMETERS = "Missing request parameters.";
public static final String INVALID_TOKEN = "Invalid token."; public static final String INVALID_TOKEN = "Invalid token.";

View File

@ -18,7 +18,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.gcube.common.authorization.utils.secret.Secret; import org.gcube.common.authorization.utils.secret.Secret;
/*** /***
* from gcat implementation * from gcat implementation
* *
@ -111,7 +110,8 @@ public class KeycloackClientGcatFactory {
private static TokenResponse getJWTAccessToken() throws Exception { private static TokenResponse getJWTAccessToken() throws Exception {
String context = SecretManagerProvider.get().getContext(); String context = SecretManagerProvider.get().getContext();
Entry<String, String> entry = getClientIdAndClientSecret(context); Entry<String, String> entry = getClientIdAndClientSecret(context);
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(context, entry.getKey(), entry.getValue(), context, null); TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(context, entry.getKey(), entry.getValue(),
context, null);
return tr; return tr;
} }

View File

@ -22,9 +22,6 @@ import org.keycloak.admin.client.KeycloakBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.QueryParam;
public class KeycloakClientFactory { public class KeycloakClientFactory {
private static final Logger logger = LoggerFactory.getLogger(KeycloakClientFactory.class); private static final Logger logger = LoggerFactory.getLogger(KeycloakClientFactory.class);

View File

@ -30,7 +30,6 @@ import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
@ManagedBy(IdMManager.class) @ManagedBy(IdMManager.class)
@Path("") @Path("")
public class KeycloakTestService { public class KeycloakTestService {
@ -51,8 +50,7 @@ public class KeycloakTestService {
@QueryParam("realm") @DefaultValue("d4science") String realm, @QueryParam("realm") @DefaultValue("d4science") String realm,
@QueryParam("role-name") @DefaultValue("Member") String roleName, @QueryParam("role-name") @DefaultValue("Member") String roleName,
@QueryParam("client_id") @DefaultValue("id.d4science.org") String clientId, @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"; String client_contenxt = "/gcube";
@ -139,4 +137,3 @@ public class KeycloakTestService {
return users_repr; return users_repr;
} }
} }

View File

@ -25,13 +25,15 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
public class ContextSerializator { public class ContextSerializator {
private static ObjectMapper serializer = null; 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); 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); return getSerializer().readValue(jsonString, typeRefHashmap);
} }

View File

@ -4,7 +4,6 @@ import org.gcube.common.authorization.library.ClientType;
import org.gcube.common.authorization.library.utils.Caller; import org.gcube.common.authorization.library.utils.Caller;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* Tokens utils methods * Tokens utils methods
*/ */
@ -14,8 +13,10 @@ public class TokensUtils {
private static final String DEFAULT_QUALIFIER_USER_TOKEN = "TOKEN"; private static final String DEFAULT_QUALIFIER_USER_TOKEN = "TOKEN";
// Logger // Logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TokensUtils.class); private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TokensUtils.class);
/** /**
* Check if it is a service token * Check if it is a service token
*
* @return a boolean value * @return a boolean value
*/ */
public static boolean isServiceToken(Caller caller) { public static boolean isServiceToken(Caller caller) {
@ -24,6 +25,7 @@ public class TokensUtils {
/** /**
* Check if it is an application token * Check if it is an application token
*
* @return a boolean value * @return a boolean value
*/ */
public static boolean isApplicationToken(Caller caller) { public static boolean isApplicationToken(Caller caller) {
@ -37,6 +39,7 @@ public class TokensUtils {
/** /**
* Check if it is a container token * Check if it is a container token
*
* @return a boolean value * @return a boolean value
*/ */
public static boolean isContainerToken(Caller caller) { public static boolean isContainerToken(Caller caller) {
@ -47,10 +50,12 @@ public class TokensUtils {
/** /**
* Check if it is a user token * Check if it is a user token
*
* @return a boolean value * @return a boolean value
*/ */
public static boolean isUserToken(Caller caller) { 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(); String username = caller.getClient().getId();
if (username.startsWith("service-account-")) { if (username.startsWith("service-account-")) {
return false; return false;
@ -61,6 +66,7 @@ public class TokensUtils {
/** /**
* Check if it is a user token (not qualified) * Check if it is a user token (not qualified)
*
* @return a boolean value * @return a boolean value
*/ */
public static boolean isUserTokenDefault(Caller caller) { public static boolean isUserTokenDefault(Caller caller) {
@ -69,11 +75,13 @@ public class TokensUtils {
/** /**
* Check if it is a user token (qualified) * Check if it is a user token (qualified)
*
* @return a boolean value * @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);
} }