Search in sources :

Example 1 with LocalizedMessage

use of com.sun.identity.install.tools.util.LocalizedMessage in project OpenAM by OpenRock.

the class UserDataInteraction method interactSilent.

/*
     * Method to interact with the user for silent attrs
     * 
     */
public InteractionResult interactSilent(IStateAccess state, Map map) throws InstallException {
    InteractionResult interResult = null;
    InteractionResultStatus result = null;
    boolean isReq = getInteractionInfo().getRequiredFlag();
    // Pre-process user input from silent state file
    String procInput = preProcessSilentInput(map);
    if ((!isReq) && (procInput.equals(STR_IN_EMPTY_STRING))) {
        result = InteractionResultStatus.STATUS_CONTINUE;
        state.put(getKey(), getNormalizedValue(procInput));
    } else {
        CumulativeValResult cumRes = processValidators(procInput, state, false);
        if (cumRes.getCumValResult()) {
            if (cumRes.getWarningMessage() != null) {
                Console.println();
                Console.println(LocalizedMessage.get(LOC_VA_WRN_VAL_MESSAGE) + getSummaryDescription().toString());
                Console.println(LocalizedMessage.get(LOC_VA_WRN_VAL_INSTALL_LOG));
            }
            result = InteractionResultStatus.STATUS_CONTINUE;
            state.put(getKey(), getNormalizedValue(procInput));
            if (cumRes.getCalcKeyValPairs() != null) {
                state.putData(cumRes.getCalcKeyValPairs());
            }
        } else {
            Debug.log("Interaction failed to continue since one or" + " more of the validators failed.");
            throw new InstallException(getError());
        }
    }
    LocalizedMessage summaryDesc = null;
    if ((result != null) && (result.getIntValue() == InteractionResultStatus.INT_STATUS_CONTINUE)) {
        summaryDesc = LocalizedMessage.get(LOC_IN_MESS_SUMMARY_DESC_FORMAT, new Object[] { getSummaryDesc(), procInput });
        interResult = new InteractionResult(result, null, summaryDesc);
    }
    return interResult;
}
Also used : LocalizedMessage(com.sun.identity.install.tools.util.LocalizedMessage)

Example 2 with LocalizedMessage

use of com.sun.identity.install.tools.util.LocalizedMessage in project OpenAM by OpenRock.

the class UserResponseHandler method getInvalidKeyErrorMessage.

public LocalizedMessage getInvalidKeyErrorMessage(int lineNumber) {
    Object[] args = { getFile(), new Integer(lineNumber), STR_KEY_VALUE_SEP };
    LocalizedMessage message = LocalizedMessage.get(LOC_DR_ERR_INVALID_KEY_DEFINED, args);
    return message;
}
Also used : LocalizedMessage(com.sun.identity.install.tools.util.LocalizedMessage)

Example 3 with LocalizedMessage

use of com.sun.identity.install.tools.util.LocalizedMessage in project OpenAM by OpenRock.

the class PasswordValidator method isAgentAdminLoginValid.

/*
     * validate Agent Administrator's name and password.
     */
