Skip to content

Request - getParameter() bug? #1

@vrodriguezTecsisa

Description

@vrodriguezTecsisa

Hi!
I'm using your Oauth2Server and I have stumbled with a 500 bug while running the Token fetching, specifically in RequestParameter.java , method fetch, when it says:

    Map<String, String> params = new HashMap<String, String>();
    Map<String, String> parameterMap = request.getParameterMap();
    params.putAll(parameterMap);
    String token = request.getParameter("access_token")

The call to request.getParameterMap() is defined in the Request implementation HttpServletRequestAdapter, like this:

@SuppressWarnings("unchecked")
@Override
public Map<String, String> getParameterMap() {
    return request.getParameterMap();
}

where request is a HttpServletRequest variable.
This is worng because the HttpServletRequest method getParameter returns a Map<String,String[]> instead of a Map<String,String> to admit multiple parameters values.

Since we are are only interested on single parameters values in this program (there can only be one access token value), I have fixed the bug changing this function :

@SuppressWarnings("unchecked")
@Override
public Map<String, String> getParameterMap() {
    Map<String,String[]> allParametersValuesMap = request.getParameterMap();
    Map<String,String> firstParameterValueMap = new HashMap<String,String>();

    for (String key: allParametersValuesMap.keySet()) {
        firstParameterValueMap.put(key,( (String []) allParametersValuesMap.get(key))[0]);
    }

    return firstParameterValueMap;
}

Hope this helps, sorry for my english :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions