Search in sources :

Example 1 with SSOTokenListener

use of com.iplanet.sso.SSOTokenListener in project OpenAM by OpenRock.

the class SSOTokenSampleServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) {
    ServletOutputStream out = null;
    try {
        try {
            response.setContentType("text/html");
            out = response.getOutputStream();
            // create the sso token from http request 
            SSOTokenManager manager = SSOTokenManager.getInstance();
            SSOToken token = manager.createSSOToken(request);
            if (manager.isValidToken(token)) {
                //print some of the values from the token.
                String host = token.getHostName();
                java.security.Principal principal = token.getPrincipal();
                String authType = token.getAuthType();
                int level = token.getAuthLevel();
                InetAddress ipAddress = token.getIPAddress();
                out.println("SSOToken host name: " + host);
                out.println("<br />");
                out.println("SSOToken Principal name: " + principal.getName());
                out.println("<br />");
                out.println("Authentication type used: " + authType);
                out.println("<br />");
                out.println("IPAddress of the host: " + ipAddress.getHostAddress());
                out.println("<br />");
            }
            /* Validate the token again, with another method.
                 * if token is invalid, this method throws exception
                 */
            manager.validateToken(token);
            out.println("SSO Token validation test succeeded");
            out.println("<br />");
            // Get the SSOTokenID associated with the token and print it.
            SSOTokenID tokenId = token.getTokenID();
            out.println("The token id is " + tokenId.toString());
            out.println("<br />");
            // Set and get some properties in the token.
            token.setProperty("Company", "Sun Microsystems");
            token.setProperty("Country", "USA");
            String name = token.getProperty("Company");
            String country = token.getProperty("Country");
            out.println("Property: Company: " + name);
            out.println("<br />");
            out.println("Property: Country: " + country);
            out.println("<br />");
            // Retrieve user profile and print them
            AMIdentity userIdentity = IdUtils.getIdentity(token);
            Map attrs = userIdentity.getAttributes();
            out.println("User Attributes: " + attrs);
            /* let us add a listener to the SSOToken. Whenever a token
                 * event arrives, ssoTokenChanged method of the listener will
                 * get called.
                 */
            SSOTokenListener myListener = new SampleTokenListener();
            token.addSSOTokenListener(myListener);
        } catch (SSOException e) {
            out.println("SSO Exception: " + e);
            out.println("<p>Authenticate to OpenAM server before visiting this page.</p>");
            e.printStackTrace();
        } catch (IdRepoException e) {
            out.println("IdRepo Exception: " + e);
            e.printStackTrace();
        } catch (IOException e) {
            out.println("IO Exception: " + e);
            e.printStackTrace();
        } finally {
            out.flush();
        }
    } catch (IOException e) {
    // ignored
    }
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOTokenID(com.iplanet.sso.SSOTokenID) SSOToken(com.iplanet.sso.SSOToken) ServletOutputStream(javax.servlet.ServletOutputStream) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) SSOTokenListener(com.iplanet.sso.SSOTokenListener) AMIdentity(com.sun.identity.idm.AMIdentity) InetAddress(java.net.InetAddress) Map(java.util.Map)

Example 2 with SSOTokenListener

use of com.iplanet.sso.SSOTokenListener in project OpenAM by OpenRock.

the class StatelessSSOTokenTest method shouldAddListenersToSession.

@Test
public void shouldAddListenersToSession() throws Exception {
    // Given
    SSOTokenListener listener = mock(SSOTokenListener.class);
    // When
    statelessSSOToken.addSSOTokenListener(listener);
    // Then
    verify(mockSession).addSessionListener(any(SSOSessionListener.class));
}
Also used : SSOTokenListener(com.iplanet.sso.SSOTokenListener) SSOSessionListener(com.iplanet.sso.providers.dpro.SSOSessionListener) Test(org.testng.annotations.Test)

Aggregations

SSOTokenListener (com.iplanet.sso.SSOTokenListener)2 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 SSOTokenID (com.iplanet.sso.SSOTokenID)1 SSOTokenManager (com.iplanet.sso.SSOTokenManager)1 SSOSessionListener (com.iplanet.sso.providers.dpro.SSOSessionListener)1 AMIdentity (com.sun.identity.idm.AMIdentity)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 Map (java.util.Map)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 Test (org.testng.annotations.Test)1