Package org.openid4java.association

Examples of org.openid4java.association.AssociationSessionType


        // the most-desirable entry is always at the top of the stack
        Stack reqStack = new Stack();
        Iterator iter = requests.keySet().iterator();
        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))
View Full Code Here


            AssociationRequest assocReq =
                    AssociationRequest.createAssociationRequest(requestParams);

            isVersion2 = assocReq.isVersion2();

            AssociationSessionType type = assocReq.getType();

            // is supported / allowed ?
            if (! Association.isHmacSupported(type.getAssociationType()) ||
                    ! DiffieHellmanSession.isDhSupported(type) ||
                    _minAssocSessEnc.isBetter(type))
            {
                throw new AssociationException("Unable create association for: "
                        + type.getSessionType() + " / "
                        + type.getAssociationType() );
            }
            else // all ok, go ahead
            {
                Association assoc = _sharedAssociations.generate(
                        type.getAssociationType(), _expireIn);

                _log.info("Returning shared association; handle: " + assoc.getHandle());

                return AssociationResponse.createAssociationResponse(assocReq, assoc);
            }
View Full Code Here

            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
View Full Code Here

        // the most-desirable entry is always at the top of the stack
        Stack reqStack = new Stack();
        Iterator iter = requests.keySet().iterator();
        while(iter.hasNext())
        {
            AssociationSessionType type = (AssociationSessionType) iter.next();

            // create the appropriate Association Request
            AssociationRequest newReq = createAssociationRequest(type, idpUrl);
            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(idpEndpoint, 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 IdPs may return a success no-encryption resp
                            ( ! discovered.isVersion2() &&
                              respType.getHAlgorithm() == null &&
                              createAssociationRequest(respType,idpUrl) != null))
                    {
                        // store the association and do no try alternatives
                        _associations.save(idpEndpoint, assoc);
                        _log.info("Associated with " + discovered.getIdpEndpoint()
                                + " handle: " + assoc.getHandle());
                        break;
                    }
                    else
                        _log.info("Discarding, 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 IdP
                    // and queue a new attempt
                    AssociationError assocErr =
                            AssociationError.createAssociationError(respParams);

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

                    if (alreadyTried.keySet().contains(idpType))
View Full Code Here

            AssociationRequest assocReq =
                    AssociationRequest.createAssociationRequest(requestParams);

            isVersion2 = assocReq.isVersion2();

            AssociationSessionType type = assocReq.getType();

            // is supported / allowed ?
            if (! Association.isHmacSupported(type.getAssociationType()) ||
                    ! DiffieHellmanSession.isDhSupported(type) ||
                    _minAssocSessEnc.isBetter(type))
            {
                throw new AssociationException("Unable create association for: "
                        + type.getSessionType() + " / "
                        + type.getAssociationType() );
            }
            else // all ok, go ahead
            {
                Association assoc = _sharedAssociations.generate(
                        type.getAssociationType(), _expireIn);

                _log.info("Returning shared association; handle: " + assoc.getHandle());

                return AssociationResponse.createAssociationResponse(assocReq, assoc);
            }
View Full Code Here

            _log.debug("Creating association response, type: " + assocReq.getType()
                       + " association handle: " + assoc.getHandle());

        if (assocReq.isVersion2()) set("ns", OPENID2_NS);

        AssociationSessionType type = assocReq.getType();
        setType(type);

        setAssocHandle(assoc.getHandle());

        Long expiryIn = new Long( ( assoc.getExpiry().getTime() -
                                    System.currentTimeMillis() ) / 1000 );
        setExpire(expiryIn);

        if (type.getHAlgorithm() != null) // DH session, encrypt the MAC key
        {
            DiffieHellmanSession dhSess = DiffieHellmanSession.create(
                    type, assocReq.getDhModulus(), assocReq.getDhGen() );

            setPublicKey(dhSess.getPublicKey());
View Full Code Here

        // basic checks
        if (! super.isValid()) return false;

        // association / session type checks
        // (includes most of the compatibility stuff)
        AssociationSessionType type;
        try
        {
            // throws exception for invalid session / association types
            type = getType();

            // make sure compatibility mode is the same for type and message
            if (type.isVersion2() ^ isVersion2())
            {
                _log.warn("Protocol verison mismatch between association " +
                          "session type: " + type +
                          " and AssociationResponse message type.");
                return false;
            }

        } catch (AssociationException e) {
            _log.error("Error verifying association response validity.", e);
            return false;
        }

        // additional compatibility checks
        if (! isVersion2() && getAssociationType() == null)
        {
            _log.warn("assoc_type cannot be omitted in OpenID1 responses");
            return false;
        }

        String macKey;
        if (type.getHAlgorithm() != null) // DH session
        {
            if ( ! hasParameter("dh_server_public") ||
                    ! hasParameter("enc_mac_key") )
            {
                _log.warn("DH public key or encrypted MAC key missing.");
                return false;
            }
            else
                macKey = getParameterValue("enc_mac_key");
        } else // no-enc session
        {
            if ( !hasParameter("mac_key") )
            {
                _log.warn("Missing MAC key.");
                return false;
            }
            else
                macKey = getParameterValue("mac_key");
        }

        // mac key size
        int macSize = Base64.decodeBase64(macKey.getBytes()).length * 8;

        if ( macSize != type.getKeySize())
        {
            _log.warn("MAC key size: " + macSize +
                      " doesn't match the association/session type: " + type);
            return false;
        }
View Full Code Here

                getParameterValue("expires_in") );

        // get (and decrypt) the MAC key
        byte[] macKey;

        AssociationSessionType type = getType();

        if ( type.getHAlgorithm() != null )
        {
            macKey = dhSess.decryptMacKey(
                    getParameterValue("enc_mac_key"),
                    getParameterValue("dh_server_public") );
            if (DEBUG) _log.debug("Decrypted MAC key (base64): " +
                                  new String(Base64.encodeBase64(macKey)));
        }
        else
        {
            macKey = Base64.decodeBase64(
                    getParameterValue("mac_key").getBytes() );

            if (DEBUG) _log.debug("Unencrypted MAC key (base64): "
                                  + getParameterValue("mac_key"));
        }

        Association assoc;

        if (Association.TYPE_HMAC_SHA1.equals(type.getAssociationType()))
            assoc = Association.createHmacSha1(handle, macKey, expiresIn);

        else if (Association.TYPE_HMAC_SHA256.equals(type.getAssociationType()))
            assoc = Association.createHmacSha256(handle, macKey, expiresIn);

        else
            throw new AssociationException("Unknown association type: " + type);
View Full Code Here

        // basic checks
        if (! super.isValid()) return false;

        // association / session type checks
        // (includes most of the compatibility stuff)
        AssociationSessionType type;
        try
        {
            // throws exception for invalid session / association types
            type = getType();

            // make sure compatibility mode is the same for type and message
            if (type.isVersion2() != isVersion2())
            {
                _log.warn("Protocol verison mismatch between association " +
                          "session type: " + type +
                          " and AssociationRequest message type.");
                return false;
            }

        } catch (AssociationException e) {
            _log.error("Error verifying association request validity.", e);
            return false;
        }

        // additional compatibility checks
        if (! isVersion2() && getSessionType() == null)
        {
            _log.warn("sess_type cannot be omitted in OpenID1 association requests");
            return false;
        }

        // DH seesion parameters
        if ( type.getHAlgorithm() != null && getDhPublicKey() == null)
        {
            _log.warn("DH consumer public key not specified.");
            return false;
        }

        // no-enc session
        if (type.getHAlgorithm() == null && (getDhGen() != null ||
                getDhModulus() != null || getDhPublicKey() != null) )
        {
            _log.warn("No-encryption session, but DH parameters specified.");
            return false;
        }
View Full Code Here

            AssociationRequest assocReq =
                    AssociationRequest.createAssociationRequest(requestParams);

            isVersion2 = assocReq.isVersion2();

            AssociationSessionType type = assocReq.getType();

            // is supported / allowed ?
            if (! Association.isHmacSupported(type.getAssociationType()) ||
                    ! DiffieHellmanSession.isDhSupported(type) ||
                    _minAssocSessEnc.isBetter(type))
            {
                throw new AssociationException("Unable create association for: "
                        + type.getSessionType() + " / "
                        + type.getAssociationType() );
            }
            else // all ok, go ahead
            {
                Association assoc = _sharedAssociations.generate(
                        type.getAssociationType(), _expireIn);

                _log.info("Returning shared association; handle: " + assoc.getHandle());

                return AssociationResponse.createAssociationResponse(assocReq, assoc);
            }
View Full Code Here

TOP

Related Classes of org.openid4java.association.AssociationSessionType

Copyright © 2018 www.massapicom. 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.