Compare commits
4 Commits
c9d0281691
...
d89f456247
Author | SHA1 | Date |
---|---|---|
Alfredo Oliviero | d89f456247 | |
Alfredo Oliviero | e64b19bddf | |
Alfredo Oliviero | c7f147d1c9 | |
Alfredo Oliviero | 914197e3f2 |
|
@ -7,10 +7,10 @@
|
|||
{
|
||||
"type": "java",
|
||||
"name": "Debug (Attach)",
|
||||
"projectName": "identity-manager",
|
||||
"projectName": "helloword",
|
||||
"request": "attach",
|
||||
"hostName": "localhost",
|
||||
"port": 5005
|
||||
"port": 5001
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,3 +1,9 @@
|
|||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"Workspace_Formatter.excludePattern": [
|
||||
"**/build",
|
||||
"**/.*",
|
||||
"**/.vscode",
|
||||
"**/target/*"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
# instructions
|
||||
|
||||
## project structure
|
||||
|
||||
├── .gitignore
|
||||
├── pom.xml
|
||||
├── src
|
||||
│ └── ***
|
||||
├── gcube/
|
||||
│ └── extra-resources/
|
||||
│ └── WEB-INF/
|
||||
│ ├── application.yaml
|
||||
│ └── web.xml
|
||||
|
||||
# optional, for local develop in docker containers
|
||||
├── docker/
|
||||
│ ├── ontainer.ini
|
||||
│ └── logback.xml
|
||||
├── docker-compose.yaml
|
||||
└── Dockerfile
|
||||
|
||||
|
||||
### file details
|
||||
* gitignore: gitignore file for java projects
|
||||
|
||||
* pom.xml
|
||||
* <parent>: maven-parent configuration. currently 1.2.0 version
|
||||
* <properties><webappDirectory> : path for web.xml
|
||||
* <scm> ???
|
||||
* <dependencyManagement> gcube dependency manager
|
||||
|
||||
* docker/container.ini: configurations for the docker container.
|
||||
* mode: [online/offline]: register the service on IS. use offline for local docker instances
|
||||
|
||||
|
||||
|
||||
# EXCECUTION
|
||||
|
||||
start the docker container
|
||||
```./buildImageAndStart.sh```
|
||||
|
||||
test urls (replace {{TOKEN}} with your token):
|
||||
|
||||
|
||||
http://localhost:8081/helloworld/guest
|
||||
|
||||
http://localhost:8080/helloworld/details?gcube-token={{TOKEN}}
|
||||
http://localhost:8080/helloworld/hello/details?gcube-token={{TOKEN}}
|
||||
|
||||
http://localhost:8080/helloworld/auth?gcube-token={{TOKEN}} (checks for myRole role)
|
||||
http://localhost:8080/helloworld/auth/orm_member?gcube-token={{TOKEN}} (checks for OrganizationMember role)
|
||||
|
||||
|
||||
### Authentication:
|
||||
|
||||
#### GCUBE-TOKEN param
|
||||
|
||||
obtain personal token at https://next.dev.d4science.org/group/gcube/home
|
||||
|
||||
add
|
||||
|
||||
|
||||
### DEBUG
|
||||
|
||||
start the docker container in debug Mode
|
||||
```./buildImageAndStartWithDebug.sh```
|
||||
|
||||
connect the JAVA debugger to port 5005
|
||||
|
||||
* VSCODE: press the green play button and start "Debug (Attach)
|
||||
|
||||
|
34
README.md
34
README.md
|
@ -14,40 +14,6 @@ HelloWorld service for smartgears4
|
|||
## Documentation
|
||||
|
||||
|
||||
|
||||
start the docker container
|
||||
```./buildImageAndStart.sh```
|
||||
|
||||
test urls (replace {{TOKEN}} with your token):
|
||||
|
||||
|
||||
http://localhost:8080/helloworld/guest
|
||||
|
||||
http://localhost:8080/helloworld/details?gcube-token={{TOKEN}}
|
||||
http://localhost:8080/helloworld/hello/details?gcube-token={{TOKEN}}
|
||||
|
||||
http://localhost:8080/helloworld/auth?gcube-token={{TOKEN}} (checks for myRole role)
|
||||
http://localhost:8080/helloworld/auth/orm_member?gcube-token={{TOKEN}} (checks for OrganizationMember role)
|
||||
|
||||
|
||||
### Authentication:
|
||||
|
||||
#### GCUBE-TOKEN param
|
||||
|
||||
obtain personal token at https://next.dev.d4science.org/group/gcube/home
|
||||
|
||||
add
|
||||
|
||||
|
||||
### DEBUG
|
||||
|
||||
start the docker container in debug Mode
|
||||
```./buildImageAndStartWithDebug.sh```
|
||||
|
||||
connect the JAVA debugger to port 5005
|
||||
|
||||
* VSCODE: press the green play button and start "Debug (Attach)
|
||||
|
||||
## Change log
|
||||
|
||||
See [Releases](https://code-repo.d4science.org/gCubeSystem/helloworld/releases).
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
mvn clean package
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 smartgears-helloworld
|
||||
|
||||
NAME=smartgears-helloworld
|
||||
PORT=8081
|
||||
DEBUG_PORT=5001
|
||||
|
||||
docker build -t $NAME .
|
||||
docker run -p $PORT:8080 $NAME
|
|
@ -1,3 +1,9 @@
|
|||
mvn package
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 -p 5005:5005 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=y" smartgears-helloworld
|
||||
mvn clean package
|
||||
|
||||
NAME=smartgears-helloworld
|
||||
PORT=8081
|
||||
DEBUG_PORT=5001
|
||||
|
||||
docker build -t $NAME .
|
||||
|
||||
docker run -p $PORT:8080 -p $DEBUG_PORT:5005 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=y" $NAME
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
<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.service.helloworld" level="DEBUG" />
|
||||
<logger name="org.gcube.smartgears" level="DEBUG" />
|
||||
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
|
@ -311,7 +311,7 @@
|
|||
"variable": [
|
||||
{
|
||||
"key": "base_url",
|
||||
"value": "http://localhost:8080",
|
||||
"value": "http://localhost:8081",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
|
|
|
@ -5,4 +5,4 @@ description: HelloWorld Service
|
|||
excludes:
|
||||
- path: /excluded
|
||||
- path: /guest
|
||||
- path: /api-docs/*
|
||||
- path: /api-docs/*
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
<?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">
|
||||
<display-name>Hello World</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">
|
||||
<display-name>Hello World</display-name>
|
||||
<description>
|
||||
A gcube HelloWorld service - smartgears 4
|
||||
</description>
|
||||
<servlet>
|
||||
|
@ -15,4 +14,4 @@
|
|||
<servlet-name>org.gcube.service.helloworld.HelloWorld</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
||||
</web-app>
|
41
pom.xml
41
pom.xml
|
@ -2,23 +2,30 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.service</groupId>
|
||||
<artifactId>helloworld</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>Smartgears HelloWorld Service</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
<aspectj-plugin.version>1.14.0</aspectj-plugin.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
|
||||
<!-- OPTIONAL. for authorization-control-library -->
|
||||
<aspectj-plugin.version>1.14.0</aspectj-plugin.version>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
<connection>
|
||||
scm:git:https://code-repo.d4science.org/gCubeSystem/hello-world-sg4-service.git</connection>
|
||||
|
@ -26,6 +33,7 @@
|
|||
scm:git:https://code-repo.d4science.org/gCubeSystem/hello-world-sg4-service.git</developerConnection>
|
||||
<url>https://code-repo.d4science.org/gCubeSystem/hello-world-sg4-service.git</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -37,6 +45,7 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- smartgears -->
|
||||
<dependency>
|
||||
|
@ -55,6 +64,7 @@
|
|||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-smartgears-app</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- jersey -->
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
|
@ -64,6 +74,7 @@
|
|||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-servlet</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.inject/jersey-cdi2-se -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.inject</groupId>
|
||||
|
@ -74,6 +85,7 @@
|
|||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- add jackson as json provider -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
|
@ -84,10 +96,25 @@
|
|||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<!-- add this plugin if you want to use gcube authorization control funzionalities -->
|
||||
|
||||
<!-- OPTIONAL generate the war in a different folder, that will be mounted on docker
|
||||
container -->
|
||||
<!-- <plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<warName>identity-manager</warName>
|
||||
<outputDirectory>tomcat/webapps</outputDirectory>
|
||||
</configuration>
|
||||
</plugin> -->
|
||||
|
||||
<!-- OPTIONAL. authorization-control-library: add this plugin if you want to use gcube
|
||||
authorization control funzionalities -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.service.helloworld.manager;
|
||||
package org.gcube.service.helloworld;
|
||||
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.Secret;
|
||||
|
@ -23,8 +23,11 @@ public class HelloWorldManager implements ApplicationManager {
|
|||
|
||||
Logger logger = LoggerFactory.getLogger(HelloWorldManager.class);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void onInit() {
|
||||
public void onInit() {
|
||||
if (ContextProvider.get().container().configuration().mode() == Mode.offline) {
|
||||
logger.debug("init called in offline mode");
|
||||
} else {
|
||||
|
@ -37,6 +40,9 @@ public class HelloWorldManager implements ApplicationManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void onShutdown() {
|
||||
if (ContextProvider.get().container().configuration().mode() == Mode.offline) {
|
|
@ -9,9 +9,10 @@ import org.gcube.common.health.api.response.HealthCheckResponse;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* this class is used to add checks about components used by the service (DB, external FS, other services etc. )
|
||||
* this class is used to add checks about components used by the service (DB,
|
||||
* external FS, other services etc. )
|
||||
* and automatically exposed using the REST method webapp/gcube/resources/health
|
||||
*
|
||||
*
|
||||
|
@ -20,11 +21,10 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
|
||||
@ReadinessChecker
|
||||
public class CreateTempFileCheck implements HealthCheck{
|
||||
public class CreateTempFileCheck implements HealthCheck {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CreateTempFileCheck.class);
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "create temp file";
|
||||
|
@ -33,13 +33,13 @@ public class CreateTempFileCheck implements HealthCheck{
|
|||
@Override
|
||||
public HealthCheckResponse check() {
|
||||
try {
|
||||
File.createTempFile("exampleTest","txt");
|
||||
File.createTempFile("exampleTest", "txt");
|
||||
return HealthCheckResponse.builder(getName()).up().info("health check example").build();
|
||||
} catch (IOException e) {
|
||||
log.error("error checking defaultStorage",e);
|
||||
return HealthCheckResponse.builder(getName()).down().error(e.getMessage()).build();
|
||||
}
|
||||
|
||||
log.error("error checking defaultStorage", e);
|
||||
return HealthCheckResponse.builder(getName()).down().error(e.getMessage()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -32,7 +32,8 @@ public class AuthenticatedService {
|
|||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
return String.format(
|
||||
"User %s in context %s is authorized to execute this method because he has the role %s", userId, context, ALLOWED_ROLE_ORG);
|
||||
"User %s in context %s is authorized to execute this method because he has the role %s", userId,
|
||||
context, ALLOWED_ROLE_ORG);
|
||||
}
|
||||
|
||||
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE_MEMBER })
|
||||
|
@ -45,10 +46,10 @@ public class AuthenticatedService {
|
|||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
return String.format(
|
||||
"User %s in context %s is authorized to execute this method because he has the role %s", userId, context, ALLOWED_ROLE_MEMBER);
|
||||
"User %s in context %s is authorized to execute this method because he has the role %s", userId,
|
||||
context, ALLOWED_ROLE_MEMBER);
|
||||
}
|
||||
|
||||
|
||||
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE })
|
||||
@GET
|
||||
@Path("")
|
||||
|
@ -59,7 +60,8 @@ public class AuthenticatedService {
|
|||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
return String.format(
|
||||
"User %s in context %s is authorized to execute this method because he has the role %s", userId, context, ALLOWED_ROLE);
|
||||
"User %s in context %s is authorized to execute this method because he has the role %s", userId,
|
||||
context, ALLOWED_ROLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,20 +8,20 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
@Path("guest")
|
||||
public class ExcludeAuthorizationService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ExcludeAuthorizationService.class);
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ExcludeAuthorizationService.class);
|
||||
|
||||
/**
|
||||
* this method doesn't need authorization and the SecretManagerProvider is null
|
||||
* see to implement this behavior add to excludes section in your application.yaml
|
||||
* see to implement this behavior add to excludes section in your
|
||||
* application.yaml
|
||||
*
|
||||
* - path: /{path-to-your-method-path}
|
||||
*
|
||||
* example for this method
|
||||
*
|
||||
* - path: /excluded
|
||||
*
|
||||
* - path: /{path-to-your-method-path}
|
||||
*
|
||||
* example for this method
|
||||
*
|
||||
* - path: /excluded
|
||||
*
|
||||
*/
|
||||
@GET
|
||||
public String exludedMethod() {
|
||||
|
|
|
@ -12,7 +12,7 @@ import javax.ws.rs.core.Response;
|
|||
import org.gcube.common.security.Owner;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.service.helloworld.manager.HelloWorldManager;
|
||||
import org.gcube.service.helloworld.HelloWorldManager;
|
||||
import org.gcube.service.helloworld.serializers.ContextSerializator;
|
||||
import org.gcube.smartgears.ContextProvider;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
|
|
Loading…
Reference in New Issue