org.openid4java.message.Parameter Java Examples

The following examples show how to use org.openid4java.message.Parameter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AxPayload.java    From openid4java with Apache License 2.0 6 votes vote down vote up
protected boolean isValid()
{
    Iterator it = _parameters.getParameters().iterator();
    while (it.hasNext())
    {
        String paramName = ((Parameter) it.next()).getKey();

        if (! paramName.equals("mode") &&
                ! paramName.startsWith("type.") &&
                ! paramName.startsWith("count.") &&
                ! paramName.startsWith("value.") &&
                ! paramName.equals("update_url"))
        {
            _log.warn("Invalid parameter name in AX payload: " + paramName);
            //return false;
        }
    }

    return checkAttributes();
}
 
Example #2
Source File: SRegRequest.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
     * Checks the validity of the extension.
     * <p>
     * Used when constructing a extension from a parameter list.
     *
     * @return      True if the extension is valid, false otherwise.
     */
    public boolean isValid()
    {
        if ( ! _parameters.hasParameter("required") &&
                ! _parameters.hasParameter("optional") )
        {
            _log.warn("One of 'required' or 'optional' parameters must be present.");
            return false;
        }

        Iterator it = _parameters.getParameters().iterator();
        while (it.hasNext())
        {
            String paramName = ((Parameter) it.next()).getKey();
            if (! paramName.equals("required") &&
                    ! paramName.equals("optional") &&
                    ! paramName.equals("policy_url"))
            {
                _log.warn("Invalid parameter name in SReg request: " + paramName);
//                return false;
            }
        }

        return true;
    }
 
Example #3
Source File: SRegRequest.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a map with the requested attributes.
 *
 * @param       required    If set to true the list of 'required' attributes
 *                          is returned, otherwise the list of 'optional'
 *                          attributes.
 * @return      List of attribute names.
 */
public List getAttributes(boolean required)
{
    List attributes = new ArrayList();

    String level = required ? "required" : "optional";

    Parameter param = _parameters.getParameter(level);
    if (param != null)
    {
        String[] values = param.getValue().split(",");
        for (int i = 0; i < values.length; i++)
        {
            String attr = multivalDecode(values[i]);
            attributes.add(attr);
        }
    }

    return attributes;
}
 
Example #4
Source File: FetchResponse.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the optional 'update_url' parameter where the OP can later re-post
 * fetch-response updates for the values of the requested attributes.
 *
 * @param       updateUrl   The URL where the RP accepts later updates
 *                          for the requested attributes.
 */
public void setUpdateUrl(String updateUrl) throws MessageException
{
    try
    {
        new URL(updateUrl);
    }
    catch (MalformedURLException e)
    {
        throw new MessageException("Invalid update_url: " + updateUrl);
    }

    if (DEBUG) _log.debug("Setting fetch response update_url: " + updateUrl);

    _parameters.set(new Parameter("update_url", updateUrl));
}
 
Example #5
Source File: SRegResponse.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the validity of the extension.
 * <p>
 * Used when constructing a extension from a parameter list.
 *
 * @return      True if the extension is valid, false otherwise.
 */
private boolean isValid()
{
    Iterator it = _parameters.getParameters().iterator();
    while (it.hasNext())
    {
        String paramName = ((Parameter) it.next()).getKey();

        if (! SREG_FIELDS.contains(paramName))
        {
            _log.warn("Invalid parameter name in SReg response: " + paramName);
            return false;
        }
    }

    return true;
}
 
Example #6
Source File: PapeRequest.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the validity of the extension.
 * <p>
 * Used when constructing a extension from a parameter list.
 *
 * @throws MessageException if the PapeRequest is not valid.
 */
public void validate() throws MessageException
{
    if (! _parameters.hasParameter("preferred_auth_policies"))
    {
        throw new MessageException(
            "preferred_auth_policies is required in a PAPE request.",
            OpenIDException.PAPE_ERROR);
    }

    Iterator it = _parameters.getParameters().iterator();
    while (it.hasNext())
    {
        String paramName = ((Parameter) it.next()).getKey();
        if (! PAPE_FIELDS.contains(paramName) && ! paramName.startsWith(PapeMessage.AUTH_LEVEL_NS_PREFIX))
        {
            throw new MessageException(
                "Invalid parameter name in PAPE request: " + paramName,
                OpenIDException.PAPE_ERROR);
        }
    }
}
 
