Search in sources :

Example 21 with ConfigurationException

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

the class Step3 method validateHostName.

/*
     * a call is made to the OpenAM url entered in the browser. If
     * the OpenAM server
     * exists a <code>Map</code> of data will be returned which contains the
     * information about the existing servers data store, including any 
     * replication ports if its embedded.
     * Information to control the UI is returned in a JSON object of the form
     * { 
     *   "param1" : "value1", 
     *   "param2" : "value2"
     * }
     * The JS on the browser will interpret the above and make the necessary
     * changes to prompt the user for any more details required.
     */
public boolean validateHostName() {
    StringBuffer sb = new StringBuffer();
    String hostName = toString("hostName");
    if (hostName == null) {
        addObject(sb, "code", "100");
        addObject(sb, "message", getLocalizedString("missing.required.field"));
    } else {
        // try to retrieve the remote OpenAM information
        String admin = "amadmin";
        String password = (String) getContext().getSessionAttribute(SessionAttributeNames.CONFIG_VAR_ADMIN_PWD);
        try {
            String dsType;
            Map data = AMSetupUtils.getRemoteServerInfo(hostName, admin, password);
            // data returned from existing OpenAM server
            if (data != null && !data.isEmpty()) {
                addObject(sb, "code", "100");
                addObject(sb, "message", getLocalizedString("ok.string"));
                setupDSParams(data);
                String key = (String) data.get("enckey");
                getContext().setSessionAttribute(SessionAttributeNames.ENCRYPTION_KEY, key);
                getContext().setSessionAttribute(SessionAttributeNames.ENCLDAPUSERPASSWD, (String) data.get("ENCLDAPUSERPASSWD"));
                // true for embedded, false for ODSEE
                String embedded = (String) data.get(BootstrapData.DS_ISEMBEDDED);
                addObject(sb, "embedded", embedded);
                String host = (String) data.get(BootstrapData.DS_HOST);
                if (embedded.equals("true")) {
                    getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_HOST, getHostName());
                    addObject(sb, "configStoreHost", getHostName());
                    // set the multi embedded flag 
                    getContext().setSessionAttribute(SessionAttributeNames.CONFIG_VAR_DATA_STORE, SetupConstants.SMS_EMBED_DATASTORE);
                    getContext().setSessionAttribute(SessionAttributeNames.DS_EMB_REPL_FLAG, SetupConstants.DS_EMP_REPL_FLAG_VAL);
                    // get the existing replication ports if any
                    String replAvailable = (String) data.get(BootstrapData.DS_REPLICATIONPORT_AVAILABLE);
                    if (replAvailable == null) {
                        replAvailable = "false";
                    }
                    addObject(sb, "replication", replAvailable);
                    String existingRep = (String) data.get(BootstrapData.DS_REPLICATIONPORT);
                    getContext().setSessionAttribute(SessionAttributeNames.EXISTING_REPL_PORT, existingRep);
                    addObject(sb, "replicationPort", existingRep);
                    String existingServerid = (String) data.get("existingserverid");
                    getContext().setSessionAttribute(SessionAttributeNames.EXISTING_SERVER_ID, existingServerid);
                    addObject(sb, "existingserverid", existingServerid);
                    // dsmgr password is same as amadmin for embedded
                    getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_PWD, password);
                } else {
                    getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_PORT, (String) data.get(BootstrapData.DS_PORT));
                    getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_HOST, host);
                    addObject(sb, "configStoreHost", host);
                    String dsprot = (String) data.get(BootstrapData.DS_PROTOCOL);
                    String dsSSL = ("ldaps".equals(dsprot)) ? "SSL" : "SIMPLE";
                    getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_SSL, dsSSL);
                    addObject(sb, "configStoreSSL", dsSSL);
                    String dspwd = (String) data.get(BootstrapData.DS_PWD);
                    getContext().setSessionAttribute(SessionAttributeNames.CONFIG_STORE_PWD, Crypt.decode(dspwd, Crypt.getHardcodedKeyEncryptor()));
                }
                // set the replication ports pulled from the remote
                // server in the session and pass back to the client
                String existing = (String) data.get(SetupConstants.DS_EMB_REPL_ADMINPORT2);
                getContext().setSessionAttribute(SessionAttributeNames.EXISTING_PORT, existing);
                addObject(sb, "existingPort", existing);
                // set the configuration store port
                String ds_existingStorePort = (String) data.get(BootstrapData.DS_PORT);
                getContext().setSessionAttribute(SessionAttributeNames.EXISTING_STORE_PORT, ds_existingStorePort);
                addObject(sb, "existingStorePort", ds_existingStorePort);
                getContext().setSessionAttribute(SessionAttributeNames.EXISTING_HOST, host);
                // set the configuration store host
                getContext().setSessionAttribute(SessionAttributeNames.EXISTING_STORE_HOST, host);
                addObject(sb, "existingStoreHost", host);
                // set the configuration store port
                getContext().setSessionAttribute(SessionAttributeNames.LOCAL_REPL_PORT, localRepPort);
            }
        } catch (ConfigurationException c) {
            String code = c.getErrorCode();
            String message = getLocalizedString(code);
            if (code == null) {
                code = "999";
                message = c.getMessage();
            }
            addObject(sb, "code", code);
            addObject(sb, "message", message);
        } catch (ConfiguratorException c) {
            String code = c.getErrorCode();
            String message = getLocalizedString(code);
            if (code == null) {
                code = "999";
                message = c.getMessage();
            }
            addObject(sb, "code", code);
            addObject(sb, "message", message);
        }
    }
    sb.append(" }");
    writeToResponse(sb.toString());
    setPath(null);
    return false;
}
Also used : ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) ConfiguratorException(com.sun.identity.setup.ConfiguratorException) Map(java.util.Map)

Example 22 with ConfigurationException

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

the class AgentsModelImpl method createAgentGroup.

/**
     * Creates agent group.
     *
     * @param realmName Realm where agent group resides.
     * @param name Name of agent group.
     * @param type Type of agent group.
     * @throws AMConsoleException if agent group cannot be created.
     */
public void createAgentGroup(String realmName, String name, String type) throws AMConsoleException {
    String[] params = { realmName, name, type };
    try {
        logEvent("ATTEMPT_CREATE_AGENT_GROUP", params);
        AgentConfiguration.createAgentGroup(getUserSSOToken(), realmName, name, type, AgentConfiguration.getDefaultValues(type, true));
        logEvent("SUCCEED_CREATE_AGENT_GROUP", params);
    } catch (ConfigurationException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT_GROUP", paramsEx);
        debug.warning("AgentsModelImpl.createAgentGroup", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (SSOException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT_GROUP", paramsEx);
        debug.warning("AgentsModelImpl.createAgentGroup", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (IdRepoException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT_GROUP", paramsEx);
        debug.warning("AgentsModelImpl.createAgentGroup", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (SMSException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT_GROUP", paramsEx);
        debug.warning("AgentsModelImpl.createAgentGroup", e);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : 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)

Example 23 with ConfigurationException

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

the class AMSetupFilter method doFilter.

/**
     * Redirects requests to configuration page if the product is not yet configured.
     *
     * @param req The HTTP request.
     * @param resp The HTTP response.
     * @param filterChain The filter chain.
     * @throws IOException If configuration file cannot be read.
     * @throws ServletException If there are errors in the servlet space.
     */
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;
    try {
        if (setupManager.isCurrentConfigurationValid()) {
            if (isSetupRequest(request.getRequestURI())) {
                response.sendRedirect(createCleanUrl(request));
            } else {
                filterChain.doFilter(request, response);
            }
        } else {
            if (isConfigStoreDown()) {
                String redirectUrl = System.getProperty(Constants.CONFIG_STORE_DOWN_REDIRECT_URL);
                if (StringUtils.isNotEmpty(redirectUrl)) {
                    response.sendRedirect(redirectUrl);
                } else {
                    throw new ConfigurationException(CONFIG_STORE_DOWN_ERROR_CODE, null);
                }
            } else {
                if (isPassthrough && isRequestForAllowedResource(resourcePath(request))) {
                    filterChain.doFilter(request, response);
                } else if (isConfiguratorRequest(request.getRequestURI())) {
                    filterChain.doFilter(request, response);
                } else {
                    String url = createCleanUrl(request);
                    if (hasWritePermissionOnUserHomeDirectory()) {
                        url += SETUP_URI;
                    } else {
                        url += NOWRITE_PERMISSION;
                    }
                    response.sendRedirect(url);
                    enablePassthrough();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new ServletException("AMSetupFilter.doFilter", e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException)

Example 24 with ConfigurationException

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

the class AMSetupUtils method getRemoteServerInfo.

/**
     * Obtains misc config data from a remote OpenAM server:
     * <ul>
     *     <li>OpendDJ admin port</li>
     *     <li>config basedn</li>
     *     <li>replication ready flag</li>
     *     <li>OpenDJ replication port or OpenDJ suggested port</li>
     * </ul>
     *
     * @param serverUrl URL string representing the remote OpenAM server.
     * @param userId The admin user id on remote server, (only amadmin).
     * @param password The admin password.
     * @return A {@code Map} of config parameters.
     * @throws ConfigurationException for the following error code:
     * <ul>
     *     <li>400=Bad Request - user id/password param missing</li>
     *     <li>401=Unauthorized - invalid credentials</li>
     *     <li>405=Method Not Allowed - only POST is honored</li>
     *     <li>408=Request Timeout - requested timed out</li>
     *     <li>500=Internal Server Error</li>
     *     <li>701=File Not Found - incorrect deploy/server uri</li>
     *     <li>702=Connection Error - failed to connect</li>
     * </ul>
     */
public static Map<String, String> getRemoteServerInfo(String serverUrl, String userId, String password) throws ConfigurationException {
    HttpURLConnection connection = null;
    try {
        connection = openConnection(serverUrl + "/getServerInfo.jsp");
        writeToConnection(connection, "IDToken1=" + URLEncoder.encode(userId, "UTF-8") + "&IDToken2=" + URLEncoder.encode(password, "UTF-8"));
        // Remove any additional /n's from the result, often seen at the beginning of the response.
        return BootstrapData.queryStringToMap(readFromConnection(connection).replace("\n", ""));
    } catch (IllegalArgumentException e) {
        debug.warning("AMSetupUtils.getRemoteServerInfo()", e);
        throw newConfigurationException("702");
    } catch (IOException e) {
        debug.warning("AMSetupUtils.getRemoteServerInfo()", e);
        if (e instanceof FileNotFoundException) {
            throw newConfigurationException("701");
        } else if (e instanceof SSLHandshakeException || e instanceof MalformedURLException || e instanceof UnknownHostException || e instanceof ConnectException) {
            throw newConfigurationException("702");
        } else {
            int status = 0;
            if (connection != null) {
                try {
                    status = connection.getResponseCode();
                } catch (Exception ignored) {
                }
            }
            if (status == 400 || status == 401 || status == 405 || status == 408) {
                throw newConfigurationException(String.valueOf(status));
            } else {
                throw new ConfiguratorException(e.getMessage());
            }
        }
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) ConnectException(java.net.ConnectException)

Example 25 with ConfigurationException

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

the class BootstrapCreator method update.

private void update(IDSConfigMgr dsCfg) throws ConfigurationException {
    try {
        String bootstrapString = getBootStrapURL(dsCfg);
        String baseDir = SystemProperties.get(SystemProperties.CONFIG_PATH);
        String file = baseDir + "/" + BootstrapData.BOOTSTRAP;
        File f = new File(file);
        boolean exist = f.exists();
        boolean writable = exist && f.canWrite();
        // make bootstrap writable if it is not
        if (exist && !writable) {
            f.setWritable(true);
            Thread.sleep(3000);
        }
        writeToFile(file, bootstrapString);
        // set permission to 400
        if (!exist) {
            if (isUnix) {
                Runtime.getRuntime().exec("/bin/chmod 400 " + file);
            }
        } else {
            // make it not writable if it was previously not writable.
            if (!writable) {
                f.setWritable(false);
            }
        }
    } catch (InterruptedException e) {
        throw new ConfigurationException(e.getMessage());
    } catch (IOException e) {
        throw new ConfigurationException(e.getMessage());
    }
}
Also used : ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) IOException(java.io.IOException) File(java.io.File) IOUtils.writeToFile(org.forgerock.openam.utils.IOUtils.writeToFile)

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