Custom functions that expose any useful WSO2 Identity Server core functions and any utility functions can be added as OSGi services. A core set of functions are available at the following GitHub location: https://github.com/wso2-extensions/identity-conditional-auth-functions
The following steps provide some guidelines on how you can write custom functions for adaptive authentication.
- Create an Apache Maven module that has packaging type as ‘bundle’ and add the maven-bundle-plugin configuration. You may skip this step if you are adding a function to an existing component providing a related functionality.
Create a functional interface (i.e., Interface with a single public method). The method name and parameters should be the same as you would be providing from js. And you may need to use wrapper classes for any object classes (except number, string and boolean). You may skip this if you can use an existing object. For more information on objects, see object reference documentation.
The functional interface is as follows.
Create a class that implements the functional interface in the above step and implement your logic.
Note: It is recommended to throw errors from the Java methods to the authentication script. All the errors have to be handled by the method itself.
JsFunctionRegistryservice in the service component class.
In the bundle activator of the module, register the class created in step 3 in the
If you have one class that implements many functional interface, you need to cast to that particular functional interface when registering.