Example #7
Source File: ConsumerManagerTest.java    From openid4java with Apache License 2.0 6 votes vote down vote up
public MockOpenIDServer(int port) {
	super(port);
	this.port = port;
	setHandler(new AbstractHandler() {				
		public void handle(String target, HttpServletRequest request,
				HttpServletResponse response, int dispatch)
				throws IOException, ServletException {
			MockOpenIDServer.this.requestParams.add(request.getParameterMap());
			
			ParameterList params = new ParameterList();
			params.set(new Parameter("ns",AssociationResponse.OPENID2_NS));
			params.set(new Parameter("assoc_handle",String.valueOf(System.nanoTime())));
			params.set(new Parameter("assoc_type",request.getParameter("openid.assoc_type")));
			params.set(new Parameter("session_type",request.getParameter("openid.session_type")));			
			params.set(new Parameter("expires_in","1799"));
			params.set(new Parameter("dh_server_public","eRm/Qn9lXQJc30ZQLtNFkrjQHuQCLyQ2fRNwLZTGVP50Lhx16EjksA6N0RvXzoJgY8/FdKioOYXKeWVvstHTUReXfF5EC9cnTVOFtTrMegJXHZIHdk+IITwsfGfTlVxMOc7DdCFOOMRWMOA9sYB5n5OoxnzYCob3vo39+Xytlcs="));
			params.set(new Parameter("enc_mac_key","CY08gTx1u4XravtWT3V5Er4sG+o="));
			response.getWriter().write(params.toString());
            ((Request) request).setHandled(true);	            
		}
	});
}
 
Example #8
Source File: AxPayload.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a map with attribute aliases -> attribute type URI.
 */
public Map getAttributeTypes()
{
    Map typeUris = new HashMap();

    Iterator it = _parameters.getParameters().iterator();
    while (it.hasNext())
    {
        Parameter param = (Parameter) it.next();
        String paramName = param.getKey();
        String paramType = param.getValue();

        if (paramName.startsWith("type."))
        {
            String alias = paramName.substring(5);

            if ( ! typeUris.containsKey(alias) )
                typeUris.put(alias, paramType);
        }
    }

    return typeUris;
}
 
Example #9
Source File: AxPayload.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a map with attribute aliases -> list of values.
 */
public Map getAttributes()
{
    Map attributes = new HashMap();

    Iterator it = _parameters.getParameters().iterator();
    while (it.hasNext())
    {
        String paramName = ((Parameter) it.next()).getKey();

        if (paramName.startsWith("type."))
        {
            String alias = paramName.substring(5);

            if ( ! attributes.containsKey(alias) )
                attributes.put(alias, getAttributeValues(alias));
        }
    }

    return attributes;
}
 
Example #10
Source File: AxPayload.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of attribute aliases.
 */
public List getAttributeAliases()
{
    List aliases = new ArrayList();

    Iterator it = _parameters.getParameters().iterator();
    while (it.hasNext())
    {
        String paramName = ((Parameter) it.next()).getKey();

        if (paramName.startsWith("type."))
        {
            String alias = paramName.substring(5);

            if ( ! aliases.contains(alias) )
                aliases.add(alias);
        }
    }

    return aliases;
}
 
Example #11
Source File: OpenIDAdminClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param openid
 * @return
 * @throws IdentityProviderException
 */
public OpenIDUserProfileDTO[] getUserProfiles(String openid, ParameterList requredClaims)
        throws IdentityProviderException {
    OpenIDParameterDTO[] params = null;
    List list = null;
    list = requredClaims.getParameters();
    params = new OpenIDParameterDTO[list.size()];
    int i = 0;
    for (Object object : list) {
        Parameter param = (Parameter) object;
        OpenIDParameterDTO openIDParameterDTO = new OpenIDParameterDTO();
        openIDParameterDTO.setName(param.getKey());
        openIDParameterDTO.setValue(param.getValue());
        params[i++] = openIDParameterDTO;
    }
    return openIDProviderService.getUserProfiles(openid, params);
}
 
