use of com.sun.identity.authentication.internal.AuthContext in project OpenAM by OpenRock.
the class InitializeSystem method getSSOToken.
public SSOToken getSSOToken(String bindPwd) throws LoginException, InvalidAuthContextException {
SSOToken ssoToken = null;
String userRootSuffix = bData.getUserBaseDN();
AuthPrincipal principal = new AuthPrincipal("cn=dsameuser,ou=DSAME Users," + userRootSuffix);
AuthContext ac = new AuthContext(userRootSuffix, principal, bindPwd.toCharArray());
if (ac.getLoginStatus() == AuthContext.AUTH_SUCCESS) {
ssoToken = ac.getSSOToken();
}
return ssoToken;
}
use of com.sun.identity.authentication.internal.AuthContext in project OpenAM by OpenRock.
the class ServerConfigMgr method changePassword.
/**
* Checks and sets the password
*/
private void changePassword(String userType, String oldPassword, String newPassword) throws Exception {
String fileEncPassword = getUserPassword(userType);
String userDN = getUserDN(userType);
if ((fileEncPassword == null) || (fileEncPassword.length() == 0) || (userDN == null) || (userDN.length() == 0)) {
debug.error("Null password or user DN for user type: " + userType + " from file: " + configFile);
throw new XMLException(i18n.getString("dscfg-corrupted-serverconfig"));
}
// Verify old password
if (!oldPassword.equals(AccessController.doPrivileged(new DecodeAction(fileEncPassword)))) {
throw new Exception(i18n.getString("dscfg-old-passwd-donot-match"));
}
if (isAMSDKConfigured) {
// this is to check if updating of DS is required.
try {
new AuthContext(new AuthPrincipal(userDN), newPassword.toCharArray());
if (debug.messageEnabled()) {
debug.message("DN: " + userDN + " new password is already updated in the directory");
}
} catch (LoginException lee) {
try {
AuthContext ac = new AuthContext(new AuthPrincipal(userDN), oldPassword.toCharArray());
PersistentObject user = UMSObject.getObject(ac.getSSOToken(), new Guid(userDN));
if (debug.messageEnabled()) {
debug.message("For DN: " + userDN + " changing password in directory");
}
user.setAttribute(new Attr("userPassword", newPassword));
user.save();
} catch (LoginException le) {
if (debug.warningEnabled()) {
debug.warning("For DN: " + userDN + " new and old passwords donot match with directory");
}
throw new Exception(i18n.getString("dscfg-invalid-password") + "\n" + le.getMessage());
}
}
}
setUserPassword(userType, newPassword);
}
use of com.sun.identity.authentication.internal.AuthContext in project OpenAM by OpenRock.
the class AdminTokenAction method getSSOToken.
private SSOToken getSSOToken() {
// Please NEVER make this method public!!!!!!!!!!
// This can only be used in server site.
SSOToken ssoAuthToken = null;
try {
//call method directly
if (AdminUtils.getAdminPassword() != null) {
String adminDN = AdminUtils.getAdminDN();
String adminPassword = new String(AdminUtils.getAdminPassword());
if (!authInitialized && (SystemProperties.isServerMode() || SystemProperties.get(AMADMIN_MODE) != null)) {
// Use internal auth context to get the SSOToken
AuthContext ac = new AuthContext(new AuthPrincipal(adminDN), adminPassword.toCharArray());
internalAppSSOToken = ssoAuthToken = ac.getSSOToken();
} else {
// Copy the authentication state
boolean authInit = authInitialized;
if (authInit) {
authInitialized = false;
}
// Obtain SSOToken using AuthN service
ssoAuthToken = new SystemAppTokenProvider(adminDN, adminPassword).getAppSSOToken();
// Restore the authentication state
if (authInit && ssoAuthToken != null) {
authInitialized = true;
}
}
}
} catch (NoClassDefFoundError ne) {
debug.error("AdminTokenAction::getSSOToken Not found AdminDN and AdminPassword.", ne);
} catch (Throwable t) {
debug.error("AdminTokenAction::getSSOToken Exception reading from serverconfig.xml", t);
}
return ssoAuthToken;
}
use of com.sun.identity.authentication.internal.AuthContext in project OpenAM by OpenRock.
the class Bootstrap method getSSOToken.
private static SSOToken getSSOToken(String basedn, String bindUser, String bindPwd) throws LoginException, InvalidAuthContextException {
SSOToken ssoToken = null;
AuthPrincipal principal = new AuthPrincipal(bindUser);
AuthContext ac = new AuthContext(basedn, principal, bindPwd.toCharArray());
if (ac.getLoginStatus() == AuthContext.AUTH_SUCCESS) {
ssoToken = ac.getSSOToken();
}
return ssoToken;
}
use of com.sun.identity.authentication.internal.AuthContext in project OpenAM by OpenRock.
the class ImportConfig method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.err.println("usage: serverAdmin import xmlFile");
System.exit(1);
}
if (args[0].equals("import")) {
try {
FileInputStream fisSchema = new FileInputStream(args[1]);
DSConfigMgr cfgMgr = DSConfigMgr.getDSConfigMgr();
ServerInstance sInst = cfgMgr.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
authPcpl = new AuthPrincipal(sInst.getAuthID());
AuthContext authCtx = new AuthContext(authPcpl, sInst.getPasswd().toCharArray());
SSOToken userSSOToken = authCtx.getSSOToken();
ServiceManager smsMgr = new ServiceManager(userSSOToken);
smsMgr.registerServices(fisSchema);
} catch (Exception e) {
e.printStackTrace();
System.err.println(e);
}
}
}
Aggregations