Skip to content

fix (jans-auth): Unexpected compilation failures during interception script deployment #10325

@tawaren

Description

@tawaren

Describe the bug
When deploying a java interception script, I get a compilation error in the jans-auth_script.log
However, the code that fails to compile is not the code I deploy, but some python code like SampleScript.
I use many different java interception scripts and all produce a compilation error for a python class.

To Reproduce

  1. Set JANSSEN_IMAGE envoironment variable to ghcr.io/janssenproject/jans/monolith:1.1.6-1
  2. Setup janssen according to: https://docs.jans.io/v1.1.6/janssen-server/install/docker-install/compose/#how-to-run
  3. Deploy a interception script as described in https://docs.jans.io/v1.1.6/janssen-server/developer/scripts/#add-modify-and-delete-a-script.
    For example a update token script.
  4. Inspect the jans-auth-log/jans-auth_script.log file to see the error.

Expected behavior
The java file should be deployed, as long as it can be compiled.
And the jans-auth_script.log should show the logs produced by the init method.

Screenshots
Excerpt jans-auth_script.log

2024-12-03 13:33:25,271 ERROR [Jans AuthScheduler_Worker-4]  [io.jans.service.custom.script.ExternalTypeCreator] (ExternalTypeCreator.java:58) - Failed to prepare external type 'f5c8a03a-42a0-410d-809d-d92386b7c341', exception: 'java.lang.IllegalArgumentException: Compilation failed:
Generated:1: error: 'module' or 'open' expected
from io.jans.service.cdi.util import CdiUtil
^
Generated:1: error: '.' expected
from io.jans.service.cdi.util import CdiUtil
                                            ^
Generated:2: error: ';' expected
from io.jans.oxauth.security import Identity
    ^
Generated:2: error: '.' expected
from io.jans.oxauth.security import Identity
                                            ^
Generated:3: error: ';' expected
from io.jans.model.custom.script.type.authz import ConsentGatheringType
    ^
Generated:3: error: '.' expected
from io.jans.model.custom.script.type.authz import ConsentGatheringType
                                                                       ^
Generated:4: error: ';' expected
from io.jans.util import StringHelper
    ^
Generated:4: error: '.' expected
from io.jans.util import StringHelper
                                     ^
Generated:6: error: '.' expected
import java
           ^
Generated:7: error: '.' expected
import random
             ^
Generated:9: error: '{' expected
class SampleScript(ConsentGatheringType):
                  ^
11 errors

 Source code: 
from io.jans.service.cdi.util import CdiUtil
from io.jans.oxauth.security import Identity
from io.jans.model.custom.script.type.authz import ConsentGatheringType
from io.jans.util import StringHelper

import java
import random

class SampleScript(ConsentGatheringType):

    def __init__(self, currentTimeMillis):

    def init(self, configurationAttributes):
        return True

    def destroy(self, configurationAttributes):
        return True

    def getApiVersion(self):
        return 1

    
    def authorize(self, step, context): 
        return True

    def getNextStep(self, step, context):
        return -1

    def prepareForStep(self, step, context):
        return True

    def getStepsCount(self, context):
        return 2

    def getPageForStep(self, step, context):
        return ""

	at io.jans.service.custom.script.jit.SimpleJavaCompiler.compile0(SimpleJavaCompiler.java:136)
	at io.jans.service.custom.script.jit.SimpleJavaCompiler.compile(SimpleJavaCompiler.java:62)
	at io.jans.service.custom.script.ExternalTypeCreator.createExternalTypeWithJava(ExternalTypeCreator.java:113)
	at io.jans.service.custom.script.ExternalTypeCreator.createExternalType(ExternalTypeCreator.java:52)
	at io.jans.service.custom.script.ExternalTypeCreator$Proxy$_$$_WeldClientProxy.createExternalType(Unknown Source)
	at io.jans.service.custom.script.CustomScriptManager.reloadCustomScriptConfigurations(CustomScriptManager.java:280)
	at io.jans.service.custom.script.CustomScriptManager.reloadImpl(CustomScriptManager.java:177)
	at io.jans.service.custom.script.CustomScriptManager.reload(CustomScriptManager.java:147)
	at io.jans.service.custom.script.CustomScriptManager.reloadTimerEvent(CustomScriptManager.java:122)
	at io.jans.service.custom.script.CustomScriptManager$Proxy$_$$_WeldSubclass.reloadTimerEvent(Unknown Source)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
	at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85)
	at org.jboss.weld.injection.MethodInvocationStrategy$SimpleMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:168)
	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330)
	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308)
	at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286)
	at jakarta.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:125)
	at org.jboss.weld.util.Observers.notify(Observers.java:166)
	at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285)
	at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273)
	at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:177)
	at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:159)
	at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:632)
	at org.jboss.weld.util.ForwardingBeanManager.fireEvent(ForwardingBeanManager.java:104)
	at io.jans.service.timer.TimerJob.execute(TimerJob.java:45)
	at io.jans.service.timer.JobExecutionDelegate.execute(JobExecutionDelegate.java:37)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
