javaopenamopensso

OpenAm how to redirect to template in callback (proceess method)


I am writing application authentication logic. At some point in the process method, I need to ask the user to select the values ​​that were received.

How can I redirect it to the selection page I created in OpenAm? Also where should this page be located in openAM? How can I pass to this page the necessary values ​​for the user to select?

Ty

This is my module:

<ModuleProperties moduleName="MyAuth" version="1.0" >
    <Callbacks length="0" order="1" timeout="600" header="#NOT SHOWN#" template="readme.html"/>

    <Callbacks length="2" order="2" timeout="600" header="#TO BE SUBSTITUTED#" template="readme.html">
        <NameCallback isRequired="true" >
            <Prompt>Username</Prompt>
        </NameCallback>
        <PasswordCallback echoPassword="false" >
            <Prompt>Password</Prompt>
        </PasswordCallback>
    </Callbacks>

</ModuleProperties>

This my class MyAuth:

public class MyAuth extends AMLoginModule {
// same code here

     @Override
        public int process(Callback[] callbacks, int state) throws LoginException {

//same code logic here 
 switch (state) {
//...
case GET_TEMPLATE:
// in this place i try redirect to templete readme.html
 Callback[] callback = getCallback(1);
        try {
            getCallbackHandler().handle(callback);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (UnsupportedCallbackException e) {
            e.printStackTrace();
        }
}
}

} 

Solution

  • To retrieve additional input, add another state to the module.

    <ModuleProperties moduleName="MyAuth" version="1.0" >
        <Callbacks length="0" order="1" timeout="600" header="#NOT SHOWN#" template="readme.html"/>
    
        <Callbacks length="2" order="2" timeout="600" header="#TO BE SUBSTITUTED#">
            <NameCallback isRequired="true" >
                <Prompt>Username</Prompt>
            </NameCallback>
            <PasswordCallback echoPassword="false" >
                <Prompt>Password</Prompt>
            </PasswordCallback>
        </Callbacks>
    
        <Callbacks length="1 order="3" timeout="600" header="#TO BE SUBSTITUTED#">
            <NameCallback isRequired="true" >
                <Prompt>Additional Input</Prompt>
            </NameCallback>
        </Callbacks>    
    </ModuleProperties>
    

    Handle the state in the auth module code

    public class MyAuth extends AMLoginModule {
    // same code here
    
         @Override
            public int process(Callback[] callbacks, int state) throws LoginException {
    
    //same code logic here 
    
     switch (state) {
    case AUTHENTICATE:
    
    return GET_ADDITIONAL_DATA;
    //...
    case GET_ADDITIONAL_DATA:
      final String additionalData = ((NameCallback) callbacks[0]).getName();
      // handle additional data
    }
    }
    
    }