-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jans-core): added Discovery.java script and sample external service
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...st/java/io/jans/service/custom/script/test/java/SampleDiscoveryExternalScriptService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.jans.service.custom.script.test.java; | ||
|
||
import io.jans.model.custom.script.CustomScriptType; | ||
import io.jans.model.custom.script.conf.CustomScriptConfiguration; | ||
import io.jans.model.custom.script.type.discovery.DiscoveryType; | ||
import io.jans.service.custom.script.ExternalScriptService; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* @author Yuriy Zabrovarnyy | ||
*/ | ||
public class SampleDiscoveryExternalScriptService extends ExternalScriptService { | ||
|
||
public SampleDiscoveryExternalScriptService() { | ||
super(CustomScriptType.DISCOVERY); | ||
} | ||
|
||
public boolean modifyDiscovery(JSONObject jsonObject, Object context) { | ||
final CustomScriptConfiguration script = getDefaultExternalCustomScript(); | ||
if (script == null) { | ||
log.trace("No discovery java script set."); | ||
return false; | ||
} | ||
|
||
try { | ||
log.trace("Executing java 'modifyDiscovery' method, script name: {}, jsonWebResponse: {}, context: {}", script.getName(), jsonObject, context); | ||
|
||
DiscoveryType discoveryType = (DiscoveryType) script.getExternalType(); | ||
final boolean result = discoveryType.modifyResponse(jsonObject, context); | ||
log.trace("Finished 'modifyDiscovery' method, script name: {}, jsonWebResponse: {}, context: {}, result: {}", script.getName(), jsonObject, context, result); | ||
|
||
return result; | ||
} catch (Exception e) { | ||
log.error(e.getMessage(), e); | ||
saveScriptError(script.getCustomScript(), e); | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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; | ||
} | ||
} |