code format

This commit is contained in:
Alfredo Oliviero 2024-02-26 10:11:45 +01:00
parent 051c448e87
commit 2fc47d8d21
13 changed files with 218 additions and 189 deletions

12
.vscode/settings.json vendored
View File

@ -8,5 +8,15 @@
"debug": false "debug": false
} }
], ],
"java.dependency.packagePresentation": "hierarchical" "java.dependency.packagePresentation": "hierarchical",
"Workspace_Formatter.excludePattern": [
"**/build",
"**/.*",
"**/.vscode",
"**/docs/*",
"**/documentazione/*",
"**/target/*",
"**/tomcat/*",
"**/webapps/*"
]
} }

View File

@ -1,8 +1,7 @@
<configuration scan="true" debug="true"> <configuration scan="true" debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>Ï <encoder>Ï <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder> </encoder>
</appender> </appender>

View File

@ -91,7 +91,7 @@ on instances.
| Operation | HTTP Method | URL | Success HTTP Status | Safe | Idempotent | | Operation | HTTP Method | URL | Success HTTP Status | Safe | Idempotent |
|-----------|-------------|-----|---------------------|------|------------| | ------------------------------ | ----------- | -------------------------------------- | ------------------- | ---- | ---------- |
| **Supported<br/>HTTP Methods** | OPTIONS | /{COLLECTION} | 204 No Content | Y | Y | | **Supported<br/>HTTP Methods** | OPTIONS | /{COLLECTION} | 204 No Content | Y | Y |
| **List** | GET | /{COLLECTION} | 200 OK | Y | Y | | **List** | GET | /{COLLECTION} | 200 OK | Y | Y |
| **Count** | GET | /{COLLECTION}?count=true | 200 OK | Y | Y | | **Count** | GET | /{COLLECTION}?count=true | 200 OK | Y | Y |

View File

@ -15,7 +15,8 @@
<javascript-client disabled="true" /> <javascript-client disabled="true" />
<docs docsDir="${project.build.directory}" docsSubdir="api-docs" /> <docs docsDir="${project.build.directory}" docsSubdir="api-docs" />
<swagger basePath="/${project.artifactId}" /> <swagger basePath="/${project.artifactId}" />
<docs freemarkerTemplate="${project.basedir}/src/main/resources/META-INF/enunciate/d4science_docs.fmt"> <docs
freemarkerTemplate="${project.basedir}/src/main/resources/META-INF/enunciate/d4science_docs.fmt">
<additional-css <additional-css
file="css/d4science_enunciate_custom.css" /> file="css/d4science_enunciate_custom.css" />
</docs> </docs>

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0" version="4.0"
metadata-complete="true"> metadata-complete="true">
<display-name>Identity Manager Service</display-name> <display-name>Identity Manager Service</display-name>

View File