'

Excerpt update_token.json (used to deploy the UpdateToken.java)
[requires mapping /extension in the docker compose to the folder containing UpdateToken.java]

{
  "name": "add_scopes",
  "aliases": null,
  "description": "Token and Scope Lifetime Management",
  "script": "_file /extension/UpdateToken.java",
  "scriptType": "UPDATE_TOKEN",
  "programmingLanguage": "JAVA",
  "moduleProperties": [{
    "value1": "location_type",
    "value2": "file",
    "description": "How is the script stored"
  },{
    "value1": "location_path",
    "value2": "/extension/installed",
    "description": "Where is the script stored"
  }],
  "configurationProperties":  [],
  "level": 1,
  "revision": 0,
  "enabled": true,
  "scriptError": null,
  "modified": true,
  "internal": false
}

UpdateToken.java (a trivial one)

import java.util.*;

import io.jans.model.SimpleCustomProperty;
import io.jans.model.custom.script.model.CustomScript;
import io.jans.model.custom.script.type.token.UpdateTokenType;
import io.jans.service.custom.script.CustomScriptManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UpdateToken implements UpdateTokenType {

    private static final Logger log = LoggerFactory.getLogger(CustomScriptManager.class);

    @Override
    public boolean init(Map<String, SimpleCustomProperty> configurationAttributes) {
        log.info("UpdateToken. Initializing ...");
        log.info("Update Token. Initialized.");
        return true;
    }

    @Override
    public boolean init(CustomScript customScript, Map<String, SimpleCustomProperty> configurationAttributes) {
        return init(configurationAttributes);
    }

    @Override
    public boolean destroy(Map<String, SimpleCustomProperty> configurationAttributes) {
        log.info("Update Token. Destroyed Java Custom Script");
        return true;
    }

    @Override
    public int getApiVersion() {
        return 11;
    }

	@Override
    public boolean modifyIdToken(Object jsonWebResponse, Object tokenContext){
        return true;
    }

    @Override
    public boolean modifyAccessToken(Object accessToken, Object tokenContext){
        return true;
    }

    @Override
    public boolean modifyRefreshToken(Object refreshToken, Object tokenContext){
        return true;
    }

    @Override
    public int getRefreshTokenLifetimeInSeconds(Object tokenContext){
        log.info("Computing Refresh Token Lifetime");
        return 600;
    }

    @Override
    public int getIdTokenLifetimeInSeconds(Object tokenContext){
        log.info("Computing Id Token Lifetime");
        return 600;
    }
	
    @Override
    public int getAccessTokenLifetimeInSeconds(Object tokenContext){
        log.info("Computing Access Token Lifetime");
        return 600;
    }
}

Desktop:
OS: Windows 10 Pro 22HS2
Docker Version: Docker version 4.36.0
Janssen Version: 1.1.6-1

Metadata

Metadata

Assignees

Labels

kind-bugIssue or PR is a bug in existing functionality

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions