Skip to content

Commit

Permalink
Merge pull request #230 from Sunbird-RC/generic-auth
Browse files Browse the repository at this point in the history
Generic auth(IAM)
  • Loading branch information
srprasanna authored Jul 4, 2023
2 parents 9093f66 + f033fda commit 095c09d
Show file tree
Hide file tree
Showing 80 changed files with 4,699 additions and 477 deletions.
2 changes: 0 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
RELEASE_VERSION=v0.0.14
VIEW_DIR=java/apitest/src/test/resources/views
SCHEMA_DIR=java/apitest/src/test/resources/schemas
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ test: build
@cd java/apitest && MODE=async ../mvnw -Pe2e test || echo 'Tests failed'
@docker-compose down
@rm -rf db-data-2 || echo "no permission to delete"
# test with fusionauth
@RELEASE_VERSION=latest DB_DIR=db-data-7 SEARCH_PROVIDER_NAME=dev.sunbirdrc.registry.service.NativeSearchService FUSION_WRAPPER_BUILD=services/sample-fusionauth-service/ FUSIONAUTH_ISSUER_URL=http://fusionauth:9011/ oauth2_resource_uri=http://fusionauth:9011/ oauth2_resource_roles_path=roles identity_provider=dev.sunbirdrc.auth.genericiam.AuthProviderImpl sunbird_sso_url=http://fusionauthwrapper:3990/fusionauth/api/v1/user IMPORTS_DIR=services/sample-fusionauth-service/imports docker-compose -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml up -d db es fusionauth fusionauthwrapper
sleep 20
@echo "Starting the test" && sh build/wait_for_port.sh 9011
@echo "Starting the test" && sh build/wait_for_port.sh 3990
sleep 20
@RELEASE_VERSION=latest DB_DIR=db-data-7 SEARCH_PROVIDER_NAME=dev.sunbirdrc.registry.service.NativeSearchService FUSION_WRAPPER_BUILD=services/sample-fusionauth-service/ FUSIONAUTH_ISSUER_URL=http://fusionauth:9011/ oauth2_resource_uri=http://fusionauth:9011/ oauth2_resource_roles_path=roles identity_provider=dev.sunbirdrc.auth.genericiam.AuthProviderImpl sunbird_sso_url=http://fusionauthwrapper:3990/fusionauth/api/v1/user IMPORTS_DIR=services/sample-fusionauth-service/imports docker-compose -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml up -d --no-deps registry
@echo "Starting the test" && sh build/wait_for_port.sh 8081
@docker-compose -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml ps
@curl -v http://localhost:8081/health
@cd java/apitest && MODE=fusionauth ../mvnw -Pe2e test || echo 'Tests failed'
@docker-compose -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml down
@rm -rf db-data-7 || echo "no permission to delete"
make -C services/certificate-signer test
make -C services/public-key-service test
make -C services/context-proxy-service test
Expand Down
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ services:
- elastic_search_password=${ELASTIC_SEARCH_PASSWORD}
- search_providerName=${SEARCH_PROVIDER_NAME-dev.sunbirdrc.registry.service.ElasticSearchService}
- sunbird_sso_realm=${KEYCLOAK_REALM-sunbird-rc}
- sunbird_sso_url=http://keycloak:8080/auth
- sunbird_sso_url=${sunbird_sso_url-http://keycloak:8080/auth}
- oauth2_resource_uri=${oauth2_resource_uri-http://keycloak:8080/auth/realms/sunbird-rc}
- oauth2_resource_roles_path=${oauth2_resource_roles_path-realm_access.roles}
- identity_provider=${identity_provider-dev.sunbirdrc.auth.keycloak.KeycloakProviderImpl}
- sunbird_sso_admin_client_id=${KEYCLOAK_ADMIN_CLIENT_ID-admin-api}
- sunbird_sso_client_id=${KEYCLOAK_CLIENT_ID-registry-frontend}
- sunbird_sso_admin_client_secret=${KEYCLOAK_SECRET}
Expand Down Expand Up @@ -89,6 +92,8 @@ services:
condition: service_healthy
db:
condition: service_healthy
keycloak:
condition: service_healthy
healthcheck:
test: [ "CMD-SHELL", "wget -nv -t1 --spider http://localhost:8081/health || exit 1" ]
interval: 30s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"userDetails": {
"passkey": "abcd"
"passkey": "abcd@12345"
},
"contactDetails": {
"mobile": "9876543210",
"email": "[email protected]"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Feature: Registry api tests
Background:
* string registryUrl = "http://localhost:8081"
* string authUrl = "http://localhost:9011"
* url registryUrl
* def admin_token = ""
* def client_secret = 'a52c5f4a-89fd-40b9-aea2-3f711f14c889'
* def sleep = function(millis){ java.lang.Thread.sleep(millis) }
@env=fusionauth
Scenario: Create student with password schema and verify if password is set
# get admin token
* url authUrl
* path '/oauth2/token'
* header Content-Type = 'application/x-www-form-urlencoded; charset=utf-8'
* header Host = 'fusionauth:9011'
* form field grant_type = 'password'
* form field client_id = '85a03867-dccf-4882-adde-1a79aeec50df'
* form field username = '[email protected]'
* form field password = 'admin@12345'
* method post
Then status 200
And print response.access_token
* def admin_token = 'Bearer ' + response.access_token
# create student schema
Given url registryUrl
And path 'api/v1/Schema'
And header Authorization = admin_token
And request read('StudentWithPasswordSchemaRequest.json')
When method post
Then status 200
And response.params.status == "SUCCESSFUL"
# invite entity for student
Given url registryUrl
And path 'api/v1/StudentWithPassword/invite'
* def studentRequest = read('StudentWithPasswordRequest.json')
And request studentRequest
When method post
Then status 200
* def studentOsid = response.result.StudentWithPassword.osid
# get student token
* url authUrl
* path '/oauth2/token'
* header Content-Type = 'application/x-www-form-urlencoded; charset=utf-8'
* header Host = 'fusionauth:9011'
* form field grant_type = 'password'
* form field client_id = '85a03867-dccf-4882-adde-1a79aeec50df'
* form field username = studentRequest.contactDetails.mobile
* form field password = studentRequest.userDetails.passkey
* method post
Then status 200
And print response.access_token
* def student_token = 'Bearer ' + response.access_token
* sleep(3000)
# get student info
Given url registryUrl
And path 'api/v1/StudentWithPassword/'
And header Authorization = student_token
When method get
Then status 200
And response[0].osid.length > 0
4 changes: 3 additions & 1 deletion java/middleware/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
<?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>

Expand Down
76 changes: 76 additions & 0 deletions java/middleware/registry-middleware/auth0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?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">
<parent>
<artifactId>registry-middleware</artifactId>
<groupId>dev.sunbirdrc</groupId>
<version>2.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>auth0</artifactId>

<dependencyManagement>
<dependencies>

</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.sunbirdrc</groupId>
<artifactId>pojos</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>dev.sunbirdrc</groupId>
<artifactId>middleware-commons</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>dev.sunbirdrc</groupId>
<artifactId>identity-provider</artifactId>
<version>2.0.3</version>
</dependency>

</dependencies>
</project>
Loading

0 comments on commit 095c09d

Please sign in to comment.