@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* @author Alfredo Oliviero (ISTI - CNR) * @author Alfredo gOliviero (ISTI - CNR)
*/ */
public class IdentityManagerApplicationManager implements ApplicationManager { public class IdentityManagerApplicationManager implements ApplicationManager {
@ -40,8 +40,6 @@ public class IdentityManagerApplicationManager implements ApplicationManager {
+ "-------------------------------------------------------", + "-------------------------------------------------------",
context); context);
} }
/** /**
@ -58,7 +56,6 @@ public class IdentityManagerApplicationManager implements ApplicationManager {
+ "-------------------------------------------------------", + "-------------------------------------------------------",
context); context);
logger.trace( logger.trace(
"\n-------------------------------------------------------\n" "\n-------------------------------------------------------\n"
+ "Identity Manager Service Stopped Successfully on context {}\n" + "Identity Manager Service Stopped Successfully on context {}\n"

View File

@ -13,115 +13,138 @@ public class UsersRest {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Users.class); private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Users.class);
/* /*
// @GET * // @GET
// @Path("/get-usernames-by-role") * // @Path("/get-usernames-by-role")
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" }) * // @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json"
public Response getUsernamesByRole( * })
@QueryParam("role-name") String roleName) { * public Response getUsernamesByRole(
Status status = Status.OK; *
ResponseBean responseBean = new ResponseBean(); * @QueryParam("role-name") String roleName) {
* Status status = Status.OK;
List<String> usernames = new ArrayList<String>(); * ResponseBean responseBean = new ResponseBean();
try { *
String ctx = SecretManagerProvider.get().getContext(); * List<String> usernames = new ArrayList<String>();
KeycloakApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx); * try {
* String ctx = SecretManagerProvider.get().getContext();
List<UserRepresentation> users = null; // searchByRole(keycloackApiClient, roleName); * KeycloakApiClient keycloackApiClient =
if (users != null) { * KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
for (UserRepresentation user : users) { *
usernames.add(user.getUsername()); * List<UserRepresentation> users = null; // searchByRole(keycloackApiClient,
} * roleName);
} * if (users != null) {
responseBean.setResult(usernames); * for (UserRepresentation user : users) {
responseBean.setSuccess(true); * usernames.add(user.getUsername());
} catch (Exception e) { * }
logger.error("Unable to retrieve user with the requested role", e); * }
responseBean.setMessage(e.getMessage()); * responseBean.setResult(usernames);
status = Status.INTERNAL_SERVER_ERROR; * responseBean.setSuccess(true);
} * } catch (Exception e) {
* logger.error("Unable to retrieve user with the requested role", e);
return Response.status(status).entity(responseBean).build(); * responseBean.setMessage(e.getMessage());
* status = Status.INTERNAL_SERVER_ERROR;
} * }
*
private static List<UserRepresentation> searchByRole(KeycloackApiClient keycloackApiClient, String roleName) { * return Response.status(status).entity(responseBean).build();
logger.info("Searching by role: {}", roleName); *
* }
List<ClientRepresentation> clients = keycloackApiClient.kclient.realm(keycloackApiClient.realmName) *
.clients().findByClientId(keycloackApiClient.clientIdContext); * private static List<UserRepresentation> searchByRole(KeycloackApiClient
* keycloackApiClient, String roleName) {
String id = ""; * logger.info("Searching by role: {}", roleName);
for (ClientRepresentation client : clients) { *
logger.info("found client =" + client.getClientId()); * List<ClientRepresentation> clients =
logger.info("found client id=" + client.getId()); * keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
id = client.getId(); * .clients().findByClientId(keycloackApiClient.clientIdContext);
} *
* String id = "";
List<UserRepresentation> users = keycloackApiClient.kclient.realm(keycloackApiClient.realmName) * for (ClientRepresentation client : clients) {
.clients() * logger.info("found client =" + client.getClientId());
.get(id).roles().get(roleName) * logger.info("found client id=" + client.getId());
.getUserMembers(0, 100000); * id = client.getId();
return users; * }
} *
* List<UserRepresentation> users =
@GET * keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
@Path("/{get-profile}") * .clients()
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" }) * .get(id).roles().get(roleName)
public String getCurrentProfile() { * .getUserMembers(0, 100000);
// SMARTGEARS Specializza il tracciamento della chiamata su Accounting * return users;
InnerMethodName.instance.set("getCurrentProfile"); * }
Owner owner = SecretManagerProvider.get().getOwner(); *
* @GET
ApplicationContext appContext = ContextProvider.get(); *
SimpleCredentials credentials = ((DefaultAuthorizationProvider) appContext.container().authorizationProvider()) * @Path("/{get-profile}")
.getCredentials(); *
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
String ctx = SecretManagerProvider.get().getContext(); * public String getCurrentProfile() {
KeycloackApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx); * // SMARTGEARS Specializza il tracciamento della chiamata su Accounting
return null; * InnerMethodName.instance.set("getCurrentProfile");
} * Owner owner = SecretManagerProvider.get().getOwner();
*
@GET * ApplicationContext appContext = ContextProvider.get();
@Path("/{get-email}") * SimpleCredentials credentials = ((DefaultAuthorizationProvider)
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" }) * appContext.container().authorizationProvider())
public String getCurrentEmail() { * .getCredentials();
throw new NotImplementedYetException(); *
} * String ctx = SecretManagerProvider.get().getContext();
* KeycloackApiClient keycloackApiClient =
@GET * KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
@Path("/{get-fullname}") * return null;
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" }) * }
public String getCurrentFullname() { *
throw new NotImplementedYetException(); * @GET
} *
* @Path("/{get-email}")
@GET *
@Path("/{get-all-usernames}") * @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" }) * public String getCurrentEmail() {
public String getAllUsernames() { * throw new NotImplementedYetException();
throw new NotImplementedYetException(); * }
} *
* @GET
@GET *
@Path("/{get-all-fullnames-and-usernames}") * @Path("/{get-fullname}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" }) *
public String getAllUsernamesFullnames() { * @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
throw new NotImplementedYetException(); * public String getCurrentFullname() {
} * throw new NotImplementedYetException();
* }
@GET *
@Path("/{user-exists}") * @GET
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" }) *
public boolean checkUserExists() { * @Path("/{get-all-usernames}")
throw new NotImplementedYetException(); *
} * @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getAllUsernames() {
@GET * throw new NotImplementedYetException();
@Path("/{get-oauth-profile}") * }
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" }) *
public boolean getCurrentOAuthProfile() { * @GET
throw new NotImplementedYetException(); *
} * @Path("/{get-all-fullnames-and-usernames}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getAllUsernamesFullnames() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @Path("/{user-exists}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public boolean checkUserExists() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @Path("/{get-oauth-profile}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public boolean getCurrentOAuthProfile() {
* throw new NotImplementedYetException();
* }
*/ */
} }

View File

@ -1,4 +1,5 @@
package org.gcube.rest; package org.gcube.rest;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -68,4 +69,3 @@ public class ResponseBean implements Serializable {
+ ", message=" + message + ", result=" + result + "]"; + ", message=" + message + ", result=" + result + "]";
} }
} }