You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2019/09/03 13:43:25 UTC
[airavata-custos] 30/45: added readme, log4j properties files,
samples for end to end testing of services and deleted unnecessary
configuration files
This is an automated email from the ASF dual-hosted git repository.
smarru pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit 5595257d48fb1ba2e5528d74083d73831d2586e7
Author: Aarushi <aa...@gmail.com>
AuthorDate: Thu Aug 22 18:45:43 2019 -0400
added readme, log4j properties files, samples for end to end testing of services and deleted unnecessary configuration files
---
.../handler/CustosAuthenticationHandler.java | 2 +-
custos-commons/custos-server.properties | 0
.../src/main/resources/custos-server.properties | 10 +-
.../src/main/resources/keystores/airavata.jks | Bin 2679 -> 0 bytes
.../src/main/resources/keystores/airavata_sym.jks | Bin 501 -> 0 bytes
.../main/resources/keystores/client_truststore.jks | Bin 1027 -> 963 bytes
ide-integration/README.md | 64 ++++++++++++
.../sample/CustosAuthenticationServiceSample.java | 108 ---------------------
.../src/main/resources/custos-server.properties | 8 +-
.../src/main/resources/docker-compose.yml | 2 +-
.../src/main/resources/keycloak/standalone.xml | 2 +-
.../src/main/resources/keystores/airavata.jks | Bin 2679 -> 0 bytes
.../src/main/resources/keystores/airavata_sym.jks | Bin 501 -> 0 bytes
.../main/resources/keystores/client_truststore.jks | Bin 1027 -> 0 bytes
.../src/main/resources/keystores/custos.jks | Bin 0 -> 2252 bytes
.../src/main/resources}/log4j.properties | 8 +-
ide-integration/pom.xml | 3 +-
.../commons}/pom.xml | 4 +-
.../org/apache/samples/common/SamplesCommon.java | 60 ++++++++++++
.../custos-authentication-service-samples/pom.xml | 8 ++
.../sample/CustosAuthenticationServiceSample.java | 64 ++++++++++++
.../src/main/resources/log4j.properties | 10 +-
.../custos-profile-service-samples/pom.xml | 7 ++
.../service/samples/TenantProfileSample.java | 0
.../profile/service/samples/UserProfileSample.java | 89 ++++-------------
.../samples/utils/ProfileServiceClientUtil.java | 0
.../src/main/resources/log4j.properties | 10 +-
.../resources/profile-client-sample.properties | 0
.../pom.xml | 9 +-
29 files changed, 255 insertions(+), 213 deletions(-)
diff --git a/custos-authentication/src/main/java/org/apache/custos/authentication/handler/CustosAuthenticationHandler.java b/custos-authentication/src/main/java/org/apache/custos/authentication/handler/CustosAuthenticationHandler.java
index 8a7de8c..8706071 100644
--- a/custos-authentication/src/main/java/org/apache/custos/authentication/handler/CustosAuthenticationHandler.java
+++ b/custos-authentication/src/main/java/org/apache/custos/authentication/handler/CustosAuthenticationHandler.java
@@ -20,7 +20,7 @@ public class CustosAuthenticationHandler implements CustosAuthenticationService.
CustosSecurityManager securityManager = SecurityManagerFactory.getSecurityManager();
boolean isAuth = securityManager.isUserAuthenticated(authzToken);
if (isAuth) {
- logger.info("User" + authzToken.getClaimsMap().get(Constants.USER_NAME) + "in gateway" + authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + "is authenticated");
+ logger.info("User " + authzToken.getClaimsMap().get(Constants.USER_NAME) + " in gateway " + authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + " is authenticated");
return isAuth;
}
else{
diff --git a/custos-commons/custos-server.properties b/custos-commons/custos-server.properties
deleted file mode 100644
index e69de29..0000000
diff --git a/custos-commons/src/main/resources/custos-server.properties b/custos-commons/src/main/resources/custos-server.properties
index d9d59c3..c5d0b2f 100644
--- a/custos-commons/src/main/resources/custos-server.properties
+++ b/custos-commons/src/main/resources/custos-server.properties
@@ -34,16 +34,16 @@ security.manager.class=org.apache.custos.security.manager.KeyCloakSecurityManage
###########################################################################
# Iam Admin services Configuration
###########################################################################
-iam.server.url=https://airavata.host:8443/auth
+iam.server.url=https://localhost:8443/auth
iam.server.super.admin.username=admin
iam.server.super.admin.password=admin
#### keystore configuration ####
-keystore.path=keystores/airavata.jks
-keystore.password=airavata
+keystore.path=keystores/custos.jks
+keystore.password=custos
#### trust store configuration ####
trust.store=keystores/client_truststore.jks
-trust.store.password=airavata
+trust.store.password=custos
#### authorization cache related configuration ####
authz.cache.enabled=true
@@ -54,7 +54,7 @@ in.memory.cache.size=1000
# Profile Service Configuration
###########################################################################
profile.service.server.host=0.0.0.0
-profile.service.server.port=9092
+profile.service.server.port=8081
profile_service=org.apache.custos.profile.server.ProfileServiceServer
# MariaDB properties
diff --git a/custos-connectors/src/main/resources/keystores/airavata.jks b/custos-connectors/src/main/resources/keystores/airavata.jks
deleted file mode 100644
index b732322..0000000
Binary files a/custos-connectors/src/main/resources/keystores/airavata.jks and /dev/null differ
diff --git a/custos-connectors/src/main/resources/keystores/airavata_sym.jks b/custos-connectors/src/main/resources/keystores/airavata_sym.jks
deleted file mode 100644
index 57434f0..0000000
Binary files a/custos-connectors/src/main/resources/keystores/airavata_sym.jks and /dev/null differ
diff --git a/custos-connectors/src/main/resources/keystores/client_truststore.jks b/custos-connectors/src/main/resources/keystores/client_truststore.jks
index a7a604c..6b16a4f 100644
Binary files a/custos-connectors/src/main/resources/keystores/client_truststore.jks and b/custos-connectors/src/main/resources/keystores/client_truststore.jks differ
diff --git a/ide-integration/README.md b/ide-integration/README.md
new file mode 100644
index 0000000..a54aacf
--- /dev/null
+++ b/ide-integration/README.md
@@ -0,0 +1,64 @@
+## Introduction
+
+This module is to setup custos authentication, profile services inside Intelij IDEA for development purposes
+
+## Prerequisites
+
+* Docker installed with 'docker-compose' utility
+ https://docs.docker.com/compose/
+
+* InteliJ IDEA with Java 8 installed
+ https://www.jetbrains.com/idea/download/
+
+* Maven
+
+* Git
+
+## Steps
+
+### Setting up the development environment
+
+* Clone Custos repository to a local directory
+
+ ```
+ git clone https://github.com/apache/airavata-custos
+ ```
+
+* Checkout develop branch
+ ```
+ git checkout develop
+ ```
+* Open the project using InteliJ IDEA
+
+* Browse to ide-integration -> custos-services -> src-> main -> resources
+
+* start the docker containers
+
+ ```
+ docker-compose up -d
+ ```
+* check if docker containers are up
+ ```
+ docker-compose ps
+ ```
+
+* Build the develop branch using Maven
+
+
+### Starting the services
+
+* Go to org.apache.custos.server.start.CustosAPIServerStarter class and right click on the editor and click Run option. This will start profile and authentication server.
+* The port on which profile and authentication service run can be changed in the custos-server.properties file found in the resources folder.
+* Once the services are up and running. Go to org.apache.custos.profile.service.samples to run code samples for tenant and profile services and org.apache.custos.authentication.service.sample.CustosAuthenticationServiceSample
+
+### Stop all components
+
+* For each composer file, run following commands to cleanup docker spawned components
+
+ ```
+ docker-compose down
+ ```
+
+ ```
+ docker-compose rm
+ ```
diff --git a/ide-integration/custos-authentication-service-samples/src/main/java/org/apache/custos/authentication/service/sample/CustosAuthenticationServiceSample.java b/ide-integration/custos-authentication-service-samples/src/main/java/org/apache/custos/authentication/service/sample/CustosAuthenticationServiceSample.java
deleted file mode 100644
index ac2c122..0000000
--- a/ide-integration/custos-authentication-service-samples/src/main/java/org/apache/custos/authentication/service/sample/CustosAuthenticationServiceSample.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package org.apache.custos.authentication.service.sample;
-
-import org.apache.custos.authentication.cpi.CustosAuthenticationService;
-import org.apache.custos.client.authentication.service.AuthenticationServiceClientFactory;
-import org.apache.custos.commons.exceptions.CustosSecurityException;
-import org.apache.custos.commons.model.security.AuthzToken;
-import org.apache.custos.commons.utils.Constants;
-import org.apache.custos.security.manager.KeyCloakSecurityManager;
-import org.apache.http.Consts;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.util.EntityUtils;
-import org.apache.thrift.TException;
-import org.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-public class CustosAuthenticationServiceSample {
-
- private static final Logger log = LoggerFactory.getLogger(CustosAuthenticationServiceSample.class);
- //present in keycloak json configuration
- public static String USERNAME = "default-admin";
- public static String GATEWAY_ID = "default";
-
- public static void main(String[] args) throws Exception{
-
- try {
- //change this based on the port on which the server is started
- String serverHost = "localhost";
- int serverPort = 9091;
- CustosAuthenticationService.Client client = AuthenticationServiceClientFactory.createAuthenticationServiceClient(serverHost, serverPort);
- testUserAuthentication(client);
- }catch (TException e) {
- throw new Exception(e);
- }catch (Exception e){
- throw new Exception("Error setting up the authentication server", e);
- }
- }
-
- public static void testUserAuthentication(CustosAuthenticationService.Client client) throws TException, CustosSecurityException {
- boolean authenticated = false;
- new KeyCloakSecurityManager().initializeSecurityInfra();
- AuthzToken authzToken = new AuthzToken();
- HashMap<String, String> map_ = new HashMap<>();
- map_.put(Constants.GATEWAY_ID, GATEWAY_ID);
- map_.put(Constants.USER_NAME, USERNAME);
- authzToken.setClaimsMap(map_);
- JSONObject json = getAccessToken();
- if(json.has("access_token")){
- String access_token = getAccessToken().get("access_token").toString();
- authzToken.setAccessToken(access_token);
- authenticated = client.isUserAuthenticated(authzToken);
- }
-
- assert (authenticated): "User authenticating failed";
- if(authenticated){
- log.info("User successfully authenticated");
- }
-
- }
-
- private static JSONObject getAccessToken() {
- String password = "123456";
- String tokenEndPoint = "https://airavata.host:8443/auth/realms/default/protocol/openid-connect/token";
- String grant_type = "password";
- String client_id = "admin-cli";
-
- CloseableHttpClient httpClient = HttpClients.createSystem();
- HttpPost httpPost = new HttpPost(tokenEndPoint);
- ;
- List<NameValuePair> formParams = new ArrayList<>();
- formParams.add(new BasicNameValuePair("grant_type", "password"));
- formParams.add(new BasicNameValuePair("client_id", client_id));
- formParams.add(new BasicNameValuePair("username", USERNAME));
- formParams.add(new BasicNameValuePair("password", password));
- UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, Consts.UTF_8);
- httpPost.setEntity(entity);
- try {
- CloseableHttpResponse response = httpClient.execute(httpPost);
- try {
- String responseBody = EntityUtils.toString(response.getEntity());
- JSONObject tokenInfo = new JSONObject(responseBody);
- return tokenInfo;
- } finally {
- response.close();
- }
-
- } catch (IOException e) {
- throw new RuntimeException(e);
- } finally {
- try {
- httpClient.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
-}
diff --git a/ide-integration/custos-services/src/main/resources/custos-server.properties b/ide-integration/custos-services/src/main/resources/custos-server.properties
index 2e07020..c5d0b2f 100644
--- a/ide-integration/custos-services/src/main/resources/custos-server.properties
+++ b/ide-integration/custos-services/src/main/resources/custos-server.properties
@@ -34,16 +34,16 @@ security.manager.class=org.apache.custos.security.manager.KeyCloakSecurityManage
###########################################################################
# Iam Admin services Configuration
###########################################################################
-iam.server.url=https://airavata.host:8443/auth
+iam.server.url=https://localhost:8443/auth
iam.server.super.admin.username=admin
iam.server.super.admin.password=admin
#### keystore configuration ####
-keystore.path=keystores/airavata.jks
-keystore.password=airavata
+keystore.path=keystores/custos.jks
+keystore.password=custos
#### trust store configuration ####
trust.store=keystores/client_truststore.jks
-trust.store.password=airavata
+trust.store.password=custos
#### authorization cache related configuration ####
authz.cache.enabled=true
diff --git a/ide-integration/custos-services/src/main/resources/docker-compose.yml b/ide-integration/custos-services/src/main/resources/docker-compose.yml
index 5ced9a8..e43b9ec 100644
--- a/ide-integration/custos-services/src/main/resources/docker-compose.yml
+++ b/ide-integration/custos-services/src/main/resources/docker-compose.yml
@@ -10,7 +10,7 @@ services:
- "8443:8443"
volumes:
- ./keycloak/Default-export.json:/opt/keycloak/Default-export.json
- - ./keystores/airavata.jks:/opt/jboss/keycloak/standalone/configuration/keystores/airavata.jks
+ - ./keystores/custos.jks:/opt/jboss/keycloak/standalone/configuration/keystores/custos.jks
- ./keycloak/standalone.xml:/opt/jboss/keycloak/standalone/configuration/standalone.xml
command: ["-b", "0.0.0.0", "-Dkeycloak.migration.action=import", "-Dkeycloak.migration.provider=singleFile", "-Dkeycloak.migration.file=/opt/keycloak/Default-export.json", "-Dkeycloak.migration.strategy=OVERWRITE_EXISTING"]
db:
diff --git a/ide-integration/custos-services/src/main/resources/keycloak/standalone.xml b/ide-integration/custos-services/src/main/resources/keycloak/standalone.xml
index f3eaea9..83006ef 100644
--- a/ide-integration/custos-services/src/main/resources/keycloak/standalone.xml
+++ b/ide-integration/custos-services/src/main/resources/keycloak/standalone.xml
@@ -47,7 +47,7 @@
<security-realm name="UndertowRealm">
<server-identities>
<ssl>
- <keystore path="keystores/airavata.jks" relative-to="jboss.server.config.dir" keystore-password="airavata" />
+ <keystore path="keystores/custos.jks" relative-to="jboss.server.config.dir" keystore-password="custos" />
</ssl>
</server-identities>
</security-realm>
diff --git a/ide-integration/custos-services/src/main/resources/keystores/airavata.jks b/ide-integration/custos-services/src/main/resources/keystores/airavata.jks
deleted file mode 100644
index b732322..0000000
Binary files a/ide-integration/custos-services/src/main/resources/keystores/airavata.jks and /dev/null differ
diff --git a/ide-integration/custos-services/src/main/resources/keystores/airavata_sym.jks b/ide-integration/custos-services/src/main/resources/keystores/airavata_sym.jks
deleted file mode 100644
index 57434f0..0000000
Binary files a/ide-integration/custos-services/src/main/resources/keystores/airavata_sym.jks and /dev/null differ
diff --git a/ide-integration/custos-services/src/main/resources/keystores/client_truststore.jks b/ide-integration/custos-services/src/main/resources/keystores/client_truststore.jks
deleted file mode 100644
index a7a604c..0000000
Binary files a/ide-integration/custos-services/src/main/resources/keystores/client_truststore.jks and /dev/null differ
diff --git a/ide-integration/custos-services/src/main/resources/keystores/custos.jks b/ide-integration/custos-services/src/main/resources/keystores/custos.jks
new file mode 100644
index 0000000..05a4a06
Binary files /dev/null and b/ide-integration/custos-services/src/main/resources/keystores/custos.jks differ
diff --git a/ide-integration/log4j.properties b/ide-integration/custos-services/src/main/resources/log4j.properties
similarity index 83%
rename from ide-integration/log4j.properties
rename to ide-integration/custos-services/src/main/resources/log4j.properties
index 0328252..4313d4a 100644
--- a/ide-integration/log4j.properties
+++ b/ide-integration/custos-services/src/main/resources/log4j.properties
@@ -17,16 +17,14 @@
# under the License.
#
-# Set root category priority to INFO and its only appender to CONSOLE.
-log4j.rootCategory=INFO, ERROR, CONSOLE,LOGFILE
-log4j.rootLogger=INFO, ERROR, CONSOLE, LOGFILE
-
+log4j.rootCategory=INFO, CONSOLE, LOGFILE
+log4j.rootLogger=INFO, CONSOLE, LOGFILE
+
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %m%n
-# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=./target/custos-server.log
log4j.appender.LOGFILE.Append=true
diff --git a/ide-integration/pom.xml b/ide-integration/pom.xml
index a91f3dc..969fd9f 100644
--- a/ide-integration/pom.xml
+++ b/ide-integration/pom.xml
@@ -12,9 +12,8 @@
<artifactId>ide-integration</artifactId>
<packaging>pom</packaging>
<modules>
- <module>custos-profile-service-samples</module>
- <module>custos-authentication-service-samples</module>
<module>custos-services</module>
+ <module>samples</module>
</modules>
<dependencies>
<dependency>
diff --git a/ide-integration/custos-profile-service-samples/pom.xml b/ide-integration/samples/commons/pom.xml
similarity index 77%
copy from ide-integration/custos-profile-service-samples/pom.xml
copy to ide-integration/samples/commons/pom.xml
index 070cda2..e8aa003 100644
--- a/ide-integration/custos-profile-service-samples/pom.xml
+++ b/ide-integration/samples/commons/pom.xml
@@ -3,13 +3,13 @@
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">
<parent>
- <artifactId>ide-integration</artifactId>
+ <artifactId>samples</artifactId>
<groupId>org.apache.custos</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>custos-profile-service-samples</artifactId>
+ <artifactId>commons</artifactId>
</project>
\ No newline at end of file
diff --git a/ide-integration/samples/commons/src/main/java/org/apache/samples/common/SamplesCommon.java b/ide-integration/samples/commons/src/main/java/org/apache/samples/common/SamplesCommon.java
new file mode 100644
index 0000000..9f508b4
--- /dev/null
+++ b/ide-integration/samples/commons/src/main/java/org/apache/samples/common/SamplesCommon.java
@@ -0,0 +1,60 @@
+package org.apache.samples.common;
+
+import org.apache.custos.commons.exceptions.CustosSecurityException;
+import org.apache.custos.security.manager.KeyCloakSecurityManager;
+import org.apache.http.Consts;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class SamplesCommon {
+
+ public static JSONObject getAccessToken(String username, String password, String clientId, String grant_type) throws CustosSecurityException {
+ new KeyCloakSecurityManager().initializeSecurityInfra();
+ if(password == null) {
+ //keeping a default password for testing
+ password = "123456";
+ }
+ String tokenEndPoint = "https://localhost:8443/auth/realms/default/protocol/openid-connect/token";
+
+ CloseableHttpClient httpClient = HttpClients.createSystem();
+ HttpPost httpPost = new HttpPost(tokenEndPoint);
+ ;
+ List<NameValuePair> formParams = new ArrayList<>();
+ formParams.add(new BasicNameValuePair("grant_type", grant_type));
+ formParams.add(new BasicNameValuePair("client_id", clientId));
+ formParams.add(new BasicNameValuePair("username", username));
+ formParams.add(new BasicNameValuePair("password", password));
+ UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, Consts.UTF_8);
+ httpPost.setEntity(entity);
+ try {
+ CloseableHttpResponse response = httpClient.execute(httpPost);
+ try {
+ String responseBody = EntityUtils.toString(response.getEntity());
+ JSONObject tokenInfo = new JSONObject(responseBody);
+ return tokenInfo;
+ } finally {
+ response.close();
+ }
+
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ try {
+ httpClient.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
diff --git a/ide-integration/custos-authentication-service-samples/pom.xml b/ide-integration/samples/custos-authentication-service-samples/pom.xml
similarity index 66%
copy from ide-integration/custos-authentication-service-samples/pom.xml
copy to ide-integration/samples/custos-authentication-service-samples/pom.xml
index 5a035cd..37037fc 100644
--- a/ide-integration/custos-authentication-service-samples/pom.xml
+++ b/ide-integration/samples/custos-authentication-service-samples/pom.xml
@@ -10,6 +10,14 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>custos-authentication-service-samples</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.custos</groupId>
+ <artifactId>commons</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
diff --git a/ide-integration/samples/custos-authentication-service-samples/src/main/java/org/apache/custos/authentication/service/sample/CustosAuthenticationServiceSample.java b/ide-integration/samples/custos-authentication-service-samples/src/main/java/org/apache/custos/authentication/service/sample/CustosAuthenticationServiceSample.java
new file mode 100644
index 0000000..4fb0be0
--- /dev/null
+++ b/ide-integration/samples/custos-authentication-service-samples/src/main/java/org/apache/custos/authentication/service/sample/CustosAuthenticationServiceSample.java
@@ -0,0 +1,64 @@
+package org.apache.custos.authentication.service.sample;
+
+import org.apache.custos.authentication.cpi.CustosAuthenticationService;
+import org.apache.custos.client.authentication.service.AuthenticationServiceClientFactory;
+import org.apache.custos.commons.model.security.AuthzToken;
+import org.apache.custos.commons.utils.Constants;
+import org.apache.custos.commons.utils.ServerSettings;
+import org.apache.samples.common.SamplesCommon;
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.HashMap;
+
+public class CustosAuthenticationServiceSample {
+
+ private static final Logger log = LoggerFactory.getLogger(CustosAuthenticationServiceSample.class);
+ //present in keycloak json configuration
+ public static String USERNAME = "default-admin";
+ public static String GATEWAY_ID = "default";
+ public static AuthzToken authzToken;
+
+ public static void main(String[] args){
+
+ try {
+ String serverHost = ServerSettings.getAuthenticationServerHost();
+ int serverPort = Integer.parseInt(ServerSettings.getAuthenticationServerPort());
+ CustosAuthenticationService.Client client = AuthenticationServiceClientFactory.createAuthenticationServiceClient(serverHost, serverPort);
+ testUserAuthentication(client);
+ }catch (Exception e){
+ log.error("Error setting up the authentication server");
+ }
+ }
+
+ public static void testUserAuthentication(CustosAuthenticationService.Client client){
+ try{
+ initializeAuthzToken();
+ boolean authenticated = client.isUserAuthenticated(authzToken);
+ assert (authenticated): "User not authenticated failed. Authentication test failed";
+ if(authenticated){
+ log.info("User successfully authenticated");
+ }
+ }catch (Exception e){
+ log.error("Test userAuthentication Failed!!", e);
+ }
+ }
+ private static void initializeAuthzToken() throws Exception{
+ try{
+ authzToken = new AuthzToken();
+ HashMap<String, String> map = new HashMap<>();
+ map.put(Constants.USER_NAME, USERNAME);
+ map.put(Constants.GATEWAY_ID, GATEWAY_ID);
+ authzToken.setClaimsMap(map);
+ JSONObject json = SamplesCommon.getAccessToken(USERNAME, null, "admin-cli", "password");
+ if(json.has("access_token")){
+ authzToken.setAccessToken(json.get("access_token").toString());
+ }else{
+ throw new Exception("Check if the user exists in keycloak");
+ }
+ }catch (Exception e) {
+ throw new Exception("Could not get access token", e);
+ }
+
+ }
+}
diff --git a/custos-profile-service/profile-service-server/src/main/resources/log4j.properties b/ide-integration/samples/custos-authentication-service-samples/src/main/resources/log4j.properties
similarity index 80%
rename from custos-profile-service/profile-service-server/src/main/resources/log4j.properties
rename to ide-integration/samples/custos-authentication-service-samples/src/main/resources/log4j.properties
index 2827ca2..31d6017 100644
--- a/custos-profile-service/profile-service-server/src/main/resources/log4j.properties
+++ b/ide-integration/samples/custos-authentication-service-samples/src/main/resources/log4j.properties
@@ -17,18 +17,16 @@
# under the License.
#
-# Set root category priority to INFO and its only appender to CONSOLE.
-log4j.rootCategory=INFO, ERROR, CONSOLE,LOGFILE
-log4j.rootLogger=INFO, ERROR, CONSOLE, LOGFILE
-
+log4j.rootCategory=INFO, CONSOLE, LOGFILE
+log4j.rootLogger=INFO, CONSOLE, LOGFILE
+
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %m%n
-# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
-log4j.appender.LOGFILE.File=./target/custos.log
+log4j.appender.LOGFILE.File=./target/custos-server-test.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
diff --git a/ide-integration/custos-profile-service-samples/pom.xml b/ide-integration/samples/custos-profile-service-samples/pom.xml
similarity index 69%
rename from ide-integration/custos-profile-service-samples/pom.xml
rename to ide-integration/samples/custos-profile-service-samples/pom.xml
index 070cda2..cce4841 100644
--- a/ide-integration/custos-profile-service-samples/pom.xml
+++ b/ide-integration/samples/custos-profile-service-samples/pom.xml
@@ -10,6 +10,13 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>custos-profile-service-samples</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.custos</groupId>
+ <artifactId>commons</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
diff --git a/ide-integration/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/TenantProfileSample.java b/ide-integration/samples/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/TenantProfileSample.java
similarity index 100%
rename from ide-integration/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/TenantProfileSample.java
rename to ide-integration/samples/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/TenantProfileSample.java
diff --git a/ide-integration/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/UserProfileSample.java b/ide-integration/samples/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/UserProfileSample.java
similarity index 69%
rename from ide-integration/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/UserProfileSample.java
rename to ide-integration/samples/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/UserProfileSample.java
index 41255fc..66c9055 100644
--- a/ide-integration/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/UserProfileSample.java
+++ b/ide-integration/samples/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/UserProfileSample.java
@@ -20,42 +20,30 @@
package org.apache.custos.profile.service.samples;
import org.apache.custos.client.profile.service.CustosProfileServiceClientFactory;
-import org.apache.custos.commons.exceptions.CustosSecurityException;
import org.apache.custos.commons.model.security.AuthzToken;
import org.apache.custos.commons.utils.Constants;
import org.apache.custos.profile.model.user.*;
import org.apache.custos.profile.service.samples.utils.ProfileServiceClientUtil;
import org.apache.custos.profile.user.cpi.UserProfileService;
-import org.apache.custos.security.manager.KeyCloakSecurityManager;
-import org.apache.http.Consts;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.util.EntityUtils;
+import org.apache.samples.common.SamplesCommon;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
-/**
- * Created by goshenoy on 3/23/17.
- */
+
public class UserProfileSample {
private static final Logger logger = LoggerFactory.getLogger(UserProfileSample.class);
private static UserProfileService.Client userProfileClient;
private static UserProfile testUser = null;
+ //before changing the test gateway and username, make sure realm and user exists in keycloak
private static String testGatewayId = "default";
private static String username = "default-admin";
+ private static String grant_type = "password";
+ private static String client_id = "admin-cli";
private static AuthzToken authzToken;
@@ -75,7 +63,7 @@ public class UserProfileSample {
try {
String profileServiceServerHost = ProfileServiceClientUtil.getProfileServiceServerHost();
int profileServiceServerPort = ProfileServiceClientUtil.getProfileServiceServerPort();
- authzToken = initializeAuthzToken();
+ initializeAuthzToken();
userProfileClient = CustosProfileServiceClientFactory.createCustosUserProfileServiceClient(profileServiceServerHost, profileServiceServerPort);
// test add-user-profile
@@ -124,7 +112,7 @@ public class UserProfileSample {
private static UserProfile getUserProfile(String userId) {
// get random value for userId
int userIdValue = ThreadLocalRandom.current().nextInt(1000);
-
+
// construct userProfile object
UserProfile userProfile = new UserProfile();
userProfile.setUserModelVersion("model-" + userIdValue);
@@ -154,58 +142,19 @@ public class UserProfileSample {
return nsfDemographics;
}
- private static AuthzToken initializeAuthzToken() throws Exception{
- authzToken = new AuthzToken();
- {
- HashMap<String, String> map_ = new HashMap<>();
- map_.put(Constants.GATEWAY_ID, testGatewayId);
- map_.put(Constants.USER_NAME, username);
- JSONObject json = getAccessToken();
- if(json.has("access_token")) {
- authzToken.setAccessToken(json.get("access_token").toString());
- }
- else{
- throw new Exception("Cannot find access token for the user. Check if the user exists in the IDP");
- }
- authzToken.setClaimsMap(map_);
- return authzToken;
+ private static void initializeAuthzToken() throws Exception{
+ authzToken = new AuthzToken();
+ HashMap<String, String> map_ = new HashMap<>();
+ map_.put(Constants.GATEWAY_ID, testGatewayId);
+ map_.put(Constants.USER_NAME, username);
+ authzToken.setClaimsMap(map_);
+ JSONObject json = SamplesCommon.getAccessToken(username,null,client_id, grant_type);
+ if(json.has("access_token")) {
+ authzToken.setAccessToken(json.get("access_token").toString());
}
- }
- private static JSONObject getAccessToken() throws CustosSecurityException {
- new KeyCloakSecurityManager().initializeSecurityInfra();
- String password = "123456";
- String tokenEndPoint = "https://airavata.host:8443/auth/realms/default/protocol/openid-connect/token";
- String grant_type = "password";
- String client_id = "admin-cli";
-
- CloseableHttpClient httpClient = HttpClients.createSystem();
- HttpPost httpPost = new HttpPost(tokenEndPoint);
- ;
- List<NameValuePair> formParams = new ArrayList<>();
- formParams.add(new BasicNameValuePair("grant_type", "password"));
- formParams.add(new BasicNameValuePair("client_id", client_id));
- formParams.add(new BasicNameValuePair("username", username));
- formParams.add(new BasicNameValuePair("password", password));
- UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, Consts.UTF_8);
- httpPost.setEntity(entity);
- try {
- CloseableHttpResponse response = httpClient.execute(httpPost);
- try {
- String responseBody = EntityUtils.toString(response.getEntity());
- JSONObject tokenInfo = new JSONObject(responseBody);
- return tokenInfo;
- } finally {
- response.close();
- }
-
- } catch (IOException e) {
- throw new RuntimeException(e);
- } finally {
- try {
- httpClient.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ else{
+ throw new Exception("Cannot find access token for the user. Check if the user exists in the IDP");
}
}
+
}
diff --git a/ide-integration/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/utils/ProfileServiceClientUtil.java b/ide-integration/samples/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/utils/ProfileServiceClientUtil.java
similarity index 100%
rename from ide-integration/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/utils/ProfileServiceClientUtil.java
rename to ide-integration/samples/custos-profile-service-samples/src/main/java/org/apache/custos/profile/service/samples/utils/ProfileServiceClientUtil.java
diff --git a/log4j.properties b/ide-integration/samples/custos-profile-service-samples/src/main/resources/log4j.properties
similarity index 80%
rename from log4j.properties
rename to ide-integration/samples/custos-profile-service-samples/src/main/resources/log4j.properties
index 2827ca2..31d6017 100644
--- a/log4j.properties
+++ b/ide-integration/samples/custos-profile-service-samples/src/main/resources/log4j.properties
@@ -17,18 +17,16 @@
# under the License.
#
-# Set root category priority to INFO and its only appender to CONSOLE.
-log4j.rootCategory=INFO, ERROR, CONSOLE,LOGFILE
-log4j.rootLogger=INFO, ERROR, CONSOLE, LOGFILE
-
+log4j.rootCategory=INFO, CONSOLE, LOGFILE
+log4j.rootLogger=INFO, CONSOLE, LOGFILE
+
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %m%n
-# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
-log4j.appender.LOGFILE.File=./target/custos.log
+log4j.appender.LOGFILE.File=./target/custos-server-test.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
diff --git a/ide-integration/custos-profile-service-samples/src/main/resources/profile-client-sample.properties b/ide-integration/samples/custos-profile-service-samples/src/main/resources/profile-client-sample.properties
similarity index 100%
rename from ide-integration/custos-profile-service-samples/src/main/resources/profile-client-sample.properties
rename to ide-integration/samples/custos-profile-service-samples/src/main/resources/profile-client-sample.properties
diff --git a/ide-integration/custos-authentication-service-samples/pom.xml b/ide-integration/samples/pom.xml
similarity index 64%
rename from ide-integration/custos-authentication-service-samples/pom.xml
rename to ide-integration/samples/pom.xml
index 5a035cd..a110489 100644
--- a/ide-integration/custos-authentication-service-samples/pom.xml
+++ b/ide-integration/samples/pom.xml
@@ -9,7 +9,12 @@
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>custos-authentication-service-samples</artifactId>
-
+ <artifactId>samples</artifactId>
+ <packaging>pom</packaging>
+ <modules>
+ <module>custos-authentication-service-samples</module>
+ <module>custos-profile-service-samples</module>
+ <module>commons</module>
+ </modules>
</project>
\ No newline at end of file