Search in sources :

Example 31 with CLIException

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

the class RealmModifyService 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();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    attributeValues = processFileAttributes(attributeValues);
    try {
        String[] params = { realm, serviceName };
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set assignedServices = ocm.getAssignedServices(true);
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = repo.getRealmIdentity();
        Set servicesFromIdRepo = ai.getAssignedServices();
        boolean modified = false;
        if (assignedServices.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_SERVICE_REALM", params);
            ocm.modifyService(serviceName, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SERVICE_REALM", params);
            modified = true;
        }
        if (servicesFromIdRepo.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_SERVICE_REALM", params);
            ai.modifyService(serviceName, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SERVICE_REALM", params);
            modified = true;
        }
        if (modified) {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-service-of-realm-succeed"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-service-of-realm-not-assigned"), (Object[]) params));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_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) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

Example 32 with CLIException

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

the class RealmRemoveAttribute 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);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String attributeName = getStringOptionValue(IArgument.ATTRIBUTE_NAME);
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { realm, serviceName, attributeName };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_REALM_ATTRIBUTE", params);
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        ocm.removeAttribute(serviceName, attributeName);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-attribute-from-realm-succeed"), (Object[]) params));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_REALM_ATTRIBUTE", params);
    } catch (SMSException e) {
        String[] args = { realm, serviceName, attributeName, e.getMessage() };
        debugError("RealmRemoveAttribute.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_REALM_ATTRIBUTE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) CLIException(com.sun.identity.cli.CLIException)

Example 33 with CLIException

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

the class RealmRemoveServiceAttributes 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();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    try {
        String[] params = { realm, serviceName };
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set assignedServices = ocm.getAssignedServices(true);
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = repo.getRealmIdentity();
        Set servicesFromIdRepo = ai.getAssignedServices();
        boolean modified = false;
        if (assignedServices.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            Map origValues = ocm.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, false)) {
                ocm.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (servicesFromIdRepo.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            Map origValues = ai.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, false)) {
                ai.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (modified) {
            outputWriter.printlnMessage(getResourceString("realm-remove-service-attributes-succeed"));
            outputWriter.printlnMessage("");
            outputWriter.printlnMessage(FormatUtils.printAttributeValues("{0}={1}", attributeValues));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("realm-remove-service-attributes-not-assigned"), (Object[]) params));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmRemoveServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmRemoveServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmRemoveServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", 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) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) Map(java.util.Map)

Example 34 with CLIException

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

the class RealmAddServiceAttributes method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    attributeValues = processFileAttributes(attributeValues);
    try {
        String[] params = { realm, serviceName };
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Map<String, Boolean> mapAttrType = getMultipleValueAttrs(serviceName);
        Set assignedServices = ocm.getAssignedServices(true);
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = repo.getRealmIdentity();
        Set servicesFromIdRepo = ai.getAssignedServices();
        boolean modified = false;
        if (assignedServices.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_ADD_SERVICE_ATTR_VALUES", params);
            Map origValues = ocm.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, mapAttrType, true)) {
                ocm.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_ADD_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (servicesFromIdRepo.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_ADD_SERVICE_ATTR_VALUES", params);
            Map origValues = ai.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, mapAttrType, true)) {
                ai.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_ADD_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (modified) {
            outputWriter.printlnMessage(getResourceString("realm-add-service-attributes-succeed"));
            outputWriter.printlnMessage("");
            outputWriter.printlnMessage(FormatUtils.printAttributeValues("{0}={1}", attributeValues));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("realm-add-service-attributes-not-assigned"), (Object[]) params));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmAddServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmAddServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmAddServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", 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) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 35 with CLIException

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

the class RealmAssignService 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);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    Map<String, Set<String>> attributeValues = null;
    if ((datafile != null) || (attrValues != null)) {
        attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
        attributeValues = processFileAttributes(attributeValues);
    }
    IOutput outputWriter = getOutputWriter();
    String[] params = { realm, serviceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ASSIGN_SERVICE_TO_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set assignableServices = ocm.getAssignableServices();
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = amir.getRealmIdentity();
        Set dynAssignableServices = ai.getAssignableServices();
        if (assignableServices.contains(serviceName)) {
            ocm.assignService(serviceName, attributeValues);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
        }
        if (dynAssignableServices.contains(serviceName)) {
            ai.assignService(serviceName, attributeValues);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ASSIGN_SERVICE_TO_REALM", params);
    } catch (SSOException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IdRepoException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_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) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

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