Package org.openid4java.consumer

Examples of org.openid4java.consumer.ConsumerManager


    private ConsumerManager consumerManager;

    @Override
    protected void internalInit() {
        CommonHelper.assertNotBlank("callbackUrl", this.callbackUrl);
        this.consumerManager = new ConsumerManager();
    }
View Full Code Here


  public static final String uniqueIdCookieName = "app-openid-uniqueid";

  private final ConsumerManager manager;

  public OpenIdServlet() throws ConsumerException {
    manager = new ConsumerManager();
  }
View Full Code Here

    private List<OpenIDAttribute> attributesToFetch = Collections.emptyList();

    //~ Constructors ===================================================================================================

    public OpenID4JavaConsumer() throws ConsumerException {
        this.consumerManager = new ConsumerManager();
    }
View Full Code Here

    public OpenID4JavaConsumer() throws ConsumerException {
        this.consumerManager = new ConsumerManager();
    }

    public OpenID4JavaConsumer(List<OpenIDAttribute> attributes) throws ConsumerException {
        this(new ConsumerManager(), attributes);
    }
View Full Code Here

        // configure the return_to URL where your application will receive
        // the authentication responses from the OpenID provider
        this.returnToUrl = returnToUrl;

        // instantiate a ConsumerManager object
        manager = new ConsumerManager();
        manager.setAssociations(new InMemoryConsumerAssociationStore());
        manager.setNonceVerifier(new InMemoryNonceVerifier(5000));

        // for a working demo, not enforcing RP realm discovery
        // since this new feature is not deployed
View Full Code Here

      log.debug("Return to URL '{}'", returnToUrl);

      // Create a consumer manager for this specific request and cache it
      // (this is to preserve session state such as nonce values etc)
      ConsumerManager consumerManager = new ConsumerManager();
      InMemoryOpenIDCache.INSTANCE.putConsumerManager(sessionToken, consumerManager);

      // Perform discovery on the user-supplied identifier
      List discoveries = consumerManager.discover(identifier);

      // Attempt to associate with the OpenID provider
      // and retrieve one service endpoint for authentication
      DiscoveryInformation discovered = consumerManager.associate(discoveries);

      // Create a memento to rebuild the discovered information in a subsequent request
      DiscoveryInformationMemento memento = new DiscoveryInformationMemento();
      if (discovered.getClaimedIdentifier() != null) {
        memento.setClaimedIdentifier(discovered.getClaimedIdentifier().getIdentifier());
      }
      memento.setDelegate(discovered.getDelegateIdentifier());
      if (discovered.getOPEndpoint() != null) {
        memento.setOpEndpoint(discovered.getOPEndpoint().toString());
      }

      memento.setTypes(discovered.getTypes());
      memento.setVersion(discovered.getVersion());

      // Create a temporary User to preserve state between requests without
      // using a session (we could be in a cluster)
      User tempUser = new User(null, sessionToken);
      tempUser.setOpenIDDiscoveryInformationMemento(memento);
      tempUser.setSessionToken(sessionToken);

      // Persist the User
      InMemoryUserCache.INSTANCE.put(sessionToken, tempUser);

      // Build the AuthRequest message to be sent to the OpenID provider
      AuthRequest authReq = consumerManager.authenticate(discovered, returnToUrl);

      // Build the FetchRequest containing the information to be copied
      // from the OpenID provider
      FetchRequest fetch = FetchRequest.createFetchRequest();
      // Attempt to decode each entry
