Search in sources :

Example 26 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class BootstrapCreator method getBootStrapURL.

/**
     * Returns the bootstrap url.
     *
     * @param dsCfg instance of the <code>IDSConfigMgr</code> containing
     *              the connection information to the config store.
     * @exception ConfigurationException if there is an error and cannot
     *     obtain the bootstrap URL. This may be due to connection error.
     */
public String getBootStrapURL(IDSConfigMgr dsCfg) throws ConfigurationException {
    String bootstrapStr = null;
    try {
        ServerGroup sg = dsCfg.getServerGroup("sms");
        ServerGroup defaultGroup = dsCfg.getServerGroup("default");
        ServerInstance svrCfg;
        if (sg == null) {
            sg = defaultGroup;
            svrCfg = dsCfg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        } else {
            svrCfg = sg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        }
        ServerInstance userInstance = defaultGroup.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        String dsameUserName = userInstance.getAuthID();
        String dsameUserPwd = JCECrypt.encode(userInstance.getPasswd());
        String connDN = svrCfg.getAuthID();
        String connPwd = JCECrypt.encode(svrCfg.getPasswd());
        String rootSuffix = svrCfg.getBaseDN();
        Collection serverList = sg.getServersList();
        StringBuilder bootstrap = new StringBuilder();
        for (Iterator i = serverList.iterator(); i.hasNext(); ) {
            Server serverObj = (Server) i.next();
            Server.Type connType = serverObj.getConnectionType();
            String proto = (connType.equals(Server.Type.CONN_SIMPLE)) ? "ldap" : "ldaps";
            String url = StringUtils.strReplaceAll(template, "@DS_PROTO@", proto);
            String host = serverObj.getServerName() + ":" + serverObj.getPort();
            url = StringUtils.strReplaceAll(url, "@DS_HOST@", host);
            url = StringUtils.strReplaceAll(url, "@INSTANCE_NAME@", URLEncoder.encode(SystemProperties.getServerInstanceName(), "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@DSAMEUSER_NAME@", URLEncoder.encode(dsameUserName, "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@DSAMEUSER_PWD@", URLEncoder.encode(dsameUserPwd, "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@BASE_DN@", URLEncoder.encode(rootSuffix, "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@BIND_DN@", URLEncoder.encode(connDN, "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@BIND_PWD@", URLEncoder.encode(connPwd, "UTF-8"));
            bootstrap.append(url).append("\n");
        }
        bootstrapStr = bootstrap.toString();
    } catch (IOException e) {
        throw new ConfigurationException(e.getMessage());
    }
    return bootstrapStr;
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) Server(com.iplanet.services.ldap.Server) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) Iterator(java.util.Iterator) Collection(java.util.Collection) IOException(java.io.IOException) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Example 27 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class BootstrapCreator method updateBootstrap.

public static void updateBootstrap() throws ConfigurationException {
    try {
        DSConfigMgrBase dsCfg = new DSConfigMgrBase();
        dsCfg.parseServiceConfigXML();
        instance.update(dsCfg);
    } catch (XMLException e) {
        throw new ConfigurationException(e.getMessage());
    } catch (SMSException e) {
        throw new ConfigurationException(e.getMessage());
    } catch (SSOException e) {
        throw new ConfigurationException(e.getMessage());
    }
}
Also used : XMLException(com.iplanet.services.util.XMLException) DSConfigMgrBase(com.iplanet.services.ldap.DSConfigMgrBase) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 28 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class AgentsModelImpl method createAgentLocal.

/**
     * Creates localized agent.
     *
     * @param realmName Realm where agent resides.
     * @param name Name of agent.
     * @param type Type of agent.
     * @param password Password of agent.
     * @param agentURL Agent URL.
     * @throws AMConsoleException if agent cannot be created.
     */
public void createAgentLocal(String realmName, String name, String type, String password, String agentURL) throws AMConsoleException {
    String[] params = { realmName, name, type };
    try {
        logEvent("ATTEMPT_CREATE_AGENT", params);
        Map map = AgentConfiguration.getDefaultValues(type, false);
        Set set = new HashSet(2);
        map.put(AgentConfiguration.ATTR_NAME_PWD, set);
        set.add(password);
        Set newset = new HashSet(2);
        newset.add(AgentConfiguration.VAL_CONFIG_REPO_LOCAL);
        map.put(AgentConfiguration.ATTR_CONFIG_REPO, newset);
        AgentConfiguration.createAgentLocal(getUserSSOToken(), realmName, name, type, map, agentURL);
        logEvent("SUCCEED_CREATE_AGENT", params);
    } catch (ConfigurationException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.createAgent", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (MalformedURLException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.createAgent", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (SSOException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.createAgent", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (IdRepoException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.createAgent", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (SMSException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.createAgent", e);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 29 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class ImportServer 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 xmlFile = getStringOptionValue(IArgument.XML_FILE);
    String[] params = { serverName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IMPORT_SERVER", params);
        if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
            ServerConfiguration.importServerInstance(adminSSOToken, serverName, xmlFile);
            outputWriter.printlnMessage(getResourceString("import-server-succeeded"));
        } else {
            outputWriter.printlnMessage(getResourceString("import-server-already-exists"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IMPORT_SERVER", params);
    } catch (ConfigurationException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ParserConfigurationException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SAXException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_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_IMPORT_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_IMPORT_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_IMPORT_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) 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) SSOException(com.iplanet.sso.SSOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 30 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class UpdateServerConfig 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);
    encryptPasswordAttributes(attributeValues);
    String[] params = { serverName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_SERVER_CONFIG", params);
        if (serverName.equals(DEFAULT_SVR_CONFIG)) {
            try {
                ServerConfiguration.setServerInstance(adminSSOToken, ServerConfiguration.DEFAULT_SERVER_CONFIG, attributeValues);
            } catch (UnknownPropertyNameException ex) {
                outputWriter.printlnMessage(ex.getL10NMessage(getCommandManager().getLocale()));
                outputWriter.printlnMessage("");
            }
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("update-server-config-succeeded"), (Object[]) params));
        } else {
            if (ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
                try {
                    ServerConfiguration.setServerInstance(adminSSOToken, serverName, attributeValues);
                } catch (UnknownPropertyNameException ex) {
                    outputWriter.printlnMessage(getResourceString("update-server-config-unknown"));
                    outputWriter.printlnMessage("");
                }
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("update-server-config-succeeded"), (Object[]) params));
            } else {
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("update-server-config-does-not-exists"), (Object[]) params));
            }
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UPDATE_SERVER_CONFIG", params);
    } catch (ConfigurationException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("UpdateServerConfig.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_SERVER_CONFIG", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("UpdateServerConfig.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_SERVER_CONFIG", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("UpdateServerConfig.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_SERVER_CONFIG", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("UpdateServerConfig.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_SERVER_CONFIG", 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)

Aggregations

ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)48 SSOException (com.iplanet.sso.SSOException)40 SMSException (com.sun.identity.sm.SMSException)39 SSOToken (com.iplanet.sso.SSOToken)30 CLIException (com.sun.identity.cli.CLIException)19 IOutput (com.sun.identity.cli.IOutput)17 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)14 List (java.util.List)12 IdRepoException (com.sun.identity.idm.IdRepoException)11 IOException (java.io.IOException)11 Map (java.util.Map)10 Set (java.util.Set)9 UnknownPropertyNameException (com.sun.identity.common.configuration.UnknownPropertyNameException)6 HashSet (java.util.HashSet)6 Iterator (java.util.Iterator)6 NotFoundException (org.forgerock.json.resource.NotFoundException)6 AMIdentity (com.sun.identity.idm.AMIdentity)5 MalformedURLException (java.net.MalformedURLException)5 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)5 HashMap (java.util.HashMap)4