Search in sources :

Example 16 with CLIException

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

the class GetSupportedIdTypes 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);
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String[] params = { realm };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_SUPPORTED_IDTYPES", params);
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        Set supportedIdTypes = amir.getSupportedIdTypes();
        if ((supportedIdTypes != null) && !supportedIdTypes.isEmpty()) {
            String msg = getResourceString("supported-type-result");
            String[] arg = { "" };
            for (Iterator i = supportedIdTypes.iterator(); i.hasNext(); ) {
                arg[0] = ((IdType) i.next()).getName();
                outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) arg));
            }
        } else {
            outputWriter.printlnMessage(getResourceString("no-supported-idtype"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_SUPPORTED_IDTYPES", params);
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("GetSupportedIdTypes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SUPPORTED_IDTYPES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("GetSupportedIdTypes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SUPPORTED_IDTYPES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IOutput(com.sun.identity.cli.IOutput) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 17 with CLIException

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

the class ModifyService 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);
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String idName = getStringOptionValue(ARGUMENT_ID_NAME);
    String type = getStringOptionValue(ARGUMENT_ID_TYPE);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    IdType idType = convert2IdType(type);
    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);
    String[] params = { realm, type, idName, serviceName };
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_MODIFY_SERVICE", params);
        AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
        amid.modifyService(serviceName, attributeValues);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-modify-service-succeed"), (Object[]) params));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_MODIFY_SERVICE", params);
    } catch (IdRepoException e) {
        String[] args = { realm, type, idName, serviceName, e.getMessage() };
        debugError("ModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_MODIFY_SERVICE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, type, idName, serviceName, e.getMessage() };
        debugError("ModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_MODIFY_SERVICE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map) IdType(com.sun.identity.idm.IdType)

Example 18 with CLIException

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

the class RemoveMember 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);
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String idName = getStringOptionValue(ARGUMENT_ID_NAME);
    String type = getStringOptionValue(ARGUMENT_ID_TYPE);
    IdType idType = convert2IdType(type);
    String memberIdName = getStringOptionValue(ARGUMENT_MEMBER_IDNAME);
    String memberType = getStringOptionValue(ARGUMENT_MEMBER_IDTYPE);
    IdType memberIdType = convert2IdType(memberType);
    String[] params = { realm, type, idName, memberIdName, memberType };
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        Set memberOfs = memberIdType.canBeMemberOf();
        if (!memberOfs.contains(idType)) {
            String[] args = { type, memberType };
            throw new CLIException(MessageFormat.format(getResourceString("idrepo-cannot-be-member"), (Object[]) args), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_REMOVE_MEMBER", params);
        AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
        AMIdentity memberAmid = new AMIdentity(adminSSOToken, memberIdName, memberIdType, realm, null);
        String[] args = { memberIdName, idName };
        amid.removeMember(memberAmid);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-get-removemember-succeed"), (Object[]) args));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_REMOVE_MEMBER", params);
    } catch (IdRepoException e) {
        String[] args = { realm, type, idName, memberIdName, memberType, e.getMessage() };
        debugError("RemoveMember.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_REMOVE_MEMBER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, type, idName, memberIdName, memberType, e.getMessage() };
        debugError("RemoveMember.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_REMOVE_MEMBER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType)

Example 19 with CLIException

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

the class RemoveApplicationPrivilegeSubjects 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);
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String name = getStringOptionValue(PARAM_NAME);
    String[] params = { realm, name };
    Set<SubjectImplementation> newSubjects = getSubjects(rc);
    Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
    ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_APPLICATION_PRIVILEGE", params);
    try {
        ApplicationPrivilege appPrivilege = apm.getPrivilege(name);
        Set<SubjectImplementation> origSubjects = appPrivilege.getSubjects();
        origSubjects.removeAll(newSubjects);
        if (origSubjects.isEmpty()) {
            throw new CLIException(getResourceString("remove-application-privilege-subjects-emptied-subjects"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        appPrivilege.setSubject(origSubjects);
        apm.replacePrivilege(appPrivilege);
        Object[] msgParam = { name };
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("update-application-privilege-succeeded"), msgParam));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_UPDATE_APPLICATION_PRIVILEGE", params);
    } catch (EntitlementException ex) {
        String[] paramExs = { realm, name, ex.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_UPDATE_APPLICATION_PRIVILEGE", paramExs);
        throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationPrivilege(com.sun.identity.entitlement.ApplicationPrivilege) CLIException(com.sun.identity.cli.CLIException) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation) ApplicationPrivilegeManager(com.sun.identity.entitlement.ApplicationPrivilegeManager) Subject(javax.security.auth.Subject)

Example 20 with CLIException

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

the class SetApplication 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);
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String appName = getStringOptionValue(PARAM_APPL_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);
    String[] params = { realm, appName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_APPLICATION", params);
    Subject adminSubject = getAdminSubject();
    try {
        Application appl = ApplicationManager.getApplication(adminSubject, realm, appName);
        Object[] param = { appName };
        if (appl == null) {
            throw new CLIException(MessageFormat.format(getResourceString("set-application-not-found"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        setApplicationAttributes(appl, attributeValues, false);
        ApplicationManager.saveApplication(getAdminSubject(), realm, appl);
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("set-application-modified"), param));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_SET_APPLICATION", params);
    } catch (EntitlementException e) {
        String[] paramExs = { realm, appName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_SET_APPLICATION", paramExs);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (CLIException e) {
        String[] paramExs = { realm, appName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_SET_APPLICATION", paramExs);
        throw e;
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) Set(java.util.Set) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject)

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