use of com.sun.identity.authentication.internal.InvalidAuthContextException in project OpenAM by OpenRock.
the class ImportServiceConfiguration method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
String xmlFile = getStringOptionValue(IArgument.XML_FILE);
String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
try {
encryptSecret = CLIUtil.getFileContent(getCommandManager(), encryptSecret).trim();
} catch (CLIException clie) {
//There is no encryptSecret file
}
validateEncryptSecret(xmlFile, encryptSecret);
// disable notification
SystemProperties.initializeProperties(Constants.SMS_ENABLE_DB_NOTIFICATION, "true");
SystemProperties.initializeProperties("com.sun.am.event.connection.disable.list", "sm,aci,um");
// disable error debug messsage
SystemProperties.initializeProperties(Constants.SYS_PROPERTY_INSTALL_TIME, "true");
IOutput outputWriter = getOutputWriter();
try (Connection ldConnection = getLDAPConnection()) {
InitializeSystem initSys = CommandManager.initSys;
SSOToken ssoToken = initSys.getSSOToken(getAdminPassword());
DirectoryServerVendor.Vendor vendor = DirectoryServerVendor.getInstance().query(ldConnection);
if (!vendor.name.equals(DirectoryServerVendor.OPENDJ) && !vendor.name.equals(DirectoryServerVendor.OPENDS) && !vendor.name.equals(DirectoryServerVendor.ODSEE)) {
throw new CLIException(getResourceString("import-service-configuration-unknown-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
loadLDIF(vendor, ldConnection);
String ouServices = "ou=services," + initSys.getRootSuffix();
if (this.isOuServicesExists(ssoToken, ouServices)) {
System.out.print(getResourceString("import-service-configuration-prompt-delete") + " ");
String value = (new BufferedReader(new InputStreamReader(System.in))).readLine();
value = value.trim();
if (value.equalsIgnoreCase("y") || value.equalsIgnoreCase("yes")) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
deleteOuServicesDescendents(ssoToken, ouServices);
importData(xmlFile, encryptSecret, ssoToken);
}
} else {
outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
importData(xmlFile, encryptSecret, ssoToken);
}
} catch (SMSException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (LdapException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (LoginException e) {
throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
} catch (InvalidAuthContextException e) {
throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
}
}
use of com.sun.identity.authentication.internal.InvalidAuthContextException in project OpenAM by OpenRock.
the class UpgradeUtils method ldapLoginInternal.
/**
* Returns the ssoToken used for admin operations.
* NOTE: this might be replaced later.
*
* @param bindUser the user distinguished name.
* @param bindPwd the user password
* @return the <code>SSOToken</code>
*/
private static SSOToken ldapLoginInternal(String bindUser, String bindPwd) {
String classMethod = "UpgradeUtils:ldapLoginInternal : ";
SSOToken ssoToken = null;
try {
com.sun.identity.authentication.internal.AuthContext ac = getLDAPAuthContext(bindUser, bindPwd);
if (ac.getLoginStatus() == AUTH_SUCCESS) {
ssoToken = ac.getSSOToken();
} else {
ssoToken = null;
}
} catch (LoginException le) {
debug.error(classMethod + "Error creating SSOToken", le);
} catch (InvalidAuthContextException iace) {
ssoToken = null;
debug.error(classMethod + "Error creating SSOToken", iace);
}
return ssoToken;
}
use of com.sun.identity.authentication.internal.InvalidAuthContextException in project OpenAM by OpenRock.
the class Authenticator method ldapLoginInternal.
private SSOToken ldapLoginInternal(CommandManager mgr, String bindUser, String bindPwd) throws CLIException {
SSOToken ssoToken = null;
ResourceBundle rb = mgr.getResourceBundle();
try {
com.sun.identity.authentication.internal.AuthContext ac = getLDAPAuthContext(bindUser, bindPwd);
if (ac.getLoginStatus() == com.sun.identity.authentication.internal.AuthContext.AUTH_SUCCESS) {
ssoToken = ac.getSSOToken();
AMIdentity amid = new AMIdentity(ssoToken, ssoToken.getPrincipal().getName(), IdType.USER, "/", null);
ssoToken.setProperty(Constants.UNIVERSAL_IDENTIFIER, amid.getUniversalId());
} else {
throw new CLIException(rb.getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
}
} catch (LoginException le) {
String[] params = { bindUser, le.getMessage() };
LogWriter.log(mgr, LogWriter.LOG_ERROR, Level.INFO, "FAILED_LOGIN", params, null);
throw new CLIException(rb.getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
} catch (SSOException e) {
String[] params = { bindUser, e.getMessage() };
LogWriter.log(mgr, LogWriter.LOG_ERROR, Level.INFO, "FAILED_LOGIN", params, null);
throw new CLIException(e, ExitCodes.LDAP_LOGIN_FAILED);
} catch (InvalidAuthContextException iace) {
String[] params = { bindUser, iace.getMessage() };
LogWriter.log(mgr, LogWriter.LOG_ERROR, Level.INFO, "FAILED_LOGIN", params, null);
throw new CLIException(rb.getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
}
return ssoToken;
}
Aggregations