The Config Api Interception script implements the ConfigApiType interface. This extends methods from the base script type in addition to adding new methods:
The getApiVersion method allows API changes in order to do transparent migration from an old script to a new API. Only include the customScript variable if the value for getApiVersion is greater than 10
responseAsJsonObject - is org.codehaus.jettison.json.JSONObject, you can use any method to manipulate json. context is reference of io.jans.as.service.external.context.ExternalIntrospectionContext (in https://github.com/JanssenFederation/oxauth project,)
Sample script which demonstrates basic client authentication#
fromio.jans.as.model.jwtimportJwtfromio.jans.as.model.cryptoimportAuthCryptoProviderfromio.jans.model.custom.script.confimportCustomScriptConfigurationfromio.jans.model.custom.script.type.configapiimportConfigApiTypefromio.jans.ormimportPersistenceEntryManagerfromio.jans.service.cdi.utilimportCdiUtilfromio.jans.utilimportStringHelper,ArrayHelperfromio.jans.configapi.model.configurationimportApiAppConfigurationfromorg.jsonimportJSONObjectfromjava.langimportStringfromjakarta.servlet.httpimportHttpServletRequestfromjakarta.servlet.httpimportHttpServletResponseclassConfigApiAuthorization(ConfigApiType):def__init__(self,currentTimeMillis):self.currentTimeMillis=currentTimeMillisdefinit(self,configurationAttributes):print"ConfigApiType script. Initializing ..."print"ConfigApiType script. Initialized successfully"returnTruedefdestroy(self,configurationAttributes):print"ConfigApiType script. Destroying ..."print"ConfigApiType script. Destroyed successfully"returnTruedefgetApiVersion(self):return1# Returns boolean true or false depending on the process, if the client is authorized# or not.# This method is called after introspection response is ready. This method can modify introspection response.# Note :# responseAsJsonObject - is org.codehaus.jettison.json.JSONObject, you can use any method to manipulate json# context is reference of io.jans.as.service.external.context.ExternalIntrospectionContext (in https://github.com/JanssenFederation/oxauth project, )defauthorize(self,responseAsJsonObject,context):print" responseAsJsonObject: %s"%responseAsJsonObjectprint" context: %s"%contextprint"Config Authentication process"request=context.httpRequestresponse=context.httpResponseprint" request = : %s"%requestprint" response = : %s"%responseappConfiguration=context.getApiAppConfiguration()customScriptConfiguration=context.getScript()issuer=context.getRequestParameters().get("ISSUER")token=context.getRequestParameters().get("TOKEN")method=context.getRequestParameters().get("METHOD")path=context.getRequestParameters().get("PATH")print" requese2: %s"%requestprint" response2 new: %s"%responseprint"ConfigApiType.appConfiguration: %s"%appConfigurationprint"ConfigApiType.customScriptConfiguration: %s"%customScriptConfigurationprint"ConfigApiType.issuer: %s"%issuerprint"ConfigApiType.token: %s"%tokenprint"ConfigApiType.method: %s"%methodprint"ConfigApiType.path: %s"%path#Example to validate methodif("GET"==StringHelper.toUpperCase(method)):print"Validate method: %s"%methodif("attributes"==StringHelper.toLowerCase(path)):print"ConfigApiType.path: %s"%pathresponseAsJsonObject.accumulate("key_from_script","value_from_script")print" final responseAsJsonObject: %s"%responseAsJsonObjectreturnTrue