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());
}
}
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());
}
}
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>");
}
}
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
}
}
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;
}
Aggregations