Search in sources :

Example 66 with IOutput

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

the class GetAllowedIdOperations 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 type = getStringOptionValue(ARGUMENT_ID_TYPE);
    String[] params = { realm, type };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ALLOWED_OPS", params);
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        IdType idType = convert2IdType(type);
        Set ops = amir.getAllowedIdOperations(idType);
        String msg = getResourceString("allowed-ops-result");
        String[] arg = { "" };
        if ((ops != null) && !ops.isEmpty()) {
            for (Iterator i = ops.iterator(); i.hasNext(); ) {
                arg[0] = ((IdOperation) i.next()).getName();
                outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) arg));
            }
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-allowed-ops-no-ops"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ALLOWED_OPS", params);
    } catch (IdRepoException e) {
        String[] args = { realm, type, e.getMessage() };
        debugError("GetAllowedIdOperations.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ALLOWED_OPS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, type, e.getMessage() };
        debugError("GetAllowedIdOperations.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ALLOWED_OPS", 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) IdType(com.sun.identity.idm.IdType)

Example 67 with IOutput

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

the class GetMembers 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 membershipType = getStringOptionValue(ARGUMENT_MEMBERSHIP_IDTYPE);
    IdType membershipIdType = convert2IdType(membershipType);
    String[] params = { realm, type, idName, membershipType };
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        Set memberOfs = membershipIdType.canBeMemberOf();
        if (!memberOfs.contains(idType)) {
            String[] args = { type, membershipType };
            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_GET_MEMBERS", params);
        AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
        Set members = amid.getMembers(membershipIdType);
        if ((members != null) && !members.isEmpty()) {
            String msg = getResourceString("idrepo-members-result");
            String[] arg = { "", "" };
            for (Iterator i = members.iterator(); i.hasNext(); ) {
                AMIdentity a = (AMIdentity) i.next();
                arg[0] = a.getName();
                arg[1] = a.getUniversalId();
                outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) arg));
            }
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-no-members"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_GET_MEMBERS", params);
    } catch (IdRepoException e) {
        String[] args = { realm, type, idName, membershipType, e.getMessage() };
        debugError("GetMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_MEMBERS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, type, idName, membershipType, e.getMessage() };
        debugError("GetMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_MEMBERS", 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) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType)

Example 68 with IOutput

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

the class GetMemberships 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 membershipType = getStringOptionValue(ARGUMENT_MEMBERSHIP_IDTYPE);
    IdType membershipIdType = convert2IdType(membershipType);
    String[] params = { realm, type, idName, membershipType };
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        Set memberOfs = idType.canBeMemberOf();
        if (!memberOfs.contains(membershipIdType)) {
            String[] args = { type, membershipType };
            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_GET_MEMBERSHIPS", params);
        AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
        Set memberships = amid.getMemberships(membershipIdType);
        if ((memberships != null) && !memberships.isEmpty()) {
            String msg = getResourceString("idrepo-memberships-result");
            String[] arg = { "", "" };
            for (Iterator i = memberships.iterator(); i.hasNext(); ) {
                AMIdentity a = (AMIdentity) i.next();
                arg[0] = a.getName();
                arg[1] = a.getUniversalId();
                outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) arg));
            }
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-no-memberships"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_GET_MEMBERSHIPS", params);
    } catch (IdRepoException e) {
        String[] args = { realm, type, idName, membershipType, e.getMessage() };
        debugError("GetMemberships.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_MEMBERSHIPS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, type, idName, membershipType, e.getMessage() };
        debugError("GetMemberships.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_MEMBERSHIPS", 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) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType)

Example 69 with IOutput

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

the class GetPrivileges 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[] params = { realm, type, idName };
    try {
        DelegationManager mgr = new DelegationManager(adminSSOToken, realm);
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_GET_PRIVILEGES", params);
        AMIdentity amid;
        if (idType.equals(IdType.ROLE) && idName.equalsIgnoreCase(ALL_AUTHENTICATED_USERS)) {
            //realm needs to be /, see DelegationPolicyImpl#privilegeToPolicy implementation
            amid = new AMIdentity(adminSSOToken, idName, idType, "/", null);
        //do not check the existense of all authenticated users role as it would fail
        } else {
            amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
            if (!amid.isExists()) {
                Object[] p = { idName, type };
                throw new CLIException(MessageFormat.format(getResourceString("identity-does-not-exist"), p), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
            }
        }
        Set results = mgr.getPrivileges(amid.getUniversalId());
        if ((results != null) && !results.isEmpty()) {
            String[] param = { "" };
            String msg = getResourceString("privilege-result");
            for (Iterator i = results.iterator(); i.hasNext(); ) {
                DelegationPrivilege p = (DelegationPrivilege) i.next();
                param[0] = p.getName();
                outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) param));
            }
        } else {
            outputWriter.printlnMessage(getResourceString("no-privileges"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_GET_PRIVILEGES", params);
    } catch (DelegationException e) {
        String[] args = { realm, type, idName, e.getMessage() };
        debugError("GetPrivileges.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_PRIVILEGES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IdRepoException e) {
        String[] args = { realm, type, idName, e.getMessage() };
        debugError("GetPrivileges.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_PRIVILEGES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, type, idName, e.getMessage() };
        debugError("GetPrivileges.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_GET_PRIVILEGES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IdRepoException(com.sun.identity.idm.IdRepoException) DelegationException(com.sun.identity.delegation.DelegationException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType) DelegationPrivilege(com.sun.identity.delegation.DelegationPrivilege) IOutput(com.sun.identity.cli.IOutput) DelegationManager(com.sun.identity.delegation.DelegationManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException)

Example 70 with IOutput

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

the class AddMember 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_ADD_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.addMember(memberAmid);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-get-addmember-succeed"), (Object[]) args));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_ADD_MEMBER", params);
    } catch (IdRepoException e) {
        String[] args = { realm, type, idName, memberIdName, memberType, e.getMessage() };
        debugError("AddMember.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ADD_MEMBER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, type, idName, memberIdName, memberType, e.getMessage() };
        debugError("AddMember.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ADD_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)

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