Package org.openid4java.association

Examples of org.openid4java.association.AssociationSessionType


            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


        // 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

            _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
        super.validate();

        // 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())
            {
                throw new MessageException(
                    "Protocol verison mismatch between association " +
                    "session type: " + type +
                    " and AssociationResponse message type.",
                    OpenIDException.ASSOC_ERROR);
            }

        }
        catch (AssociationException e)
        {
            throw new MessageException(
                "Error verifying association response validity.",
                OpenIDException.ASSOC_ERROR, e);
        }

        // additional compatibility checks
        if (! isVersion2() && getAssociationType() == null)
        {
            throw new MessageException(
                "assoc_type cannot be omitted in OpenID1 responses",
                OpenIDException.ASSOC_ERROR);
        }

        String macKey;
        if (type.getHAlgorithm() != null) // DH session
        {
            if ( ! hasParameter("dh_server_public") ||
                    ! hasParameter("enc_mac_key") )
            {
                throw new MessageException(
                    "DH public key or encrypted MAC key missing.",
                    OpenIDException.ASSOC_ERROR);
            }
            else
                macKey = getParameterValue("enc_mac_key");
        } else // no-enc session
        {
            if ( !hasParameter("mac_key") )
            {
                throw new MessageException("Missing MAC key.",
                    OpenIDException.ASSOC_ERROR);
            }
            else
                macKey = getParameterValue("mac_key");
        }

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

        if ( macSize != type.getKeySize())
        {
            throw new MessageException("MAC key size: " + macSize +
                " doesn't match the association/session type: " + type,
                OpenIDException.ASSOC_ERROR);
        }
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
        super.validate();

        // 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())
            {
                throw new MessageException("Protocol verison mismatch " +
                    "between association session type: " + type +
                    " and AssociationRequest message type.",
                    OpenIDException.ASSOC_ERROR);
            }

        }
        catch (AssociationException e)
        {
            throw new MessageException(
                "Error verifying association request validity.",
                OpenIDException.ASSOC_ERROR, e);
        }

        // additional compatibility checks
        if (! isVersion2() && getSessionType() == null)
        {
            throw new MessageException(
                "sess_type cannot be omitted in OpenID1 association requests",
                OpenIDException.ASSOC_ERROR);
        }

        // DH seesion parameters
        if ( type.getHAlgorithm() != null && getDhPublicKey() == null)
        {
            throw new MessageException("DH consumer public key not specified.",
                OpenIDException.ASSOC_ERROR);
        }

        // no-enc session
        if (type.getHAlgorithm() == null && (getDhGen() != null ||
                getDhModulus() != null || getDhPublicKey() != null) )
        {
            throw new MessageException(
                "No-encryption session, but DH parameters specified.",
                OpenIDException.ASSOC_ERROR);
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

        openIdProxy.setRemoveResponseAssociationHandle(removeRespAssocHandle);
    }//GEN-LAST:event_removeRespAssocHandleCheckBoxItemStateChanged

    private void associationRequestButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_associationRequestButtonActionPerformed
        final String opUrl = this.opUrlTextField.getText();
        final AssociationSessionType associationSessionType = this.associationSessionComboBoxModel.getSelectedAssociationSessionType();
        this.associationRequestButton.setEnabled(false);
        new SwingWorker() {

            @Override
            public Object construct() {
View Full Code Here

                    new Item(AssociationSessionType.DH_SHA256)});
    }

    public AssociationSessionType getSelectedAssociationSessionType() {
        Item item = (Item) this.getSelectedItem();
        AssociationSessionType associationSessionType = item.getAssociationSessionType();
        return associationSessionType;
    }
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, 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

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.