use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.
the class Authenticator method sessionBasedLoginInternal.
private AuthContext sessionBasedLoginInternal(CommandManager mgr, String bindUser, String bindPwd, String indexType, String indexName) throws CLIException {
AuthContext lc = getAuthContext(mgr, indexType, indexName);
processCallback(mgr, lc, bindUser, bindPwd);
try {
lc.getSSOToken();
} catch (Exception e) {
ResourceBundle rb = mgr.getResourceBundle();
throw new CLIException(rb.getString("exception-session-based-login-failed"), ExitCodes.SESSION_BASED_LOGIN_FAILED);
}
return lc;
}
use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.
the class SystemAppTokenProvider method getAppSSOToken.
/**
* Returns Application single sign on token.
*
* @return application single sign on token.
*/
public SSOToken getAppSSOToken() {
SSOToken ssoToken = null;
try {
AuthContext authContext = new AuthContext("/");
authContext.login(AuthContext.IndexType.MODULE_INSTANCE, MODULE_APPLICATION);
if (authContext.hasMoreRequirements()) {
Callback[] callbacks = authContext.getRequirements();
if (callbacks != null) {
addLoginCallbackMessage(callbacks, appUserName, appPassword);
authContext.submitRequirements(callbacks);
}
}
if (authContext.getStatus() == AuthContext.Status.SUCCESS) {
ssoToken = authContext.getSSOToken();
}
} catch (AuthLoginException ale) {
AdminTokenAction.debug.error("SystemAppTokenProvider.getAppSSOToken()", ale);
} catch (UnsupportedCallbackException usce) {
AdminTokenAction.debug.error("SystemAppTokenProvider.getAppSSOToken()", usce);
} catch (Exception e) {
AdminTokenAction.debug.error("SystemAppTokenProvider.getAppSSOToken()", e);
}
return ssoToken;
}
use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.
the class TokenUtils method getSessionToken.
public static SSOToken getSessionToken(String orgName, String userId, String password, String module, int level) throws Exception {
AuthContext ac = null;
try {
//System.out.println("TokenUtils:orgName=" + orgName);
ac = new AuthContext(orgName);
if (module != null) {
ac.login(AuthContext.IndexType.MODULE_INSTANCE, module);
} else if (level != -1) {
ac.login(AuthContext.IndexType.LEVEL, String.valueOf(level));
} else {
//System.out.println("TokenUtils:calling login()");
ac.login();
}
//System.out.println("TokenUtils:after ac.login()");
} catch (LoginException le) {
le.printStackTrace();
return null;
}
try {
Callback[] callbacks = null;
// Get the information requested by the plug-ins
if (ac.hasMoreRequirements()) {
callbacks = ac.getRequirements();
if (callbacks != null) {
addLoginCallbackMessage(callbacks, userId, password);
ac.submitRequirements(callbacks);
if (ac.getStatus() == AuthContext.Status.SUCCESS) {
//System.out.println("Auth success");
Subject authSubject = ac.getSubject();
if (authSubject != null) {
Iterator principals = (authSubject.getPrincipals()).iterator();
Principal principal;
while (principals.hasNext()) {
principal = (Principal) principals.next();
}
}
} else if (ac.getStatus() == AuthContext.Status.FAILED) {
//System.out.println("Authentication has FAILED");
} else {
}
} else {
}
}
} catch (Exception e) {
e.printStackTrace();
}
//System.out.println(ac.getSSOToken().getPrincipal().getName());
return ac.getSSOToken();
}
use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.
the class LogSample method logWriteProcessing.
private void logWriteProcessing() {
/*
* get:
* 1. subject userid (subject of the LogRecord)
* 2. subject userid's password
* 3. Log filename to log to
* 4. LogRecord's "data"
* 5. LoggedBy userid (who's doing the logging)
* 6. LoggedBy userid's password
* 7. Realm (for both subject userid and LoggedBy userid
* in this sample)
*/
String userSID = sampleUtils.getLine("Subject Userid", DEF_USERNAME);
String userPWD = sampleUtils.getLine("Subject Userid " + userSID + "'s password", DEF_USERPSWD);
String logName = sampleUtils.getLine("Log file", DEF_LOGNAME);
String message = sampleUtils.getLine("Log message", DEF_LOGMSG);
;
String loggedBySID = sampleUtils.getLine("LoggedBy Userid", DEF_LOGGEDBY);
String loggedByPWD = sampleUtils.getLine("LoggedBy Userid's password", DEF_LOGGEDBYPSWD);
String realmName = sampleUtils.getLine("Realm", DEF_REALM);
// get AuthContexts for subject userid and loggedby userid
try {
userAC = new AuthContext(realmName);
loggerAC = new AuthContext(realmName);
} catch (AuthLoginException le) {
System.err.println("LogSampleUtils: could not get AuthContext for realm " + realmName);
System.exit(2);
}
// do user and loggedby login and get the SSOToken
try {
userSSOToken = sampleUtils.realmLogin(userSID, userPWD, userAC);
loggerSSOToken = sampleUtils.realmLogin(loggedBySID, loggedByPWD, loggerAC);
} catch (SSOException ssoe) {
System.err.println("logWriteProcessing: could not get SSOToken: " + ssoe.getMessage());
System.exit(3);
} catch (AuthLoginException ale) {
System.err.println("logWriteProcessing: could not authenticate: " + ale.getMessage());
System.exit(4);
} catch (Exception e) {
System.err.println("logWriteProcessing: exception getting SSOToken: " + e.getMessage());
System.exit(5);
}
try {
LogRecord logRecord = new LogRecord(java.util.logging.Level.INFO, message, userSSOToken);
logRecord.addLogInfo("ModuleName", DEF_MODULENAME);
java.net.InetAddress ipAddr = java.net.InetAddress.getLocalHost();
logRecord.addLogInfo("IPAddr", ipAddr.getHostAddress());
Logger logger = (Logger) Logger.getLogger(logName);
logger.log(logRecord, loggerSSOToken);
System.out.println("LogSample: Logging Successful !!!");
userAC.logout();
loggerAC.logout();
} catch (AMLogException amex) {
System.err.println("LogSample: AMLogException: " + amex.getMessage());
System.err.println("LogSample: Logging Failed; " + "Is user '" + loggedBySID + "' a member of a Role or Group with log writing privileges?");
} catch (Exception ssoe) {
System.err.println("LogSample: Exception: " + ssoe.getMessage());
System.err.println("LogSample: Logging Failed !!!");
}
}
use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.
the class SampleBase method authenticate.
protected AuthContext authenticate(String orgname, String username, String password, PrintWriter out) throws Exception {
// Authenticate the user and obtain SSO Token
AuthContext lc = new AuthContext(orgname);
lc.login();
while (lc.hasMoreRequirements()) {
Callback[] callbacks = lc.getRequirements();
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback nc = (NameCallback) callbacks[i];
nc.setName(username);
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) callbacks[i];
pc.setPassword(password.toCharArray());
} else {
out.println("Unknow Callback: " + callbacks[i]);
out.println("</body></html>");
return null;
}
}
lc.submitRequirements(callbacks);
}
if (lc.getStatus() != AuthContext.Status.SUCCESS) {
out.println("Invalid credentials");
out.println("</body></html>");
return null;
}
return lc;
}
Aggregations