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,2 +1,2 @@
echo "deploying tomcat with tomcat/manager applications"
cp -a tomcat/manager/* tomcat/webappsgit
cp -a tomcat/manager/* tomcat/webappsgit

View File

@ -1,23 +1,22 @@
<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>
<encoder>Ï <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.gcube" level="DEBUG" />
<logger name="org.gcube.smartgears" level="TRACE" />
<logger name="org.gcube.smartgears.handlers" level="TRACE"/>
<logger name="org.gcube.smartgears.handlers" level="TRACE" />
<logger name="org.gcube.common.events" level="WARN" />
<logger name="org.gcube.data.publishing" level="ERROR" />
<logger name="org.gcube.documentstore" level="ERROR" />
<logger name="org.gcube.common.core.publisher.is.legacy" level="TRACE" />
<logger name="org.gcube.data.access" level="TRACE" />
<logger name="org.gcube.data.access.storagehub.handlers" level="DEBUG"/>
<logger name="org.gcube.data.access.storagehub.handlers" level="DEBUG" />
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -6,4 +6,4 @@ rm -fr tomcat/webapps/*
mvn clean package
docker compose up -d --build --force-recreate
# curl http://localhost:8080/identity-manager/gcube/resource/healthx
# curl http://localhost:8080/identity-manager/gcube/resource/healthx

View File

@ -90,21 +90,21 @@ on instances.
:widths: grid
| 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 |
| **Exists** | HEAD | /{COLLECTION} | 204 No Content | Y | Y |
| **Create** | POST | /{COLLECTION} | 201 Created | N | N |
| **Supported<br/>HTTP Methods** | OPTIONS | /{COLLECTION}/{INSTANCE_ID} | 204 No Content | Y | Y |
| **Exist** | HEAD | /{COLLECTION}/{INSTANCE_ID} | 204 No Content | Y | Y |
| **Read** | GET | /{COLLECTION}/{INSTANCE_ID} | 200 OK | Y | Y |
| **Update** | PUT | /{COLLECTION}/{INSTANCE_ID} | 200 OK | N | Y |
| **Patch** | PATCH | /{COLLECTION}/{INSTANCE_ID} | 200 OK | N | Y |
| **Delete** | DELETE | /{COLLECTION}/{INSTANCE_ID} | 204 No Content | N | N |
| **Purge** | PURGE | /{COLLECTION}/{INSTANCE_ID} | 204 No Content | N | N |
| **Purge** | DELETE | /{COLLECTION}/{INSTANCE_ID}?purge=true | 204 No Content | N | N |
| 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 |
| **Exists** | HEAD | /{COLLECTION} | 204 No Content | Y | Y |
| **Create** | POST | /{COLLECTION} | 201 Created | N | N |
| **Supported<br/>HTTP Methods** | OPTIONS | /{COLLECTION}/{INSTANCE_ID} | 204 No Content | Y | Y |
| **Exist** | HEAD | /{COLLECTION}/{INSTANCE_ID} | 204 No Content | Y | Y |
| **Read** | GET | /{COLLECTION}/{INSTANCE_ID} | 200 OK | Y | Y |
| **Update** | PUT | /{COLLECTION}/{INSTANCE_ID} | 200 OK | N | Y |
| **Patch** | PATCH | /{COLLECTION}/{INSTANCE_ID} | 200 OK | N | Y |
| **Delete** | DELETE | /{COLLECTION}/{INSTANCE_ID} | 204 No Content | N | N |
| **Purge** | PURGE | /{COLLECTION}/{INSTANCE_ID} | 204 No Content | N | N |
| **Purge** | DELETE | /{COLLECTION}/{INSTANCE_ID}?purge=true | 204 No Content | N | N |
### About URL

View File

@ -2,7 +2,7 @@
<enunciate
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.14.0.xsd">
<description package="org.gcube.acme.rest"/>
<description package="org.gcube.acme.rest" />
<api-classes>
<include pattern="org.gcube.acme.rest.*" />
<exclude pattern="org.gcube.acme.*" />
@ -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,12 +1,11 @@
<?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"
version="4.0"
metadata-complete="true">
<display-name>Identity Manager Service</display-name>
<description>
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"
version="4.0"
metadata-complete="true">
<display-name>Identity Manager Service</display-name>
<description>
A gcube service - smartgears 4
</description>
<servlet>
@ -16,4 +15,4 @@
<servlet-name>org.gcube.idm.IdentityManagerResourceInitializer</servlet-name>
<url-pattern>/idm/*</url-pattern>
</servlet-mapping>
</web-app>
</web-app>

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 {
@ -14,55 +14,52 @@ public class IdentityManagerApplicationManager implements ApplicationManager {
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(IdentityManagerApplicationManager.class);
public static boolean initialised;
/**
/**
* {@inheritDoc}
*/
@Override
public synchronized void onInit() {
String context = SecretManagerProvider.get().getContext();
logger.trace(
"\n-------------------------------------------------------\n"
+ "Identity Manager Service is Starting on context {}\n"
+ "-------------------------------------------------------",
context);
// ApplicationContext applicationContext = ContextProvider.get();
// String helloWorldEServiceID = applicationContext.id();
logger.trace(
"\n-------------------------------------------------------\n"
+ "Identity Manager Service Started Successfully on context {}\n"
+ "-------------------------------------------------------",
+ "Identity Manager Service is Starting on context {}\n"
+ "-------------------------------------------------------",
context);
// ApplicationContext applicationContext = ContextProvider.get();
// String helloWorldEServiceID = applicationContext.id();
logger.trace(
"\n-------------------------------------------------------\n"
+ "Identity Manager Service Started Successfully on context {}\n"
+ "-------------------------------------------------------",
context);
}
/**
* {@inheritDoc}
/**
* {@inheritDoc}
*/
@Override
public synchronized void onShutdown(){
public synchronized void onShutdown() {
String context = SecretManagerProvider.get().getContext();
logger.trace(
"\n-------------------------------------------------------\n"
+ "Identity Manager Service is Stopping on context {}\n"
+ "-------------------------------------------------------",
+ "Identity Manager Service is Stopping on context {}\n"
+ "-------------------------------------------------------",
context);
logger.trace(
"\n-------------------------------------------------------\n"
+ "Identity Manager Service Stopped Successfully on context {}\n"
+ "-------------------------------------------------------",
+ "Identity Manager Service Stopped Successfully on context {}\n"
+ "-------------------------------------------------------",
context);
}
}

