Search in sources :

Example 21 with IOutput

use of com.sun.identity.cli.IOutput 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 22 with IOutput

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

the class DeleteService method deletePolicyRule.

private void deletePolicyRule(RequestContext rc, String serviceName, SSOToken adminSSOToken) throws CLIException, SMSException, SSOException {
    IOutput outputWriter = getOutputWriter();
    List listDelPolicyRule = (List) rc.getOption(ARGUMENT_DELETE_POLICY_RULE);
    if (listDelPolicyRule != null) {
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, adminSSOToken);
        if (ssm == null) {
            if (isVerbose()) {
                outputWriter.printlnMessage(getResourceString("delete-service-no-policy-rules"));
            }
        } else {
            if (ssm.getPolicySchema() == null) {
                if (isVerbose()) {
                    outputWriter.printlnMessage(getResourceString("delete-service-no-policy-schema"));
                }
            } else {
                if (isVerbose()) {
                    outputWriter.printlnMessage(getResourceString("delete-service-delete-policy-rules"));
                }
                processCleanPolicies(serviceName, adminSSOToken);
            }
        }
    }
}
Also used : IOutput(com.sun.identity.cli.IOutput) List(java.util.List) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 23 with IOutput

use of com.sun.identity.cli.IOutput 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 24 with IOutput

use of com.sun.identity.cli.IOutput 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 25 with IOutput

use of com.sun.identity.cli.IOutput 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)

Aggregations

IOutput (com.sun.identity.cli.IOutput)152 CLIException (com.sun.identity.cli.CLIException)137 SSOException (com.iplanet.sso.SSOException)123 SSOToken (com.iplanet.sso.SSOToken)99 SMSException (com.sun.identity.sm.SMSException)98 Set (java.util.Set)61 Iterator (java.util.Iterator)53 IdRepoException (com.sun.identity.idm.IdRepoException)45 List (java.util.List)45 AMIdentity (com.sun.identity.idm.AMIdentity)42 Map (java.util.Map)35 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)26 ServiceSchema (com.sun.identity.sm.ServiceSchema)26 IdType (com.sun.identity.idm.IdType)19 IOException (java.io.IOException)18 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)17 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)15 AttributeSchema (com.sun.identity.sm.AttributeSchema)14