Example #12
Source File: FetchRequest.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a map with the requested attributes.
 *
 * @param       required    If set to true the list of 'required' attributes
 *                          is returned, otherwise the list of 'if_available'
 *                          attributes.
 * @return      Map of attribute aliases -> attribute type URIs.
 */
public Map getAttributes(boolean required)
{
    HashMap attributes = new LinkedHashMap();

    String level = required ? "required" : "if_available";

    Parameter param = _parameters.getParameter(level);
    if (param != null)
    {
        String[] values = param.getValue().split(",");
        for (int i = 0; i < values.length; i++)
        {
            String alias = values[i];
            attributes.put(alias,
                    _parameters.getParameterValue("type." + alias));
        }
    }

    return attributes;
}
 
Example #13
Source File: OpenIDUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static OpenIDParameterDTO[] getOpenIDAuthRequest(ParameterList request) {
    OpenIDParameterDTO[] params = null;
    List list = null;

    list = request.getParameters();
    params = new OpenIDParameterDTO[list.size()];
    int i = 0;
    for (Object object : list) {
        Parameter param = (Parameter) object;
        OpenIDParameterDTO openIDParameterDTO = new OpenIDParameterDTO();
        openIDParameterDTO.setName(param.getKey());
        openIDParameterDTO.setValue(param.getValue());
        params[i++] = openIDParameterDTO;
    }
    return params;
}
 
Example #14
Source File: YahooFetchResponse.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
protected boolean isValid() {

        Iterator it = _parameters.getParameters().iterator();
        while (it.hasNext()) {
            String paramName = ((Parameter) it.next()).getKey();

            if (!paramName.equals("mode") &&
                    !paramName.startsWith("type.") &&
                    !paramName.startsWith("count.") &&
                    !paramName.startsWith("value.") &&
                    !paramName.equals("update_url")) {
                log.warn("Invalid parameter name in AX payload: " + paramName);
                //return false;
            }
        }
        return checkAttributes();
    }
 
Example #15
Source File: CustomOpenIdProcessorTest.java    From OpenID-Attacker with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public void testOpenidGenerateResponse() throws Exception {
        final String EXPECTED_ASSOC_VALUE = "MY_CUSTOM_ASSOC_VALUE";

        ParameterList assoc_parameter = new ParameterList();
        assoc_parameter.set(new Parameter("openid.dh_consumer_public", "MTEK"));
        assoc_parameter.set(new Parameter("openid.mode", "associate"));
        assoc_parameter.set(new Parameter("openid.ns", "http://specs.openid.net/auth/2.0"));
        assoc_parameter.set(new Parameter("openid.session_type", "DH-SHA1"));
        assoc_parameter.set(new Parameter("openid.assoc_type", "HMAC-SHA1"));

//        System.out.println("### REQUEST:\n" + assoc_parameter.toString());
        store.setAssociationPrefix(EXPECTED_ASSOC_VALUE);

        Message responseAuthenticaton = processor.processAssociationRequest(assoc_parameter);
        String assoc_value = responseAuthenticaton.getParameterValue("assoc_handle");
        assertThat(assoc_value, equalTo(EXPECTED_ASSOC_VALUE));

        ParameterList generate_parameter = new ParameterList();
        generate_parameter.set(new Parameter("openid.ns", "http://specs.openid.net/auth/2.0"));
//        generate_parameter.set(new Parameter("openid.realm", "http://realm"));
        generate_parameter.set(new Parameter("openid.mode", "checkid_setup"));
        generate_parameter.set(new Parameter("openid.return_to", "http://return"));
        generate_parameter.set(new Parameter("openid.claimed_id", "http://claimed"));
        generate_parameter.set(new Parameter("openid.identity", "http://identity"));
        generate_parameter.set(new Parameter("openid.assoc_handle", assoc_value));

//        System.out.println("### GENERATE:\n" + generate_parameter);
        AttackParameterKeeper responseToken = processor.processTokenRequest(generate_parameter);
//        responseToken.validate();
//        System.out.println("### TOKEN:\n" + responseToken.toString());

        // is there a signature?
        assertThat(responseToken.getParameter("openid.sig") != null, is(true));

    }
 
Example #16
Source File: StoreRequest.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a Store Request with an empty parameter list.
 */
protected StoreRequest()
{
    _parameters.set(new Parameter("mode", "store_request"));

    if (DEBUG) _log.debug("Created empty store request.");
}
 