View File

@ -12,116 +12,139 @@ import org.slf4j.LoggerFactory;
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 + "]";
}
}

View File

@ -10,7 +10,7 @@ import javax.ws.rs.HttpMethod;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Target({ElementType.METHOD})
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("PATCH")
public @interface PATCH {

View File

@ -10,7 +10,7 @@ import javax.ws.rs.HttpMethod;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Target({ElementType.METHOD})
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("PURGE")
public @interface PURGE {

View File

@ -16,24 +16,24 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR)
*/
public class HTTPUtility {
private static final Logger logger = LoggerFactory.getLogger(HTTPUtility.class);
public static StringBuilder getStringBuilder(InputStream inputStream) throws IOException {
StringBuilder result = new StringBuilder();
try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while((line = reader.readLine()) != null) {
while ((line = reader.readLine()) != null) {
result.append(line);
}
}
return result;
}
public static String getResultAsString(HttpURLConnection httpURLConnection) throws IOException {
int responseCode = httpURLConnection.getResponseCode();
if(responseCode >= Status.BAD_REQUEST.getStatusCode()) {
if (responseCode >= Status.BAD_REQUEST.getStatusCode()) {
Status status = Status.fromStatusCode(responseCode);
InputStream inputStream = httpURLConnection.getErrorStream();
StringBuilder result = getStringBuilder(inputStream);
@ -45,5 +45,5 @@ public class HTTPUtility {
logger.trace("Got Respose is {}", ret);
return ret;
}
}