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

Offer Pure Java Interception Scripts #318

Closed
nynymike opened this issue Sep 17, 2021 · 1 comment
Closed

Offer Pure Java Interception Scripts #318

nynymike opened this issue Sep 17, 2021 · 1 comment
Assignees
Labels
comp-jans-core Component affected by issue or PR effort-13 Relative effort required for completion of issue or PR kind-feature Issue or PR is a new feature request priority-2 Issue or PR is important to majority of users, Currently workaround exists triaged Issue or PR is fully triaged

Comments

@nynymike
Copy link
Contributor

Instead of using a script, the end user should be able to specify a Java class and upload a third party jar file to the lib folder.

@ghost ghost assigned yuriyz and yurem Dec 27, 2021
@ghost ghost unassigned yuriyz and yurem Jan 10, 2022
@ossdhaval ossdhaval transferred this issue from another repository Jan 13, 2022
@ossdhaval ossdhaval added comp-jans-core Component affected by issue or PR effort-13 Relative effort required for completion of issue or PR kind-feature Issue or PR is a new feature request priority-2 Issue or PR is important to majority of users, Currently workaround exists triaged Issue or PR is fully triaged labels Jan 13, 2022
moabu pushed a commit that referenced this issue Jan 13, 2022
fix: if there no scripts return true
moabu pushed a commit that referenced this issue Jan 13, 2022
fix: if there no scripts return true
@yuriyz yuriyz self-assigned this Apr 25, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 18, 2022
yuriyz added a commit that referenced this issue May 19, 2022
@yuriyz
Copy link
Contributor

yuriyz commented May 30, 2022

Pure Java support is added.

During implementation I noticed that loading already compiled class produce few inconveniences to author of the script:

  • how do I compile it? (author have to switch to jans-auth-server classpath and manage class path on their own)
  • how do I pack it into jar? (e.g. do I need specific package to put it in?)
  • given these extra steps isn't it easier to use jython?

To make it easier for end-author of the script pure java support works in same as jython:

  • write java code (put it via UI or jans-config-api)
  • AS will compile it and run. No need to compile and pack it manually.
  • loading from file is supported in the same way as for Jython (simply put it in java source file and specify location, e.g. /opt/jans/jetty/jans-auth/custom/scripts/Discovery.java).

Docs:
https://github.com/JanssenProject/jans/wiki/Interception-scripts--(or--Custom-scripts)#using-pure-java-scripts

Sample script:

import io.jans.model.SimpleCustomProperty;
import io.jans.model.custom.script.model.CustomScript;
import io.jans.model.custom.script.type.discovery.DiscoveryType;
import io.jans.service.custom.script.CustomScriptManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.json.JSONObject;

import java.util.Map;

/**
 * @author Yuriy Zabrovarnyy
 */
public class Discovery implements DiscoveryType {

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

    @Override
    public boolean init(Map<String, SimpleCustomProperty> configurationAttributes) {
        log.info("Init of Discovery Java custom script");
        return true;
    }

    @Override
    public boolean init(CustomScript customScript, Map<String, SimpleCustomProperty> configurationAttributes) {
        log.info("Init of Discovery Java custom script");
        return true;
    }

    @Override
    public boolean destroy(Map<String, SimpleCustomProperty> configurationAttributes) {
        log.info("Destroy of Discovery Java custom script");
        return true;
    }

    @Override
    public int getApiVersion() {
        log.info("getApiVersion Discovery Java custom script: 11");
        return 11;
    }

    @Override
    public boolean modifyResponse(Object responseAsJsonObject, Object context) {
        scriptLogger.info("write to script logger");
        JSONObject response = (JSONObject) responseAsJsonObject;
        response.accumulate("key_from_java", "value_from_script_on_java");
        return true;
    }
}

@yuriyz yuriyz closed this as completed May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-jans-core Component affected by issue or PR effort-13 Relative effort required for completion of issue or PR kind-feature Issue or PR is a new feature request priority-2 Issue or PR is important to majority of users, Currently workaround exists triaged Issue or PR is fully triaged
Projects
None yet
Development

No branches or pull requests

4 participants