View Full Code Here

    Optional<ConsumerManager> consumerManagerOptional = InMemoryOpenIDCache.INSTANCE.getConsumerManager(sessionToken);
    if (!consumerManagerOptional.isPresent()) {
      log.debug("Authentication failed due to no consumer manager matching session token {}", rawToken);
      throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    ConsumerManager consumerManager = consumerManagerOptional.get();

    // Attempt to locate the user by the session token
    Optional<User> tempUserOptional = InMemoryUserCache.INSTANCE.getBySessionToken(sessionToken);
    if (!tempUserOptional.isPresent()) {
      log.debug("Authentication failed due to no temp User matching session token {}", rawToken);
      throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    User tempUser = tempUserOptional.get();

    // Retrieve the discovery information
    final DiscoveryInformationMemento memento = tempUser.getOpenIDDiscoveryInformationMemento();
    Identifier identifier = new Identifier() {
      @Override
      public String getIdentifier() {
        return memento.getClaimedIdentifier();
      }
    };

    DiscoveryInformation discovered;
    try {
      discovered = new DiscoveryInformation(
        URI.create(memento.getOpEndpoint()).toURL(),
        identifier,
        memento.getDelegate(),
        memento.getVersion(),
        memento.getTypes()
      );
    } catch (DiscoveryException e) {
      throw new WebApplicationException(e, Response.Status.UNAUTHORIZED);
    } catch (MalformedURLException e) {
      throw new WebApplicationException(e, Response.Status.UNAUTHORIZED);
    }

    // Extract the receiving URL from the HTTP request
    StringBuffer receivingURL = request.getRequestURL();
    String queryString = request.getQueryString();
    if (queryString != null && queryString.length() > 0) {
      receivingURL.append("?").append(request.getQueryString());
    }
    log.debug("Receiving URL = '{}", receivingURL.toString());

    // Extract the parameters from the authentication response
    // (which comes in as a HTTP request from the OpenID provider)
    ParameterList parameterList = new ParameterList(request.getParameterMap());

    try {

      // Verify the response
      // ConsumerManager needs to be the same (static) instance used
      // to place the authentication request
      // This could be tricky if this service is load-balanced
      VerificationResult verification = consumerManager.verify(
        receivingURL.toString(),
        parameterList,
        discovered);

      // Examine the verification result and extract the verified identifier
View Full Code Here

    @Override
    public void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException,
            IOException {
        try {
            HttpSession httpSession = httpRequest.getSession(false);
            ConsumerManager manager = (ConsumerManager) httpSession.getAttribute("manager");

            ParameterList openidResp = new ParameterList(httpRequest.getParameterMap());
            List list = openidResp.getParameters();
            if (list != null){
                for (Object param : list) {
                    if (param != null && ((Parameter)param).getKey() != null && ((Parameter)param).getValue() != null){
                        log.info(((Parameter) param).getKey() + "=" + ((Parameter) param).getValue());
                    }
                }
            }

            String openIdIdentity = httpRequest.getParameter("openid.identity");
            DiscoveryInformation discovered = (DiscoveryInformation) httpSession.getAttribute("discovered");

            StringBuffer receivingURL = httpRequest.getRequestURL();
            String queryString = httpRequest.getQueryString();
            if (queryString != null && queryString.length() > 0) {
                receivingURL.append("?").append(httpRequest.getQueryString());
            }
            // verify the response
            VerificationResult verification = null;
            log.info("Receiving URL = " + receivingURL.toString());
            verification = manager.verify(receivingURL.toString(), openidResp, discovered);
            // examine the verification result and extract the verified identifier
            Identifier verified = verification.getVerifiedId();
            if (verified != null) {
                AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
View Full Code Here

        init();
    }

    @Create
    public void init() {
        manager = new ConsumerManager();
        discovered = null;
        id = null;
        authResult = new OpenIdAuthenticationResult();
        // TODO inject these
        identity =
View Full Code Here

   
    public void init(FilterConfig config) throws ServletException {
        super.init(config);
        try
        {
            this.manager = new ConsumerManager();
        } catch (ConsumerException ex) {
            throw new ServletException(ex);
        }
        manager.setAssociations(new InMemoryConsumerAssociationStore());
        manager.setNonceVerifier(new InMemoryNonceVerifier(5000));
View Full Code Here

TOP

Related Classes of org.openid4java.consumer.ConsumerManager

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.