private ValidationResult isAgentAdminLoginValid(String passfileName, Map props, IStateAccess state) throws InstallException {
    ValidationResultStatus validRes = ValidationResultStatus.STATUS_FAILED;
    LocalizedMessage returnMessage = null;
    String agentUserName = null;
    String serverURL = null;
    String restAuthURL = null;
    String agentUserNameKey = (String) props.get(STR_AGENT_PROFILE_LOOKUP_KEY);
    if (agentUserNameKey != null) {
        agentUserName = (String) state.get(agentUserNameKey);
    }
    Map tokens = state.getData();
    if (tokens.containsKey("AM_SERVER_URL")) {
        serverURL = (String) tokens.get("AM_SERVER_URL");
    }
    String agentUserPasswd = readDataFromFile(passfileName);
    try {
        restAuthURL = serverURL + "/identity/authenticate";
        String encodingType = "UTF-8";
        String encodedPostData = "username=" + URLEncoder.encode(agentUserName, encodingType) + "&password=" + URLEncoder.encode(agentUserPasswd, encodingType) + "&uri=" + URLEncoder.encode("realm=/&module=Application", encodingType);
        RESTUtils.RESTResponse response = RESTUtils.callServiceURL(restAuthURL, encodedPostData);
        // Read response code
        int responseCode = response.getResponseCode();
        if (responseCode == HTTP_RESPONSE_OK) {
            validRes = ValidationResultStatus.STATUS_SUCCESS;
            setCreateAgentProfile(state, "true");
        } else if (responseCode == HTTP_RESPONSE_AUTHENTICATION_FAILED) {
            String responseStr = response.toString();
            if (responseStr.indexOf(STR_IDENTITY_INVALID_PASSWORD) > 0) {
                // wrong password
                returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_AGENT_PASSWORD, new Object[] { agentUserName });
            } else if (responseStr.indexOf(STR_IDENTITY_INVALID_CREDENTIALS) > 0) {
                // user does not exist.
                returnMessage = LocalizedMessage.get(LOC_VA_ERR_IN_VAL_AGENT_PROFILE_NOT_PRESENT, new Object[] { agentUserName });
            } else {
                Debug.log("PasswordValidator.isAgentAdminLoginValid() - " + "Error from OpenSSO:" + response.toString());
                returnMessage = LocalizedMessage.get(LOC_VA_ERR_IN_VAL_OTHER_AGENT_AUTH_FAILURE, new Object[] { Integer.valueOf(responseCode) });
            }
        } else {
            Debug.log("PasswordValidator.isAgentAdminLoginValid() - " + "Error from OpenSSO:" + response.toString());
            returnMessage = LocalizedMessage.get(LOC_VA_ERR_IN_VAL_AGENT_GENERIC_FAILURE, new Object[] { Integer.valueOf(responseCode) });
        }
    } catch (UnknownHostException uhe) {
        Debug.log("PasswordValidator.isAgentAdminLoginValid() " + "threw exception :", uhe);
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_FAM_SERVER_URL, new Object[] { restAuthURL });
    } catch (ConnectException ce) {
        Debug.log("PasswordValidator.isAgentAdminLoginValid() " + "threw exception :", ce);
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_FAM_SERVER_URL, new Object[] { restAuthURL });
    } catch (FileNotFoundException ex) {
        Debug.log("PasswordValidator.isAgentAdminLoginValid() " + "threw exception :", ex);
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_NOT_FOUND_SERVER_URL, new Object[] { restAuthURL });
    } catch (IOException ex) {
        Debug.log("PasswordValidator.isAgentAdminLoginValid() " + "threw exception :", ex);
    }
    return new ValidationResult(validRes, null, returnMessage);
}
Also used : RESTUtils(com.sun.identity.install.tools.util.RESTUtils) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) LocalizedMessage(com.sun.identity.install.tools.util.LocalizedMessage) ConnectException(java.net.ConnectException)

Example 4 with LocalizedMessage

use of com.sun.identity.install.tools.util.LocalizedMessage in project OpenAM by OpenRock.

the class PasswordValidator method isAgentLoginValid.

/*
     * Checks if Agent profile/User's name&password is valid.
     *
     * @param port @param props @param state
     *
     * @return ValidationResult
     */
