Search in sources :

Example 96 with CLIException

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

the class RemoveSiteFailoverURLs 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 siteName = getStringOptionValue(IArgument.SITE_NAME);
    List secondaryURLs = (List) rc.getOption(IArgument.SECONDARY_URLS);
    String[] params = { siteName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_SITE_FAILOVER_URLS", params);
        if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
            SiteConfiguration.removeSiteSecondaryURLs(adminSSOToken, siteName, secondaryURLs);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-site-secondary-urls-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-site-secondary-urls-no-exists"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_SITE_FAILOVER_URLS", params);
    } catch (SSOException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("RemoveSiteFailoverURLs.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SITE_FAILOVER_URLS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("RemoveSiteFailoverURLs.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SITE_FAILOVER_URLS", 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) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 97 with CLIException

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

the class CreateServer 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 serverName = getStringOptionValue(IArgument.SERVER_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);
    String serverconfigxml = CLIUtil.getFileContent(getCommandManager(), getStringOptionValue(SERVER_CONFIG_XML_FILE));
    String[] params = { serverName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_SERVER", params);
        if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
            ServerConfiguration.createServerInstance(adminSSOToken, serverName, attributeValues, serverconfigxml);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("create-server-config-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("create-server-config-already-exists"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_CREATE_SERVER", params);
    } catch (UnknownPropertyNameException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) SSOToken(com.iplanet.sso.SSOToken) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) Map(java.util.Map)

Example 98 with CLIException

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

the class DeleteServer 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 serverName = getStringOptionValue(IArgument.SERVER_NAME);
    String[] params = { serverName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_SERVER", params);
        if (ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
            ServerConfiguration.deleteServerInstance(adminSSOToken, serverName);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("delete-server-config-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("delete-server-config-dont-exists"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_SERVER", params);
    } catch (SSOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("DeleteServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("DeleteServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SERVER", 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) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 99 with CLIException

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

the class GetServerConfigXML method handleRequest.

/**
     * Returns Server Configuration XML.
     *
     * @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 serverName = getStringOptionValue(IArgument.SERVER_NAME);
    String outfile = getStringOptionValue(IArgument.OUTPUT_FILE);
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serverName };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_SERVER_CONFIG_XML", params);
        String xml = ServerConfiguration.getServerConfigXML(adminSSOToken, serverName);
        if ((xml != null) && (xml.length() > 0)) {
            if ((outfile != null) && (outfile.length() > 0)) {
                CLIUtil.writeToFile(outfile, xml);
            } else {
                outputWriter.printlnMessage(xml);
            }
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("get-serverconfig-xml-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(getResourceString("get-server-config-xml-no-result-no-results"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_SERVER_CONFIG_XML", params);
    } catch (IOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("GetServerConfigXML.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SERVER_CONFIG_XML", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("GetServerConfigXML.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SERVER_CONFIG_XML", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("GetServerConfigXML.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_SERVER_CONFIG_XML", 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) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException)

Example 100 with CLIException

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

the class RemovePrivileges 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);
    List privileges = (List) rc.getOption(IArgument.PRIVILEGES);
    IdType idType = convert2IdType(type);
    String[] params = { realm, type, idName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_REMOVE_PRIVILEGES", params);
        DelegationManager mgr = new DelegationManager(adminSSOToken, realm);
        Set privilegeObjects = mgr.getPrivileges();
        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);
        }
        String uid = amid.getUniversalId();
        for (Iterator i = privileges.iterator(); i.hasNext(); ) {
            String name = (String) i.next();
            DelegationPrivilege dp = getDelegationPrivilege(name, privilegeObjects);
            boolean removed = false;
            if (dp != null) {
                Set subjects = dp.getSubjects();
                if (subjects.contains(uid)) {
                    subjects.remove(uid);
                    mgr.addPrivilege(dp);
                    removed = true;
                }
            }
            if (!removed) {
                String[] args = { idName, name };
                String msg = MessageFormat.format(getResourceString("delegation-does-not-have-privilege"), (Object[]) args);
                throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
            }
        }
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-remove-privileges-succeed"), (Object[]) params));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_REMOVE_PRIVILEGES", params);
    } catch (DelegationException e) {
        String[] args = { realm, type, idName, e.getMessage() };
        debugError("RemovePrivileges.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_REMOVE_PRIVILEGES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, type, idName, e.getMessage() };
        debugError("RemovePrivileges.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_REMOVE_PRIVILEGES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) 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) Iterator(java.util.Iterator) 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