Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 9 additions & 38 deletions config/7.3.0/securebanking/ig/config/dev/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,43 +141,6 @@
"format": "PLAIN"
}
},
{
"name": "IDMClientHandler",
"type": "Chain",
"config": {
"filters": [
{
"type": "ResourceOwnerOAuth2ClientFilter",
"config": {
"tokenEndpoint": "https://&{identity.platform.fqdn}/am/oauth2/realms/root/realms/&{am.realm}/access_token",
"username": "&{ig.idm.user}",
"passwordSecretId": "ig.idm.password",
"secretsProvider": "SystemAndEnvSecretStore-IAM",
"scopes": [
"fr:idm:*"
],
"endpointHandler": {
"type": "Chain",
"config": {
"handler": "ForgeRockClientHandler",
"filters": [
{
"type": "ClientSecretBasicAuthenticationFilter",
"config": {
"clientId": "&{ig.client.id}",
"clientSecretId": "ig.client.secret",
"secretsProvider": "SystemAndEnvSecretStore-IAM"
}
}
]
}
}
}
}
],
"handler": "ForgeRockClientHandler"
}
},
{
"name": "TrustManager-OB",
"type": "TrustManager",
Expand Down Expand Up @@ -234,7 +197,15 @@
"type": "IdmService",
"config": {
"baseEndpoint": "&{urls.idmBaseUri}",
"endpointHandler": "IDMClientHandler"
"tokenEndpoint": "https://&{identity.platform.fqdn}/am/oauth2/realms/root/realms/&{am.realm}/access_token",
"username": "&{ig.idm.user}",
"passwordSecretId": "ig.idm.password",
"secretsProvider": "SystemAndEnvSecretStore-IAM",
"authMethod": "CLIENT_SECRET_BASIC",
"authConfig": {
"clientId": "&{ig.client.id}",
"clientSecretId": "ig.client.secret"
}
}
},
{
Expand Down
47 changes: 9 additions & 38 deletions config/7.3.0/securebanking/ig/config/prod/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,43 +129,6 @@
"format": "PLAIN"
}
},
{
"name": "IDMClientHandler",
"type": "Chain",
"config": {
"filters": [
{
"type": "ResourceOwnerOAuth2ClientFilter",
"config": {
"tokenEndpoint": "https://&{identity.platform.fqdn}/am/oauth2/realms/root/realms/&{am.realm}/access_token",
"username": "&{ig.idm.user}",
"passwordSecretId": "ig.idm.password",
"secretsProvider": "SystemAndEnvSecretStore-IAM",
"scopes": [
"fr:idm:*"
],
"endpointHandler": {
"type": "Chain",
"config": {
"handler": "ForgeRockClientHandler",
"filters": [
{
"type": "ClientSecretBasicAuthenticationFilter",
"config": {
"clientId": "&{ig.client.id}",
"clientSecretId": "ig.client.secret",
"secretsProvider": "SystemAndEnvSecretStore-IAM"
}
}
]
}
}
}
}
],
"handler": "ForgeRockClientHandler"
}
},
{
"name": "TrustManager-OB",
"type": "TrustManager",
Expand Down Expand Up @@ -222,7 +185,15 @@
"type": "IdmService",
"config": {
"baseEndpoint": "&{urls.idmBaseUri}",
"endpointHandler": "IDMClientHandler"
"tokenEndpoint": "https://&{identity.platform.fqdn}/am/oauth2/realms/root/realms/&{am.realm}/access_token",
"username": "&{ig.idm.user}",
"passwordSecretId": "ig.idm.password",
"secretsProvider": "SystemAndEnvSecretStore-IAM",
"authMethod": "CLIENT_SECRET_BASIC",
"authConfig": {
"clientId": "&{ig.client.id}",
"clientSecretId": "ig.client.secret"
}
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
"type": "ScriptableHandler",
"config": {
"type": "application/x-groovy",
"clientHandler": "IDMClientHandler",
"file": "RepoApiClient.groovy",
"args": {
"routeArgObjApiClient": "apiClient",
"routeArgIdmBaseUri": "https://&{identity.platform.fqdn}"
"routeArgIdmService": "${heap[IdmService]}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script seems to use idmService arg name?

That would be better, don't see why we need the routeArg... prefixes really.

"routeArgObjApiClient": "apiClient"
}
}
}
Expand All @@ -47,7 +46,7 @@
"clientHandler": "IDMClientHandler",
"file": "RepoUser.groovy",
"args": {
"routeArgIdmBaseUri": "https://&{identity.platform.fqdn}",
"routeArgIdmService": "${heap[IdmService]}",
"routeArgObjUser": "&{user.object}"
}
}
Expand Down
65 changes: 32 additions & 33 deletions config/7.3.0/securebanking/ig/scripts/groovy/RepoApiClient.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import groovy.json.JsonOutput
import static org.forgerock.util.CloseSilentlyAsyncFunction.closeSilently;
import static org.forgerock.util.promise.NeverThrowsException.neverThrownAsync;

