Package org.openid4java.association

Examples of org.openid4java.association.Association


        throws ServerException, AssociationException
    {
        String handle = authSuccess.getHandle();

        // try shared associations first, then private
        Association assoc = _sharedAssociations.load(handle);

        if (assoc == null)
            assoc = _privateAssociations.load(handle);

        if (assoc == null) throw new ServerException(
                "No association found for handle: " + handle);

        authSuccess.setSignature(assoc.sign(authSuccess.getSignedText()));
    }
View Full Code Here


            isVersion2 = vrfyReq.isVersion2();
            String handle = vrfyReq.getHandle();

            boolean verified = false;

            Association assoc = _privateAssociations.load(handle);
            if (assoc != null) // verify the signature
            {
                _log.info("Loaded private association; handle: " + handle);

                verified = assoc.verifySignature(
                        vrfyReq.getSignedText(),
                        vrfyReq.getSignature());

                // remove the association so that the request
                // cannot be verified more than once
View Full Code Here

    public abstract ServerAssociationStore createStore();

    public void testGenerate() throws AssociationException
    {
        Association association = _associationStore.generate(Association.TYPE_HMAC_SHA1, 60);

        assertNotNull(association);

        assertSame(association, _associationStore.load(association.getHandle()));

        association = _associationStore.generate(Association.TYPE_HMAC_SHA256, 60);

        assertNotNull(association);

        assertSame(association, _associationStore.load(association.getHandle()));
    }
View Full Code Here

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

        firstServiceMatch = service;
      }

      // we'll keep looking for a service for which we already have an
      // association. Only if we don't find any do we return the first match
      Association assoc = consumerManager.getPrivateAssociationStore().load(
          service.getOPEndpoint().toString(),
          authResp.getHandle());

      // don't look further if there is an association with this endpoint
      if (assoc != null) {
View Full Code Here

        {
            try
            {
                String handle = Long.toHexString(_random.nextLong());

                Association association =
                        Association.generate(type, handle, expiryIn);

                int cnt = jdbcTemplate.update(sql,
                        new Object[] {
                                association.getHandle(),
                                association.getType(),
                                new String(Base64.encodeBase64(
                                        association.getMacKey().getEncoded())),
                                association.getExpiry()
                        });

                if (cnt == 1)
                {
                    if (DEBUG)
View Full Code Here

            if (type == null || macKey == null || expDate == null)
                throw new AssociationException("Invalid association data " +
                        "retrived from database; cannot create Association " +
                        "object for handle: " + handle);

            Association assoc;

            if (Association.TYPE_HMAC_SHA1.equals(type))
                assoc = Association.createHmacSha1(handle,
                        Base64.decodeBase64(macKey.getBytes() ), expDate);
View Full Code Here

     * @see Discovery#discover(org.openid4java.discovery.Identifier)
     */
    public DiscoveryInformation associate(List discoveries)
    {
        DiscoveryInformation discovered;
        Association assoc;

        int attemptsLeft = _maxAssocAttempts;
        Iterator itr = discoveries.iterator();
        while (itr.hasNext() && attemptsLeft > 0)
        {
            discovered = (DiscoveryInformation) itr.next();
            attemptsLeft -= associate(discovered, attemptsLeft);

            // check if an association was established
            assoc = _associations.load(discovered.getIdpEndpoint().toString());

            if ( assoc != null &&
                    ! Association.FAILED_ASSOC_HANDLE.equals(assoc.getHandle()))
                return discovered;
        }

        if (discoveries.size() > 0)
        {
View Full Code Here

        _log.info("Trying to associate with " + idpEndpoint +
                " attempts left: " + maxAttempts);

        // check if there's an already established association
        Association a = _associations.load(idpEndpoint);
        if (a != null && a.getHandle() != null)
        {
            _log.info("Found an existing association.");
            return 0;
        }

        String handle = Association.FAILED_ASSOC_HANDLE;

        // build a list of association types, with the preferred one at the end
        LinkedHashMap requests = new LinkedHashMap();

        if (discovered.isVersion2())
        {
            requests.put(AssociationSessionType.NO_ENCRYPTION_SHA1MAC, null);
            requests.put(AssociationSessionType.NO_ENCRYPTION_SHA256MAC, null);
            requests.put(AssociationSessionType.DH_SHA1, null);
            requests.put(AssociationSessionType.DH_SHA256, null);
        }
        else
        {
            requests.put(AssociationSessionType.NO_ENCRYPTION_COMPAT_SHA1MAC, null);
            requests.put(AssociationSessionType.DH_COMPAT_SHA1, null);
        }

        if (_prefAssocSessEnc.isVersion2() == discovered.isVersion2())
            requests.put(_prefAssocSessEnc, null);

        // build a stack of Association Request objects
        // and keep only the allowed by the configured preferences
        // 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");
                }
View Full Code Here

            throw new ConsumerException("Authentication cannot continue: " +
                    "no discovery information provided.");

        associate(discovered, _maxAssocAttempts);

        Association assoc =
                _associations.load(discovered.getIdpEndpoint().toString());
        String handle = assoc != null ?
                assoc.getHandle() : Association.FAILED_ASSOC_HANDLE;

        // get the Claimed ID
        String claimedId;
        if (discovered.hasClaimedIdentifier())
            claimedId = discovered.getClaimedIdentifier().getIdentifier();
View Full Code Here

TOP

Related Classes of org.openid4java.association.Association

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.