Examples of AssociationRequest


Examples of org.openid4java.message.AssociationRequest

        while(iter.hasNext())
        {
            AssociationSessionType type = (AssociationSessionType) iter.next();

            // create the appropriate Association Request
            AssociationRequest newReq = createAssociationRequest(type, opUrl);
            if (newReq != null) reqStack.push(newReq);
        }

        // perform the association attempts
        int attemptsLeft = maxAttempts;
        LinkedHashMap alreadyTried = new LinkedHashMap();
        while (attemptsLeft > 0 && ! reqStack.empty())
        {
            try
            {
                attemptsLeft--;
                AssociationRequest assocReq =
                        (AssociationRequest) reqStack.pop();

                if (DEBUG)
                    _log.debug("Trying association type: " + assocReq.getType());

                // was this association / session type attempted already?
                if (alreadyTried.keySet().contains(assocReq.getType()))
                {
                    if (DEBUG) _log.debug("Already tried.");
                    continue;
                }

                // mark the current request type as already tried
                alreadyTried.put(assocReq.getType(), null);

                ParameterList respParams = new ParameterList();
                int status = call(opEndpoint, assocReq, respParams);

                // process the response
                if (status == HttpStatus.SC_OK) // success response
                {
                    AssociationResponse assocResp;

                    assocResp = AssociationResponse
                            .createAssociationResponse(respParams);

                    // valid association response
                    Association assoc =
                            assocResp.getAssociation(assocReq.getDHSess());
                    handle = assoc.getHandle();

                    AssociationSessionType respType = assocResp.getType();
                    if ( respType.equals(assocReq.getType()) ||
                            // v1 OPs may return a success no-encryption resp
                            ( ! discovered.isVersion2() &&
                              respType.getHAlgorithm() == null &&
                              createAssociationRequest(respType,opUrl) != null))
                    {
                        // store the association and do no try alternatives
                        _associations.save(opEndpoint, assoc);
                        _log.info("Associated with " + discovered.getOPEndpoint()
                                + " handle: " + assoc.getHandle());
                        break;
                    }
                    else
                        _log.info("Discarding association response, " +
                                  "not matching consumer criteria");
                }
                else if (status == HttpStatus.SC_BAD_REQUEST) // error response
                {
                    _log.info("Association attempt failed.");

                    // retrieve fallback sess/assoc/encryption params set by OP
                    // and queue a new attempt
                    AssociationError assocErr =
                            AssociationError.createAssociationError(respParams);

                    AssociationSessionType opType =
                            AssociationSessionType.create(
                                    assocErr.getSessionType(),
                                    assocErr.getAssocType());

                    if (alreadyTried.keySet().contains(opType))
                        continue;

                    // create the appropriate Association Request
                    AssociationRequest newReq =
                            createAssociationRequest(opType, opUrl);

                    if (newReq != null)
                    {
                        if (DEBUG) _log.debug("Retrieved association type " +
                                              "from the association error: " +
                                              newReq.getType());

                        reqStack.push(newReq);
                    }
                }
            }
View Full Code Here

Examples of org.openid4java.message.AssociationRequest

        try
        {
            if (_minAssocSessEnc.isBetter(type))
                return null;

            AssociationRequest assocReq = null;

            DiffieHellmanSession dhSess;
            if (type.getHAlgorithm() != null) // DH session
            {
                dhSess = DiffieHellmanSession.create(type, _dhParams);
View Full Code Here

Examples of org.openid4java.message.AssociationRequest

     */
    public Message associationResponse(ParameterList requestParams) {
        boolean isVersion2 = requestParams.hasParameter(IdentityConstants.OpenId.ATTR_NS);

        try {
            AssociationRequest assocReq = AssociationRequest
                    .createAssociationRequest(requestParams);

            isVersion2 = assocReq.isVersion2();

            AssociationSessionType type = assocReq.getType();

            // is supported / allowed ?
            if (!Association.isHmacSupported(type.getAssociationType())
                    || !DiffieHellmanSession.isDhSupported(type)
                    || getMinAssocSessEnc().isBetter(type)) {
                throw new AssociationException("Unable create association for: "
                        + type.getSessionType() + " / " + type.getAssociationType());
            } else {
                Association assoc = getPrivateAssociations().generate(type.getAssociationType(),
                        getExpireIn());
                return AssociationResponse.createAssociationResponse(assocReq, assoc);
            }
        } catch (Exception e) {
            // association failed, respond accordingly
            if (isVersion2) {
                return AssociationError.createAssociationError(e.getMessage(),
                        getPrefAssocSessEnc());
            } else {

                try {
                    // generate dummy association & no-encryption response
                    // for compatibility mode
                    Association dummyAssoc = getPrivateAssociations().generate(
                            Association.TYPE_HMAC_SHA1, 0);

                    AssociationRequest dummyRequest = AssociationRequest
                            .createAssociationRequest(AssociationSessionType.NO_ENCRYPTION_COMPAT_SHA1MAC);

                    return AssociationResponse.createAssociationResponse(dummyRequest, dummyAssoc);
                } catch (OpenIDException ex) {
                    return null;
View Full Code Here

Examples of org.openid4java.message.AssociationRequest

            dhSession = DiffieHellmanSession.create(associationSessionType,
                    dhParameterSpec);
        } else {
            dhSession = null;
        }
        AssociationRequest associationRequest = AssociationRequest.createAssociationRequest(associationSessionType, dhSession);
        Request request = new Request();
        request.setMethod("POST");
        request.setURL(new HttpUrl(opUrl));
        request.setHeader("Content-Type", "application/x-www-form-urlencoded");

        StringBuilder body = new StringBuilder();
        Map parameters = associationRequest.getParameterMap();
        Set parameterEntries = parameters.entrySet();
        Iterator parameterIterator = parameterEntries.iterator();
        while (parameterIterator.hasNext()) {
            if (0 != body.length()) {
                body.append("&");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.