Example #17
Source File: CustomOpenIdProcessor.java    From OpenID-Attacker with GNU General Public License v2.0 5 votes vote down vote up
private void addNamespaceIfNotContained(ParameterList token_parameter) {
    if (!token_parameter.hasParameter("ns")) {
        final String nsValue = xrdsConfiguration.getOpenIdVersion().getNS();
        final Parameter nsParameter = new Parameter("openid.ns", nsValue);
        token_parameter.set(nsParameter);
    }
}
 
Example #18
Source File: OpenIDAdminClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public Map<String, OpenIDClaimDTO> getClaimValues(String openId, String profileId, ParameterList requiredClaims)
        throws IdentityProviderException {

    List list = requiredClaims.getParameters();
    OpenIDParameterDTO[] params = new OpenIDParameterDTO[list.size()];
    int i = 0;
    for (Object object : list) {
        Parameter param = (Parameter) object;
        OpenIDParameterDTO openIDParameterDTO = new OpenIDParameterDTO();
        openIDParameterDTO.setName(param.getKey());
        openIDParameterDTO.setValue(param.getValue());
        params[i++] = openIDParameterDTO;
    }

    OpenIDClaimDTO[] claims = openIDProviderService.getClaimValues(openId.trim(), profileId, params);

    Map<String, OpenIDClaimDTO> map = new HashMap<String, OpenIDClaimDTO>();
    if (claims != null) {
        for (int j = 0; j < claims.length; j++) {
            if (claims[j] != null) {
                map.put(claims[j].getClaimUri(), claims[j]);
            }
        }
    }

    return map;
}
 
Example #19
Source File: SRegResponse.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a map with attribute names -> values.
 */
public Map getAttributes()
{
    Map attributes = new HashMap();

    Iterator it = _parameters.getParameters().iterator();
    while (it.hasNext())
    {
        String attr = ((Parameter) it.next()).getKey();
        attributes.put(attr, getAttributeValue(attr));
    }

    return attributes;
}
 
Example #20
Source File: SRegResponse.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a list of attribute names in the SReg response.
 */
public List getAttributeNames()
{
    List attributes = new ArrayList();

    Iterator it = _parameters.getParameters().iterator();
    while (it.hasNext())
    {
        attributes.add(((Parameter) it.next()).getKey());
    }

    return attributes;
}
 
Example #21
Source File: SRegResponse.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Adds an attribute to the SReg response. The allowed attribute names are
 * the ones defined in the SReg specification: nickname, email, fullname,
 * dob, gender, postcode, country, language, timezone.
 *
 * @param       attr        An attribute name.
 * @param       value       The value of the attribute.
 */
public void addAttribute(String attr, String value) throws MessageException
{
    _parameters.set(new Parameter(attr, value));

    if (! SREG_FIELDS.contains(attr))
        throw new MessageException("Invalid attribute for SReg: " + attr);

    if (DEBUG)
        _log.debug("Added new attribute to SReg response: " + attr +
                   " value: " + value);
}
 
Example #22
Source File: SRegRequest.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the optional policy URL.
 *
 * @param   policyUrl   A URL which the Consumer provides to give the
 *                      End User a place to read about the how the profile
 *                      data will be used. The Identity Provider SHOULD
 *                      display this URL to the End User if it is given.
 */
public void setPolicyUrl(String policyUrl) throws MessageException {
    try
    {
        new URL(policyUrl);
    } catch (MalformedURLException e)
    {
        throw new MessageException("Invalid policy_url: " + policyUrl);
    }

    if (DEBUG) _log.debug("Setting SReg request policy_url: " + policyUrl);

    _parameters.set(new Parameter("policy_url", policyUrl));
}
 
Example #23
Source File: FetchRequest.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a Fetch Request with an empty parameter list.
 */
protected FetchRequest()
{
    _parameters.set(new Parameter("mode", "fetch_request"));

    if (DEBUG) _log.debug("Created empty fetch request.");
}
 
Example #24
Source File: FetchResponse.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a Fetch Response with an empty parameter list.
 */
protected FetchResponse()
{
    _parameters.set(new Parameter("mode", "fetch_response"));

    if (DEBUG) _log.debug("Created empty fetch response.");
}
 
