Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jans-config-api): agama configuration integration #1501

Merged
merged 1 commit into from
Jun 3, 2022
Merged
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
59 changes: 59 additions & 0 deletions jans-config-api/docs/jans-config-api-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4743,6 +4743,10 @@ components:
useHighestLevelScriptIfAcrScriptNotFound:
type: boolean
description: Enable/Disable usage of highest level script in case ACR script does not exist.
agamaConfiguration:
type: object
desciption: Engine Config which offers an alternative way to build authentication flows in Janssen server
$ref: '#/components/schemas/EngineConfig'

GluuAttribute:
title: GluuAttribute
Expand Down Expand Up @@ -6859,3 +6863,58 @@ components:
type: array
items:
$ref: '#/components/schemas/CustomAttribute'

EngineConfig:
title: Engine config object
description: Engine config object that offers an alternative way to build authentication flows in Janssen server.
type: object
properties:
enabled:
type: boolean
description: boolean value indicating if agama configuration enabled.
default: false
templatesPath:
type: string
description: path to the templates
default: '/ftl'
scriptsPath:
type: string
description: path to the scripts
default: '/scripts'
serializerType:
type: string
description: type of supported serializer
default: KRYO
enum:
- KRYO
- FST
maxItemsLoggedInCollections:
type: integer
description: maximum logged in collection item
default: 3
minimum: 1
pageMismatchErrorPage:
type: string
description: mismatch error page.
default: mismatch.ftl
interruptionErrorPage:
type: string
description: interruption error page.
default: timeout.ftl
crashErrorPage:
type: string
description: crash error page.
default: crash.ftl
finishedFlowPage:
type: string
description: finished flow page.
default: finished.ftl
bridgeScriptPage:
type: string
description: bridge script page.
default: agama.xhtml
defaultResponseHeaders:
type: object
additionalProperties:
type: string

4 changes: 2 additions & 2 deletions jans-config-api/profiles/local/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ test.scopes=https://jans.io/oauth/config/acrs.readonly https://jans.io/oauth/con
# jans.server
token.endpoint=https://jans.server2/jans-auth/restv1/token
token.grant.type=client_credentials
test.client.id=1800.d254faba-2788-4cfa-8ecb-f4f9b9d7b143
test.client.secret=mKYRKfZQHL6R
test.client.id=1800.1e34098b-b661-4aaf-8bc3-bfcb1880b90d
test.client.secret=8BBf3Zb5XR6Y
test.issuer=https://jans.server2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package io.jans.configapi.rest.resource.auth;

import io.jans.agama.model.EngineConfig;
import io.jans.as.model.config.Conf;
import io.jans.as.model.configuration.AppConfiguration;
import io.jans.configapi.core.rest.ProtectedApi;
Expand All @@ -27,6 +28,8 @@
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ConfigResource extends ConfigBaseResource {

private static final String AGAMACONFIGURATION = "agamaConfiguration";

@Inject
Logger log;
Expand All @@ -38,25 +41,30 @@ public class ConfigResource extends ConfigBaseResource {
@ProtectedApi(scopes = { ApiAccessConstants.JANS_AUTH_CONFIG_READ_ACCESS })
public Response getAppConfiguration() {
AppConfiguration appConfiguration = configurationService.find();
log.debug("ConfigResource::getAppConfiguration() appConfiguration - " + appConfiguration);
log.debug("ConfigResource::getAppConfiguration() appConfiguration:{}",appConfiguration);
return Response.ok(appConfiguration).build();
}

@PATCH
@Consumes(MediaType.APPLICATION_JSON_PATCH_JSON)
@ProtectedApi(scopes = { ApiAccessConstants.JANS_AUTH_CONFIG_WRITE_ACCESS })
public Response patchAppConfigurationProperty(@NotNull String requestString) throws Exception {
log.debug("AUTH CONF details to patch - requestString = " + requestString);
log.debug("AUTH CONF details to patch - requestString:{} ", requestString);
Conf conf = configurationService.findConf();
AppConfiguration appConfiguration = configurationService.find();
log.debug("AUTH CONF details BEFORE patch - appConfiguration = " + appConfiguration);
log.debug("AUTH CONF details BEFORE patch - appConfiguration :{}", appConfiguration);
appConfiguration = Jackson.applyPatch(requestString, conf.getDynamic());
log.debug("AUTH CONF details BEFORE patch merge - appConfiguration = " + appConfiguration);
log.debug("AUTH CONF details BEFORE patch merge - appConfiguration:{}", appConfiguration);
conf.setDynamic(appConfiguration);


//validate Agama Configuration
if(requestString.contains(AGAMACONFIGURATION)){
validateAgamaConfiguration(appConfiguration.getAgamaConfiguration());
}

configurationService.merge(conf);
appConfiguration = configurationService.find();
log.debug("AUTH CONF details AFTER patch merge - appConfiguration = " + appConfiguration);
log.debug("AUTH CONF details AFTER patch merge - appConfiguration:{}", appConfiguration);
return Response.ok(appConfiguration).build();
}

Expand All @@ -65,11 +73,23 @@ public Response patchAppConfigurationProperty(@NotNull String requestString) thr
@Path(ApiConstants.PERSISTENCE)
public Response getPersistenceDetails() {
String persistenceType = configurationService.getPersistenceType();
log.debug("ConfigResource::getPersistenceDetails() - persistenceType - " + persistenceType);
log.debug("ConfigResource::getPersistenceDetails() - persistenceType:{}", persistenceType);
JSONObject jsonObject = new JSONObject();
jsonObject.put("persistenceType", persistenceType);
log.debug("\n\n\n ConfigResource::getPersistenceDetails() - jsonObject = " + jsonObject + "\n\n");
log.debug("ConfigResource::getPersistenceDetails() - jsonObject:{}", jsonObject );
return Response.ok(jsonObject.toString()).build();
}


private void validateAgamaConfiguration(EngineConfig engineConfig) {
log.debug("engineConfig:{}", engineConfig);

if(engineConfig == null) {
return;
}

if(engineConfig.getMaxItemsLoggedInCollections()<1) {
thorwBadRequestException("maxItemsLoggedInCollections should be greater than zero -> " + engineConfig.getMaxItemsLoggedInCollections());
}
}
}