Search in sources :

Example 41 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class RealmGetAssignedServices 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);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    boolean incMandatory = isOptionSet(IArgument.MANDATORY);
    String strMandatory = (incMandatory) ? "include mandatory" : "exclude mandatory";
    String[] params = { realm, strMandatory };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ASSIGNED_SERVICES_OF_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set serviceNames = ocm.getAssignedServices(incMandatory);
        Set dynamicServiceNames = getAssignedDynamicServiceNames(adminSSOToken, realm);
        if ((dynamicServiceNames != null) && !dynamicServiceNames.isEmpty()) {
            if ((serviceNames != null) && !serviceNames.isEmpty()) {
                serviceNames.addAll(dynamicServiceNames);
            } else {
                serviceNames = dynamicServiceNames;
            }
        }
        IOutput outputWriter = getOutputWriter();
        if ((serviceNames != null) && !serviceNames.isEmpty()) {
            String msg = getResourceString("realm-get-assigned-services-results");
            outputWriter.printlnMessage(FormatUtils.printServiceNames(serviceNames, msg, adminSSOToken));
            outputWriter.printlnMessage(getResourceString("realm-get-assigned-services-succeed"));
        } else {
            outputWriter.printlnMessage(getResourceString("realm-get-assigned-services-no-services"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ASSIGNED_SERVICES_OF_REALM", params);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignedServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES_OF_REALM", args);
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignedServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES_OF_REALM", args);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignedServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES_OF_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 42 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class DeleteSubConfiguration method deleteSubConfigToRoot.

private void deleteSubConfigToRoot(String serviceName, String subConfigName) throws CLIException {
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String[] params = { subConfigName, serviceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_SUB_CONFIGURATION", params);
    try {
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminSSOToken);
        ServiceConfig sc = scm.getGlobalConfig(null);
        deleteSubConfig(sc, subConfigName);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_SUB_CONFIGURATION", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("delete-sub-configuration-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { subConfigName, serviceName, e.getMessage() };
        debugError("DeleteSubConfiguration.deleteSubConfigToRoot", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SUB_CONFIGURATION", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { subConfigName, serviceName, e.getMessage() };
        debugError("DeleteSubConfiguration.deleteSubConfigToRoot", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SUB_CONFIGURATION", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 43 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class ImportServiceConfiguration method getLDAPConnection.

private Connection getLDAPConnection() throws CLIException {
    IOutput outputWriter = getOutputWriter();
    if (isVerbose()) {
        outputWriter.printlnMessage(getResourceString("import-service-configuration-connecting-to-ds"));
    }
    try {
        Connection conn;
        DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
        ServerGroup sg = dsCfg.getServerGroup("sms");
        if (sg != null) {
            conn = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN).getConnection();
        } else {
            throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
        }
        if (isVerbose()) {
            outputWriter.printlnMessage(getResourceString("import-service-configuration-connected-to-ds"));
        }
        return conn;
    } catch (LDAPServiceException | LdapException e) {
        throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
    }
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) IOutput(com.sun.identity.cli.IOutput) Connection(org.forgerock.opendj.ldap.Connection) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) CLIException(com.sun.identity.cli.CLIException) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 44 with CLIException

use of com.sun.identity.cli.CLIException 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);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) InputStreamReader(java.io.InputStreamReader) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) InitializeSystem(com.sun.identity.cli.InitializeSystem) IOutput(com.sun.identity.cli.IOutput) BufferedReader(java.io.BufferedReader) CLIException(com.sun.identity.cli.CLIException) DirectoryServerVendor(com.sun.identity.sm.DirectoryServerVendor) LoginException(javax.security.auth.login.LoginException) LdapException(org.forgerock.opendj.ldap.LdapException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException)

Example 45 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class LoadSchema method loadSchemaXML.

private void loadSchemaXML(ServiceManager ssm, String xml) throws CLIException {
    ByteArrayInputStream bis = null;
    try {
        bis = new ByteArrayInputStream(xml.getBytes());
        ssm.registerServices(bis);
    } catch (SSOException e) {
        String[] args = { CLIConstants.WEB_INPUT, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_LOAD_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { CLIConstants.WEB_INPUT, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_LOAD_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (bis != null) {
            try {
                bis.close();
            } catch (IOException ie) {
            //ignore if file input stream cannot be closed.
            }
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SMSException(com.sun.identity.sm.SMSException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException)

Aggregations

CLIException (com.sun.identity.cli.CLIException)282 SSOException (com.iplanet.sso.SSOException)171 SMSException (com.sun.identity.sm.SMSException)150 IOutput (com.sun.identity.cli.IOutput)136 SSOToken (com.iplanet.sso.SSOToken)116 Set (java.util.Set)88 Iterator (java.util.Iterator)62 List (java.util.List)61 IOException (java.io.IOException)53 IdRepoException (com.sun.identity.idm.IdRepoException)48 ServiceSchema (com.sun.identity.sm.ServiceSchema)46 AMIdentity (com.sun.identity.idm.AMIdentity)43 Map (java.util.Map)42 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)33 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)29 AttributeSchema (com.sun.identity.sm.AttributeSchema)28 CLIRequest (com.sun.identity.cli.CLIRequest)27 AfterTest (org.testng.annotations.AfterTest)27 BeforeTest (org.testng.annotations.BeforeTest)27 Test (org.testng.annotations.Test)27