def fapiInteractionId = request.getHeaders().getFirst("x-fapi-interaction-id");
if(fapiInteractionId == null) fapiInteractionId = "No x-fapi-interaction-id";
Expand Down Expand Up @@ -28,36 +30,33 @@ def apiClientId = splitUri[splitUri.length - 1];
logger.debug(SCRIPT_NAME + "Looking up API Client {}",apiClientId)

apiClientRequest.setUri(routeArgIdmBaseUri + "/openidm/managed/" + routeArgObjApiClient + "/" + apiClientId)

http.send(apiClientRequest).then(apiClientResponse -> {
apiClientRequest.close()
logger.debug(SCRIPT_NAME + "Back from IDM")

def apiClientResponseStatus = apiClientResponse.getStatus();

if (apiClientResponseStatus != Status.OK) {
message = "Failed to get API Client details"
logger.error(message)
response.status = apiClientResponseStatus
response.entity = "{ \"error\":\"" + message + "\"}"
return response
}

def apiClientResponseContent = apiClientResponse.getEntity();
def apiClientResponseObject = apiClientResponseContent.getJson();

def responseObj = [
"id": apiClientResponseObject.id,
"name": apiClientResponseObject.name,
"officialName": apiClientResponseObject.name,
"oauth2ClientId": apiClientResponseObject.oauth2ClientId,
"logoUri": apiClientResponseObject.logoUri
]

def responseJson = JsonOutput.toJson(responseObj);
logger.debug(SCRIPT_NAME + "Final JSON " + responseJson)

response.entity = responseJson;
return response

}).then(response -> { return response })
idmService.send(context, apiClientRequest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems a better fit (the intention) to use idmService here (not http), isn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And in RepoUser.

.thenAsync(closeSilently(response -> {
logger.debug(SCRIPT_NAME + "Back from IDM")
def apiClientResponseStatus = apiClientResponse.getStatus();

if (apiClientResponseStatus != Status.OK) {
message = "Failed to get API Client details"
logger.error(message)
response.status = apiClientResponseStatus
response.entity = "{ \"error\":\"" + message + "\"}"
return response
}
return response.getEntity()
.getJsonAsync()
.then(json -> {
def responseObj = [
"id" : json.id,
"name" : json.name,
"officialName" : json.name,
"oauth2ClientId": json.oauth2ClientId,
"logoUri" : json.logoUri
]

def responseJson = JsonOutput.toJson(responseObj);
logger.debug(SCRIPT_NAME + "Final JSON " + responseJson)

response.entity = responseJson;
return response
});
}), neverThrownAsync())
74 changes: 33 additions & 41 deletions config/7.3.0/securebanking/ig/scripts/groovy/RepoUser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,39 @@ if(Objects.nonNull(uriQuery)){
- curl -i -v http://ig:80/repo/users?_queryFilter=userName+eq+%22<Cloud platform user name>%22
- curl -i -v http://ig:80/repo/users/<Cloud platform user ID>
*/

http.send(userRequest).then(userResponse -> {
userRequest.close()
logger.debug(SCRIPT_NAME + "Back from IDM")

def userResponseStatus = userResponse.getStatus();
logger.debug(SCRIPT_NAME + " status {}", userResponseStatus)

if (userResponseStatus != Status.OK) {
return errorResponse("User details not found", userResponseStatus)
}

def userResponseContent = userResponse.getEntity()

logger.debug(SCRIPT_NAME + "response JSON {}", userResponseContent.getJson().result)

// build response Object
def userResponseObject = userResponseContent.getJson()
if(queryFilter){
if(userResponseContent.getJson().result.isEmpty()){
return errorResponse("User details not found", Status.NOT_FOUND)
}
userResponseObject = userResponseContent.getJson().result[0]
}

def responseObj = [
"id": userResponseObject._id,
"userName": userResponseObject.userName,
"givenName": userResponseObject.givenName,
"surname": userResponseObject.sn,
"mail": userResponseObject.mail,
"accountStatus": userResponseObject.accountStatus
]

def responseJson = JsonOutput.toJson(responseObj)
logger.debug(SCRIPT_NAME + "Final JSON " + responseJson)

response.entity = responseJson;
return response

}).then(response -> { return response })
idmService.send(context, userRequest)
.thenAsync(closeSilently(response -> {
logger.debug(SCRIPT_NAME + "Back from IDM")
def userResponseStatus = userResponse.getStatus();
logger.debug(SCRIPT_NAME + " status {}", userResponseStatus)
if (userResponseStatus != Status.OK) {
return errorResponse("User details not found", userResponseStatus)
}
return response.getEntity()
.getJsonAsync()
.then(json -> {
if(queryFilter){
if(json.isEmpty()){
return errorResponse("User details not found", Status.NOT_FOUND)
}
userResponseObject = userResponseContent.getJson().result[0]
}
def responseObj = [
"id": json._id,
"userName": json.userName,
"givenName": json.givenName,
"surname": json.sn,
"mail": json.mail,
"accountStatus": json.accountStatus
]

def responseJson = JsonOutput.toJson(responseObj)
logger.debug(SCRIPT_NAME + "Final JSON " + responseJson)

response.entity = responseJson;
return response
});
}), neverThrownAsync())

def errorResponse(String message, userResponseStatus) {
logger.error(SCRIPT_NAME + message)
Expand Down