/** * Verify a previously authenticated user with the provider * * @param adapter protocol adapter * @param parameterMap request parameters * @param receivedURL url where the response will be received * @return * @throws OpenIDMessageException * @throws OpenIDDiscoveryException * @throws OpenIDAssociationException * @throws OpenIDLifeCycleException */ public boolean verify( OpenIDProtocolAdapter adapter, Map<String, String> parameterMap, String receivedURL) throws OpenIDMessageException, OpenIDDiscoveryException, OpenIDAssociationException, OpenIDLifeCycleException { OpenIDLifecycle lifeCycle = null; if (adapter instanceof OpenIDLifecycle) { lifeCycle = (OpenIDLifecycle) adapter; } ParameterList responselist = new ParameterList(parameterMap); if (lifeCycle == null) throw new IllegalStateException("Lifecycle not found"); DiscoveryInformation discovered = (DiscoveryInformation) lifeCycle.getAttributeValue(CONST.OPENID_DISC.get()); // verify the response; ConsumerManager needs to be the same // (static) instance used to place the authentication request try { VerificationResult verification = this.consumerManager.verify(receivedURL, responselist, discovered); // examine the verification result and extract the verified identifier Identifier verified = verification.getVerifiedId(); if (verified != null) { AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse(); // Create an lifecycle event array OpenIDLifecycleEvent[] eventArr = new OpenIDLifecycleEvent[] { /** Store the id * */ new OpenIDLifecycleEvent( OpenIDLifecycleEvent.TYPE.SESSION, OpenIDLifecycleEvent.OP.ADD, CONST.OPENID.get(), authSuccess.getIdentity()), /** Store the claimed * */ new OpenIDLifecycleEvent( OpenIDLifecycleEvent.TYPE.SESSION, OpenIDLifecycleEvent.OP.ADD, CONST.OPENID_CLAIMED.get(), authSuccess.getClaimed()), /** Indicate success * */ new OpenIDLifecycleEvent(OpenIDLifecycleEvent.TYPE.SUCCESS, null, null, null) }; lifeCycle.handle(eventArr); return true; } } catch (MessageException e) { throw new OpenIDMessageException(e); } catch (DiscoveryException e) { throw new OpenIDDiscoveryException(e); } catch (AssociationException e) { throw new OpenIDAssociationException(e); } return false; }
/** * Associate with a list of open id providers * * @param adapter Protocol adapter (such as http) * @param listOfProviders (a list of providers from discovery) * @return * @throws OpenIDConsumerException * @throws OpenIDLifeCycleException */ public OpenIDProviderInformation associate( OpenIDProtocolAdapter adapter, OpenIDProviderList listOfProviders) throws OpenIDConsumerException, OpenIDLifeCycleException { OpenIDLifecycle lifeCycle = null; if (adapter instanceof OpenIDLifecycle) { lifeCycle = (OpenIDLifecycle) adapter; } List<DiscoveryInformation> discoveries = listOfProviders.get(); if (discoveries.size() == 0) throw new OpenIDConsumerException("No open id endpoints discovered"); // attempt to associate with the OpenID provider // and retrieve one service endpoint for authentication DiscoveryInformation discovered = consumerManager.associate(discoveries); // store the discovery information in the user's session for later use // leave out for stateless operation / if there is no session if (lifeCycle != null) { OpenIDLifecycleEvent ev = new OpenIDLifecycleEvent( OpenIDLifecycleEvent.TYPE.SESSION, OpenIDLifecycleEvent.OP.ADD, CONST.OPENID_DISC.get(), discovered); lifeCycle.handle(ev); } return new OpenIDProviderInformation(discovered); }