Example #25
Source File: StoreResponse.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the validity of the extension.
 * <p>
 * Used when constructing a extension from a parameter list.
 *
 * @return      True if the extension is valid, false otherwise.
 */
private boolean isValid()
{
    if ( ! _parameters.hasParameter("mode") ||
            ( ! "store_response_success".equals(_parameters.getParameterValue("mode")) &&
              ! "store_response_failure".equals(_parameters.getParameterValue("mode")) ) )
    {
        _log.warn("Invalid mode value in store response: "
                  + _parameters.getParameterValue("mode"));
        return false;
    }

    Iterator it = _parameters.getParameters().iterator();
    while (it.hasNext())
    {
        Parameter param = (Parameter) it.next();
        String paramName = param.getKey();

        if (! paramName.equals("mode") &&
                ! paramName.equals("error"))
        {
            _log.warn("Invalid parameter name in store response: " + paramName);
            return false;
        }
    }

    return true;
}
 
Example #26
Source File: StoreResponse.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Marks the Store Response as a failure, by setting the appropirate
 * parameters.
 *
 * @param       description     Describes the error condition leading to
 *                              the failure response
 */
public void setFailure(String description)
{
    _parameters.set(new Parameter("mode", "store_response_failure"));

    if (description != null)
        _parameters.set(new Parameter("error", description));
}
 
Example #27
Source File: StoreResponse.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a Store Response with an empty parameter list.
 */
protected StoreResponse()
{
    _parameters.set(new Parameter("mode", "store_response_success"));

    if (DEBUG) _log.debug("Created empty store request.");
}
 
Example #28
Source File: AxPayload.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Adds an attribute to the attribute payload, without the caller having to
 * specify an alias. An alias in the form "attrNN" will be automatically
 * generated.
 *
 * @param typeUri   The attribute type URI.
 * @param value     The attribute value.
 * @return          The generated attribute alias.
 */
public String addAttribute(String typeUri, String value)
{
    String alias = generateAlias();

    // not calling the other addAttribute - extra overhead in checks there
    _parameters.set(new Parameter("type." + alias, typeUri));
    _parameters.set(new Parameter("value." + alias, value));

    if (DEBUG)
        _log.debug("Added new attribute to the AX payload; type: " + typeUri
                   + " alias: " + alias);

    return alias;
}
 
Example #29
Source File: AxPayload.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Adds an attribute to the attribute payload.
 *
 * @param       alias       The alias identifier that will be associated
 *                          with the attribute type URI.
 * @param       typeUri     The attribute type URI.
 * @param       value       The value of the attribute.
 */
public void addAttribute(String alias, String typeUri, String value)
    throws MessageException
{
    if ( alias.indexOf(',') > -1 || alias.indexOf('.') > -1 ||
         alias.indexOf(':') > -1 || alias.indexOf('\n') > -1 )
        throw new MessageException(
            "Characters [.,:\\n] are not allowed in attribute aliases: " + alias);

    int count = getCount(alias);

    String index = "";

    switch(count)
    {
        case 0:
            _parameters.set(new Parameter("type." + alias, typeUri));
            break;

        case 1:
            // rename the existing one
            _parameters.set(new Parameter("value." + alias + ".1",
                    getParameterValue("value." + alias)));
            _parameters.removeParameters("value." + alias);
            index = ".2";
            break;

        default:
            index = "." +Integer.toString(count + 1);
    }

    _parameters.set(new Parameter("value." + alias + index, value));
    setCount(alias, ++count);

    if (DEBUG)
        _log.debug("Added new attribute to AX payload; type: " + typeUri
                   + " alias: " + alias + " count: " + count);
}
 
Example #30
Source File: FetchRequest.java    From openid4java with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the optional 'update_url' parameter where the OP can later re-post
 * fetch-response updates to the values of the requested attributes.
 *
 * @param       updateUrl   The URL where the RP accepts later updates
 *                          to the requested attributes.
 */
public void setUpdateUrl(String updateUrl) throws MessageException
{
    try
    {
        new URL(updateUrl);
    } catch (MalformedURLException e)
    {
        throw new MessageException("Invalid update_url: " + updateUrl);
    }

    if (DEBUG) _log.debug("Setting fetch request update_url: " + updateUrl);

    _parameters.set(new Parameter("update_url", updateUrl));
}