public ValidationResult isAgentLoginValid(String passfileName, Map props, IStateAccess state) throws InstallException {
    ValidationResultStatus validRes = ValidationResultStatus.STATUS_FAILED;
    LocalizedMessage returnMessage = null;
    String agentUserName = null;
    String serverURL = null;
    String restAuthURL = null;
    String str = null;
    String serverURLValid = (String) state.get("isServerURLValid");
    String createAgentProfileKey = (String) state.get(InstallConstants.STR_CREATE_AGENT_PROFILE_KEY);
    if (createAgentProfileKey == null) {
        setCreateAgentProfile(state, "false");
    }
    if (serverURLValid != null && serverURLValid.equals("true")) {
        if (isAgentAdmin(props, state)) {
            return isAgentAdminLoginValid(passfileName, props, state);
        }
        String agentUserNameKey = (String) props.get(STR_AGENT_PROFILE_LOOKUP_KEY);
        if (agentUserNameKey != null) {
            agentUserName = (String) state.get(agentUserNameKey);
        }
        Map tokens = state.getData();
        if (tokens.containsKey("AM_SERVER_URL")) {
            serverURL = (String) tokens.get("AM_SERVER_URL");
        }
        String agentUserPasswd = readDataFromFile(passfileName);
        try {
            restAuthURL = serverURL + "/identity/authenticate";
            String encodingType = "UTF-8";
            String encodedPostData = "username=" + URLEncoder.encode(agentUserName, encodingType) + "&password=" + URLEncoder.encode(agentUserPasswd, encodingType) + "&uri=" + URLEncoder.encode("realm=/&module=Application", encodingType);
            RESTUtils.RESTResponse response = RESTUtils.callServiceURL(restAuthURL, encodedPostData);
            // Read response code
            int responseCode = response.getResponseCode();
            if (responseCode == HTTP_RESPONSE_OK) {
                validRes = ValidationResultStatus.STATUS_SUCCESS;
                setCreateAgentProfile(state, "false");
            } else if (responseCode == HTTP_RESPONSE_AUTHENTICATION_FAILED) {
                String responseStr = response.toString();
                if (responseStr.indexOf(STR_IDENTITY_INVALID_PASSWORD) > 0) {
                    // wrong password
                    returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_AGENT_PASSWORD, new Object[] { agentUserName });
                } else if (responseStr.indexOf(STR_IDENTITY_INVALID_CREDENTIALS) > 0) {
                    // create agent profile only when agent profile 
                    // does not exist.
                    setCreateAgentProfile(state, "true");
                    returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_AGENT_PROFILE_NOT_PRESENT, new Object[] { agentUserName });
                    validRes = ValidationResultStatus.STATUS_WARNING;
                } else {
                    Debug.log("PasswordValidator.isAgentLoginValid() - " + "Error from OpenSSO:" + response.toString());
                    returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_OTHER_AGENT_AUTH_FAILURE, new Object[] { Integer.valueOf(responseCode) });
                    validRes = ValidationResultStatus.STATUS_WARNING;
                }
            } else {
                Debug.log("PasswordValidator.isAgentLoginValid() - " + "Error from OpenSSO:" + response.toString());
                returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_AGENT_GENERIC_FAILURE, new Object[] { Integer.valueOf(responseCode) });
                validRes = ValidationResultStatus.STATUS_WARNING;
            }
        } catch (UnknownHostException uhe) {
            Debug.log("PasswordValidator.isAgentLoginValid() " + "threw exception :", uhe);
            returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_FAM_SERVER_URL, new Object[] { restAuthURL });
            validRes = ValidationResultStatus.STATUS_WARNING;
        } catch (ConnectException ce) {
            Debug.log("PasswordValidator.isAgentLoginValid() " + "threw exception :", ce);
            returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_FAM_SERVER_URL, new Object[] { restAuthURL });
            validRes = ValidationResultStatus.STATUS_WARNING;
        } catch (FileNotFoundException ex) {
            Debug.log("PasswordValidator.isAgentLoginValid() " + "threw exception :", ex);
            returnMessage = LocalizedMessage.get(LOC_VA_WRN_NOT_FOUND_SERVER_URL, new Object[] { restAuthURL });
            validRes = ValidationResultStatus.STATUS_WARNING;
        } catch (IOException ex) {
            Debug.log("PasswordValidator.isAgentLoginValid() " + "threw exception :", ex);
        }
        return new ValidationResult(validRes, null, returnMessage);
    } else {
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_SERVER_URL_NOT_RUNNING, new Object[] { serverURL });
        validRes = ValidationResultStatus.STATUS_WARNING;
        return new ValidationResult(validRes, null, returnMessage);
    }
}
Also used : RESTUtils(com.sun.identity.install.tools.util.RESTUtils) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) LocalizedMessage(com.sun.identity.install.tools.util.LocalizedMessage) ConnectException(java.net.ConnectException)

Example 5 with LocalizedMessage

use of com.sun.identity.install.tools.util.LocalizedMessage in project OpenAM by OpenRock.

the class StringValidator method isKeyValid.

public ValidationResult isKeyValid(String key, Map props, IStateAccess state) {
    ValidationResultStatus validRes = ValidationResultStatus.STATUS_FAILED;
    LocalizedMessage returnMessage = null;
    try {
        if ((key != null) && (key.length() > 0)) {
            String minSize = (String) props.get(STR_VAL_MIN_DIGITS);
            if ((minSize != null) && (minSize.length() > 0)) {
                int minLen = Integer.parseInt(minSize);
                Debug.log("StringValidator : key min length = " + minLen);
                int passLen = key.length();
                if (passLen >= minLen) {
                    validRes = ValidationResultStatus.STATUS_SUCCESS;
                } else {
                    Debug.log("StringValidator : Length of key is " + "invalid");
                }
            } else {
                // User did not enter a min length
                validRes = ValidationResultStatus.STATUS_SUCCESS;
            }
        }
    } catch (Exception ex) {
        Debug.log("StringValidator : Failed to read key with ex :", ex);
    }
    if (validRes.getIntValue() == ValidationResultStatus.INT_STATUS_FAILED) {
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_KEY);
    } else {
        Debug.log("StringValidator : key is valid");
        returnMessage = LocalizedMessage.get(LOC_VA_MSG_VAL_KEY);
    }
    Debug.log("StringValidator : Is Key valid ? " + validRes.isSuccessful());
    return new ValidationResult(validRes, null, returnMessage);
}
Also used : LocalizedMessage(com.sun.identity.install.tools.util.LocalizedMessage)

Aggregations

LocalizedMessage (com.sun.identity.install.tools.util.LocalizedMessage)73 Map (java.util.Map)9 File (java.io.File)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 ConnectException (java.net.ConnectException)4 UnknownHostException (java.net.UnknownHostException)4 StringTokenizer (java.util.StringTokenizer)4 FileNotFoundException (java.io.FileNotFoundException)3 RESTUtils (com.sun.identity.install.tools.util.RESTUtils)2 BufferedReader (java.io.BufferedReader)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 TreeMap (java.util.TreeMap)2 Audit (com.sun.identity.install.tools.util.Audit)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1