Mentions légales du service

Skip to content
Snippets Groups Projects
Commit a2933aaf authored by Wylem Bars's avatar Wylem Bars
Browse files

IUAINFRA-52 | Create dummy REST service

parent 281ac39f
No related branches found
No related tags found
1 merge request!2Feature/iuainfra 52
Showing
with 230 additions and 17 deletions
Put here classes from adapter layer :
Data transformers, adapters, presenters or DAO. Abstraction of external libraries for
application or business use.
Web-services point, sockets, database connection and pool, GUI, file system, framework,
external libraries.
\ No newline at end of file
......@@ -3,26 +3,45 @@ package net.ihe.gazelle.app.accesstokenproviderapi.application;
import net.ihe.gazelle.app.accesstokenproviderapi.business.AccessTokenRequest;
import net.ihe.gazelle.app.accesstokenproviderapi.business.SymmetricSignature;
import net.ihe.gazelle.app.audienceretriever.adapter.AudienceSecretRetrieverForSoapui;
import net.ihe.gazelle.app.audienceretriever.adapter.AudienceSecretRetrieverImpl;
import net.ihe.gazelle.app.audienceretriever.application.AudienceSecretRetriever;
import net.ihe.gazelle.modelapi.sb.business.EncodingException;
import net.ihe.gazelle.sb.iua.business.TokenType;
import java.time.Duration;
public class DummyAuthzServerSoapui implements DummyAuthzServer {
public class DummyAuthzServerSoapui implements DummyAuthzServer {
private static final String ALGORITHM = "HS256";
private static final String ISSUER = "https://ehealthsuisse.ihe-europe.net/access-token-provider";
private static final TokenType TOKEN_TYPE = TokenType.JWT;
private static final Duration DURATION = Duration.ofHours(1);
private AudienceSecretRetriever audienceSecretRetriever;
/**
* Default constructor for the class.
*/
public DummyAuthzServerSoapui() {
audienceSecretRetriever = new AudienceSecretRetrieverForSoapui();
}
/**
* Setter for the audienceSecretRetriever property.
*
* @param audienceSecretRetriever value to set to the property.
*/
public void setAudienceSecretRetriever(AudienceSecretRetriever audienceSecretRetriever) {
this.audienceSecretRetriever = audienceSecretRetriever;
}
/**
* {@inheritDoc}
*/
@Override
public byte[] getAccessToken(String userId, String audienceId, String purposeOfUse, String resourceId) {
//todo purposeOfUse and resourceId are not yet implemented
TokenGenerator tokenGenerator = new TokenGenerator();
tokenGenerator.setAudienceSecretRetriever(new AudienceSecretRetrieverForSoapui());
tokenGenerator.setAudienceSecretRetriever(audienceSecretRetriever);
return getTokenGenerator(userId, audienceId, tokenGenerator);
}
......
Put here classes from application layer :
Use cases. Business elements applied in an application context or scenario.
\ No newline at end of file
Put here classes from business layer :
Business model, rules and constraints. Always true. Independent from the application.
\ No newline at end of file
package net.ihe.gazelle.app.accesstokenproviderapi.application;
import net.ihe.gazelle.app.audienceretriever.application.AudienceSecretRetriever;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
......@@ -11,7 +12,8 @@ class DummyAuthzServerSoapuiTest {
@Test
public void test() {
DummyAuthzServerSoapui dummyAuthzServer = new DummyAuthzServerSoapui();
dummyAuthzServer.setAudienceSecretRetriever((String audience) -> "secret");
assertNotNull(dummyAuthzServer.getAccessToken(SUBJECT, AUDIENCE, null, null));
}
}
......@@ -32,6 +32,14 @@
<artifactId>framework.preferences-model-api</artifactId>
<version>1.0.0</version>
</dependency>
<!-- Implementation of Operational Preferences -->
<dependency>
<groupId>net.ihe.gazelle</groupId>
<artifactId>framework.operational-preferences-service</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>app.access-token-provider</artifactId>
<groupId>net.ihe.gazelle</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>net.ihe.gazelle</groupId>
<artifactId>app.dummy-authorization-server-service</artifactId>
<name>Dummy Authorization Server Service</name>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.ihe.gazelle</groupId>
<artifactId>app.access-token-provider-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package net.ihe.gazelle.app.dummyauthorizationserverservice.adapter;
import net.ihe.gazelle.app.accesstokenproviderapi.application.DummyAuthzServer;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
import java.nio.charset.StandardCharsets;
@Provider
@Path(value="/mock-token")
public class AuthorizationServerService {
@GET
public byte[] getAccessToken(String userId, String audienceId, String purposeOfUse, String resourceId){
// TODO Put real implementation but it doesn't work right now
// DummyAuthzServer dummyAuthzServer = new DummyAuthzServerSoapui();
DummyAuthzServer dummyAuthzServer = new DummyAuthzServer() {
@Override
public byte[] getAccessToken(String userId, String audienceId, String purposeOfUse, String resourceId) {
return "Tartes aux pommes".getBytes(StandardCharsets.UTF_8);
}
};
return dummyAuthzServer.getAccessToken(userId, audienceId, purposeOfUse, resourceId);
}
}
package net.ihe.gazelle.app.dummyauthorizationserverservice.adapter;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
/**
* Our Application
*/
@ApplicationPath("/")
public class DummyAuthorizationServerServiceApplication extends Application {
/**
* {@inheritDoc}
*/
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<>();
s.add(AuthorizationServerService.class);
return s;
}
}
package net.ihe.gazelle.app.dummyauthorizationserverservice.adapter;
import net.ihe.gazelle.framework.preferencesmodelapi.application.OperationalPreferencesClientApplication;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Define mandatory preferences.
*/
public class OperationalPreferencesDummy implements OperationalPreferencesClientApplication {
/**
* {@inheritDoc}
*/
@Override
public Map<String, List<String>> wantedMandatoryPreferences() {
return new HashMap<>();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans bean-discovery-mode="all" version="2.0"
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/beans_2_0.xsd">
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>authorization-server</context-root>
</jboss-web>
\ No newline at end of file
<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_3_1.xsd"
version="3.1">
</web-app>
package net.ihe.gazelle.app.dummyauthorizationserverservice.adapter;
import net.ihe.gazelle.app.accesstokenproviderapi.application.DummyAuthzServerSoapui;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AuthorizationServerServiceTest {
private static final String SUBJECT = "aamrein";
private static final String AUDIENCE = "audience";
/**
* Test the generation of a token
*/
@Test
public void getAccessToken() {
AuthorizationServerService authorizationServerService = new AuthorizationServerService();
assertNotNull(authorizationServerService.getAccessToken(SUBJECT, AUDIENCE, null, null));
}
}
\ No newline at end of file
package net.ihe.gazelle.app.dummyauthorizationserverservice.adapter;
import org.junit.jupiter.api.Test;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class DummyAuthorizationServerServiceApplicationTest {
/**
* Test class getter.
*/
@Test
void getClasses() {
DummyAuthorizationServerServiceApplication application = new DummyAuthorizationServerServiceApplication();
Set classes = application.getClasses();
assertNotNull(classes, "Classes map shall not be null !");
assertEquals(1, classes.size(), "Classes map shall contain a single element !");
}
}
\ No newline at end of file
package net.ihe.gazelle.app.dummyauthorizationserverservice.adapter;
import net.ihe.gazelle.framework.preferencesmodelapi.application.OperationalPreferencesClientApplication;
import net.ihe.gazelle.framework.preferencesmodelapi.application.OperationalPreferencesService;
import org.junit.jupiter.api.Test;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
class OperationalPreferencesDummyTest {
/**
* Test wanted mandatroy preferences list.
*/
@Test
void wantedMandatoryPreferences() {
OperationalPreferencesClientApplication operationalPreferencesService = new OperationalPreferencesDummy();
Map wantedMandatoryPreferences = operationalPreferencesService.wantedMandatoryPreferences();
assertNotNull(wantedMandatoryPreferences, "Wanted Mandatory Preferences map shall not be null !");
assertEquals(0, wantedMandatoryPreferences.entrySet().size(), "Wanted Mandatory Preferences map shall be empty");
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.ihe.gazelle</groupId>
......@@ -200,5 +199,6 @@
<modules>
<module>access-token-provider-api</module>
<module>audience-retriever</module>
</modules>
<module>dummy-authorization-server-service</module>
</modules>
</project>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment