Search in sources :

Example 91 with SSOToken

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

the class SampleTokenListener method ssoTokenChanged.

public void ssoTokenChanged(SSOTokenEvent event) {
    try {
        SSOToken token = event.getToken();
        int type = event.getType();
        long time = event.getTime();
        System.out.println("Token id is: " + token.getTokenID().toString());
        if (SSOTokenManager.getInstance().isValidToken(token)) {
            System.out.println("Token is Valid");
        } else {
            System.out.println("Token is Invalid");
        }
        switch(type) {
            case SSOTokenEvent.SSO_TOKEN_IDLE_TIMEOUT:
                System.out.println("Token Idel Timeout event");
                break;
            case SSOTokenEvent.SSO_TOKEN_MAX_TIMEOUT:
                System.out.println("Token Max Timeout event");
                break;
            case SSOTokenEvent.SSO_TOKEN_DESTROY:
                System.out.println("Token Destroyed event");
                break;
            default:
                System.out.println("Unknown Token event");
                break;
        }
    } catch (SSOException e) {
        System.out.println(e.getMessage());
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SSOException(com.iplanet.sso.SSOException)

Example 92 with SSOToken

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

the class ServiceConfigServlet method printInfo.

private void printInfo(AuthContext lc, String servicename, String method, PrintWriter out) throws Exception {
    // Obtain the SSO Token
    SSOToken token = lc.getSSOToken();
    out.println("<br><h3>SSOToken:</h3> " + token.getTokenID());
    out.println("<p>");
    // Obtain Service Manager
    if (method.equalsIgnoreCase("globalSchema")) {
        ServiceSchemaManager ssm = new ServiceSchemaManager(servicename, token);
        out.println(ssm.getGlobalSchema().toString());
    } else if (method.equalsIgnoreCase("globalConfig")) {
        ServiceConfigManager scm = new ServiceConfigManager(servicename, token);
        out.println(scm.getGlobalConfig(null).toString());
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 93 with SSOToken

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

the class UserProfileServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // Get query parameters
    String orgname = request.getParameter("orgname");
    if (orgname == null || orgname.length() == 0) {
        orgname = "/";
    }
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    response.setContentType("text/html");
    // Get the output stream
    PrintWriter out = response.getWriter();
    out.println(SampleConstants.HTML_HEADER);
    if (username == null || password == null) {
        out.println("Value for user name and password are required.");
        out.println("</body></html>");
        return;
    }
    out.println("<br><h3>Username:</h3> " + username);
    try {
        // Authenticate the user and obtain SSO Token
        AuthContext lc = authenticate(orgname, username, password, out);
        if (lc != null) {
            // Obtain the SSO Token
            SSOToken token = lc.getSSOToken();
            out.println("<br><h3>SSOToken:</h3> " + token.getTokenID());
            out.println("<br><h3>User DN:</h3> " + token.getPrincipal().getName());
            out.println("<p>");
            AMIdentity amid = IdUtils.getIdentity(token);
            Map attrs = amid.getAttributes();
            out.println("User Attributes: ");
            for (Iterator i = attrs.keySet().iterator(); i.hasNext(); ) {
                String attrName = (String) i.next();
                Set values = (Set) attrs.get(attrName);
                out.println(attrName + "=" + values);
            }
        }
    } catch (Exception e) {
        e.printStackTrace(out);
        out.println("</body></html>");
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) AuthContext(com.sun.identity.authentication.AuthContext) Map(java.util.Map) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 94 with SSOToken

use of com.iplanet.sso.SSOToken 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 95 with SSOToken

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

the class IdRepoSampleUtils method realmLogin.

public SSOToken realmLogin(String userid, String password, String realm) throws SSOException, AuthLoginException, Exception {
    SSOTokenManager mgr;
    String adminDN;
    String adminPassword;
    SSOToken ssoToken = null;
    AuthContext.IndexType authType = AuthContext.IndexType.MODULE_INSTANCE;
    try {
        lc = new AuthContext(realm);
    } catch (AuthLoginException le) {
        System.err.println("IdRepoSampleUtils: could not get AuthContext for realm " + realm);
        throw le;
    }
    try {
        lc.login();
    } catch (AuthLoginException le) {
        System.err.println("IdRepoSampleUtils: Failed to start login " + "for default authmodule");
        throw le;
    }
    userID = userid;
    Callback[] callbacks = null;
    Hashtable values = new Hashtable();
    values.put(AuthXMLTags.NAME_CALLBACK, userid);
    values.put(AuthXMLTags.PASSWORD_CALLBACK, password);
    while (lc.hasMoreRequirements()) {
        callbacks = lc.getRequirements();
        try {
            fillCallbacks(callbacks, values);
            lc.submitRequirements(callbacks);
        } catch (Exception e) {
            System.err.println("Failed to submit callbacks!");
            e.printStackTrace();
            return null;
        }
    }
    AuthContext.Status istat = lc.getStatus();
    if (istat == AuthContext.Status.SUCCESS) {
        System.out.println("==>Authentication SUCCESSFUL for user " + userid);
    } else if (istat == AuthContext.Status.COMPLETED) {
        System.out.println("==>Authentication Status for user " + userid + " = " + istat);
        return null;
    }
    try {
        ssoToken = lc.getSSOToken();
    } catch (Exception e) {
        System.err.println("Failed to get SSO token!  " + e.getMessage());
        throw e;
    }
    return ssoToken;
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) AuthContext(com.sun.identity.authentication.AuthContext) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Aggregations

SSOToken (com.iplanet.sso.SSOToken)776 SSOException (com.iplanet.sso.SSOException)390 Set (java.util.Set)226 SMSException (com.sun.identity.sm.SMSException)218 HashSet (java.util.HashSet)179 IdRepoException (com.sun.identity.idm.IdRepoException)144 HashMap (java.util.HashMap)130 Test (org.testng.annotations.Test)130 CLIException (com.sun.identity.cli.CLIException)117 Iterator (java.util.Iterator)115 AMIdentity (com.sun.identity.idm.AMIdentity)113 Map (java.util.Map)113 IOutput (com.sun.identity.cli.IOutput)99 IOException (java.io.IOException)68 List (java.util.List)57 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)56 IdType (com.sun.identity.idm.IdType)54 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)53 EntitlementException (com.sun.identity.entitlement.EntitlementException)52 ServiceConfig (com.sun.identity.sm.ServiceConfig)52