コード例 #1
0
  /**
   * 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;
  }
コード例 #2
0
  /**
   * Log an user out from an openid provider
   *
   * @param adapter protocol adapter
   * @throws OpenIDLifeCycleException
   */
  public void logout(OpenIDProtocolAdapter adapter) throws OpenIDLifeCycleException {
    OpenIDLifecycle lifeCycle = null;

    if (adapter instanceof OpenIDLifecycle) {
      lifeCycle = (OpenIDLifecycle) adapter;
    }
    if (lifeCycle != null) {
      lifeCycle.handle(
          new OpenIDLifecycleEvent(
              OpenIDLifecycleEvent.TYPE.SESSION,
              OpenIDLifecycleEvent.OP.REMOVE,
              CONST.OPENID.get(),
              null));
      lifeCycle.handle(
          new OpenIDLifecycleEvent(
              OpenIDLifecycleEvent.TYPE.SESSION,
              OpenIDLifecycleEvent.OP.REMOVE,
              CONST.OPENID_CLAIMED.get(),
              null));
    }
  }