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
}
],
"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">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>Ï
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<encoder>Ï <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

View File

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

View File

@ -15,7 +15,8 @@
<javascript-client disabled="true" />
<docs docsDir="${project.build.directory}" docsSubdir="api-docs" />
<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
file="css/d4science_enunciate_custom.css" />
</docs>

View File

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

View File

@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Alfredo Oliviero (ISTI - CNR)
* @author Alfredo gOliviero (ISTI - CNR)
*/
public class IdentityManagerApplicationManager implements ApplicationManager {
@ -40,8 +40,6 @@ public class IdentityManagerApplicationManager implements ApplicationManager {
+ "-------------------------------------------------------",
context);
}
/**
@ -58,7 +56,6 @@ public class IdentityManagerApplicationManager implements ApplicationManager {
+ "-------------------------------------------------------",
context);
logger.trace(
"\n-------------------------------------------------------\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);
/*
// @GET
// @Path("/get-usernames-by-role")
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public Response getUsernamesByRole(
@QueryParam("role-name") String roleName) {
Status status = Status.OK;
ResponseBean responseBean = new ResponseBean();
List<String> usernames = new ArrayList<String>();
try {
String ctx = SecretManagerProvider.get().getContext();
KeycloakApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
List<UserRepresentation> users = null; // searchByRole(keycloackApiClient, roleName);
if (users != null) {
for (UserRepresentation user : users) {
usernames.add(user.getUsername());
}
}
responseBean.setResult(usernames);
responseBean.setSuccess(true);
} catch (Exception e) {
logger.error("Unable to retrieve user with the requested role", e);
responseBean.setMessage(e.getMessage());
status = Status.INTERNAL_SERVER_ERROR;
}
return Response.status(status).entity(responseBean).build();
}
private static List<UserRepresentation> searchByRole(KeycloackApiClient keycloackApiClient, String roleName) {
logger.info("Searching by role: {}", roleName);
List<ClientRepresentation> clients = keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
.clients().findByClientId(keycloackApiClient.clientIdContext);
String id = "";
for (ClientRepresentation client : clients) {
logger.info("found client =" + client.getClientId());
logger.info("found client id=" + client.getId());
id = client.getId();
}
List<UserRepresentation> users = keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
.clients()
.get(id).roles().get(roleName)
.getUserMembers(0, 100000);
return users;
}
@GET
@Path("/{get-profile}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public String getCurrentProfile() {
// SMARTGEARS Specializza il tracciamento della chiamata su Accounting
InnerMethodName.instance.set("getCurrentProfile");
Owner owner = SecretManagerProvider.get().getOwner();
ApplicationContext appContext = ContextProvider.get();
SimpleCredentials credentials = ((DefaultAuthorizationProvider) appContext.container().authorizationProvider())
.getCredentials();
String ctx = SecretManagerProvider.get().getContext();
KeycloackApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
return null;
}
@GET
@Path("/{get-email}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public String getCurrentEmail() {
throw new NotImplementedYetException();
}
@GET
@Path("/{get-fullname}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public String getCurrentFullname() {
throw new NotImplementedYetException();
}
@GET
@Path("/{get-all-usernames}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public String getAllUsernames() {
throw new NotImplementedYetException();
}
@GET
@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();
}
* // @GET
* // @Path("/get-usernames-by-role")
* // @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json"
* })
* public Response getUsernamesByRole(
*
* @QueryParam("role-name") String roleName) {
* Status status = Status.OK;
* ResponseBean responseBean = new ResponseBean();
*
* List<String> usernames = new ArrayList<String>();
* try {
* String ctx = SecretManagerProvider.get().getContext();
* KeycloakApiClient keycloackApiClient =
* KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
*
* List<UserRepresentation> users = null; // searchByRole(keycloackApiClient,
* roleName);
* if (users != null) {
* for (UserRepresentation user : users) {
* usernames.add(user.getUsername());
* }
* }
* responseBean.setResult(usernames);
* responseBean.setSuccess(true);
* } catch (Exception e) {
* logger.error("Unable to retrieve user with the requested role", e);
* responseBean.setMessage(e.getMessage());
* status = Status.INTERNAL_SERVER_ERROR;
* }
*
* return Response.status(status).entity(responseBean).build();
*
* }
*
* private static List<UserRepresentation> searchByRole(KeycloackApiClient
* keycloackApiClient, String roleName) {
* logger.info("Searching by role: {}", roleName);
*
* List<ClientRepresentation> clients =
* keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
* .clients().findByClientId(keycloackApiClient.clientIdContext);
*
* String id = "";
* for (ClientRepresentation client : clients) {
* logger.info("found client =" + client.getClientId());
* logger.info("found client id=" + client.getId());
* id = client.getId();
* }
*
* List<UserRepresentation> users =
* keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
* .clients()
* .get(id).roles().get(roleName)
* .getUserMembers(0, 100000);
* return users;
* }
*
* @GET
*
* @Path("/{get-profile}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getCurrentProfile() {
* // SMARTGEARS Specializza il tracciamento della chiamata su Accounting
* InnerMethodName.instance.set("getCurrentProfile");
* Owner owner = SecretManagerProvider.get().getOwner();
*
* ApplicationContext appContext = ContextProvider.get();
* SimpleCredentials credentials = ((DefaultAuthorizationProvider)
* appContext.container().authorizationProvider())
* .getCredentials();
*
* String ctx = SecretManagerProvider.get().getContext();
* KeycloackApiClient keycloackApiClient =
* KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
* return null;
* }
*
* @GET
*
* @Path("/{get-email}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getCurrentEmail() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @Path("/{get-fullname}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getCurrentFullname() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @Path("/{get-all-usernames}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getAllUsernames() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @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;
import java.io.Serializable;
/**
@ -68,4 +69,3 @@ public class ResponseBean implements Serializable {
+ ", message=" + message + ", result=" + result + "]";
}
}