Java Code Examples for org.openid4java.message.ParameterList#hasParameter()

The following examples show how to use org.openid4java.message.ParameterList#hasParameter() . 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: SmartOpenIdController.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
/**
 * Gets the association response. Determines the mode first.
 * If mode is set to associate, will set the response. Then
 * builds the response parameters next and returns.
 *
 * @param request the request
 * @return the association response
 */
public Map<String, String> getAssociationResponse(final HttpServletRequest request) {
    final ParameterList parameters = new ParameterList(request.getParameterMap());

    final String mode = parameters.hasParameter(OpenIdConstants.OPENID_MODE)
            ? parameters.getParameterValue(OpenIdConstants.OPENID_MODE)
            : null;

    Message response = null;

    if (StringUtils.equals(mode, OpenIdConstants.ASSOCIATE)) {
        response = serverManager.associationResponse(parameters);
    }
    final Map<String, String> responseParams = new HashMap<>();
    if (response != null) {
        responseParams.putAll(response.getParameterMap());
    }

    return responseParams;

}
 
Example 2
Source File: SmartOpenIdController.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
public Map<String, String> getAssociationResponse(final HttpServletRequest request) {
    ParameterList parameters = new ParameterList(request.getParameterMap());

    final String mode = parameters.hasParameter("openid.mode")
            ? parameters.getParameterValue("openid.mode")
            : null;

    Message response = null;
    if (mode != null && mode.equals("associate")) {
        response = serverManager.associationResponse(parameters);
    }
    final Map<String, String> responseParams = new HashMap<String, String>();
    if (response != null) {
        responseParams.putAll(response.getParameterMap());
    }

    return responseParams;

}
 
Example 3
Source File: SReg11ExtensionFactory.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates the apropriate Simple Registration object
 * (request / response) for the supplied parameter list.
 *
 * Similar to SRegMessage.getExtension(), but sets the SREG 1.1 type URI.
 *
 * @param parameterList         The Simple Registration specific parameters
 *                              (without the openid.<ext_alias> prefix)
 *                              extracted from the openid message.
 * @param isRequest             Indicates whether the parameters were
 *                              extracted from an OpenID request (true),
 *                              or from an OpenID response.
 * @return                      MessageExtension implementation for
 *                              the supplied extension parameters.
 * @throws MessageException     If a Simple Registration object could not be
 *                              instantiated from the supplied parameter list.
 */
public MessageExtension getExtension(
        ParameterList parameterList, boolean isRequest)
        throws MessageException
{
    SRegMessage sreg;

    if ( parameterList.hasParameter("required") ||
         parameterList.hasParameter("optional"))

        sreg = SRegRequest.createSRegRequest(parameterList);

    else
        sreg = SRegResponse.createSRegResponse(parameterList);

    sreg.setTypeUri(SRegMessage.OPENID_NS_SREG11);

    return sreg;
}
 
Example 4
Source File: OpenIDHandler.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the mode field of the OpenID message.
 *
 * @param paramList
 * @param response
 * @param request
 * @return
 * @throws IOException
 */
private String getOpenIDMessageMode(ParameterList paramList, HttpServletResponse response,
                                    HttpServletRequest request) throws IOException {
    String mode = null;
    if (paramList == null) {
        if (log.isDebugEnabled()) {
            log.debug("Invalid OpenID message :" + request.getQueryString());
        }
        directResponse(response, getErrorResponseText("Invalid OpenID message"));
        return null;
    }
    mode = paramList.hasParameter(OpenId.ATTR_MODE) ? paramList.getParameterValue(OpenId.ATTR_MODE) : null;
    if (log.isDebugEnabled()) {
        log.debug("OpenID authentication mode :" + mode);
    }
    return mode;
}
 
Example 5
Source File: CustomOpenIdProviderHandler.java    From OpenID-Attacker with GNU General Public License v2.0 5 votes vote down vote up
private void handleRequest(ParameterList requestParameter, String target, HttpServletResponse response, Request baseRequest) throws IOException, OpenIdAttackerServerException, TransformerException {
       // get the openIdProcessor.mode
       final String method = baseRequest.getMethod();
       final HttpURI uri = baseRequest.getUri();
       final String protocol = baseRequest.getProtocol();
       final String info = String.format("%s %s %s", method, uri, protocol);
       final String mode = requestParameter.hasParameter("openid.mode")
         ? requestParameter.getParameterValue("openid.mode") : null;

if (uri.getCompletePath().equals("/favicon.ico")) {
           handleFaviconRequest(info, response);
       } else if (target.contains("xxe")) {
           // Case: XXE
           handleXxeRequest(info, response, requestParameter);
       } /*else if (target.contains("dtd")) {
           // Case: DTD
           handleDtdRequest(info, response, requestParameter);
       }*/ else if (mode == null) {
           if (target.contains("xrds") || requestParameter.toString().contains("xrds")) {
               // Case: Request XRDS Document
               handleXrdsRequest(info, response);                
           } else {
               // Case: Request HTML Document
               handleHtmlDiscovery(info, response);
           }
       } else if ("associate".equals(mode)) {
           // Case: Process Association
           handleAssociationRequest(info, response, requestParameter);
       } else if ("checkid_setup".equals(mode) || "checkid_immediate".equals(mode)) {
           // Case: Generate Token
           handleTokenRequest(info, response, requestParameter);
       } else if ("check_authentication".equals(mode)) {
           handleCheckAuthentication(info, response, requestParameter);
       } else {
           throw new IllegalStateException("Unknown Request");
       }
       baseRequest.setHandled(true);
   }
 
Example 6
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);
    }
}