All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clouway.oauth2.exampleapp.storage.InMemoryUserRepository Maven / Gradle / Ivy

The newest version!
package com.clouway.oauth2.exampleapp.storage;

import com.clouway.friendlyserve.Request;
import com.clouway.oauth2.DateTime;
import com.clouway.oauth2.Identity;
import com.clouway.oauth2.exampleapp.UserRepository;
import com.clouway.oauth2.token.GrantType;
import com.clouway.oauth2.user.FindIdentityRequest;
import com.clouway.oauth2.user.IdentityFinder;
import com.clouway.oauth2.user.ResourceOwnerIdentityFinder;
import com.clouway.oauth2.user.User;
import com.google.common.base.Optional;

import java.util.Collections;
import java.util.Map;

/**
 * @author Mihail Lesikov ([email protected])
 */
class InMemoryUserRepository implements IdentityFinder, ResourceOwnerIdentityFinder, UserRepository {

  @Override
  public Optional find(Request request, DateTime instantTime) {
    // get session id from cookie
    // and retrieve user information for that SID
    for (String sid : request.cookie("SID")) {
      return Optional.of("testUserID");
    }

    return Optional.absent();
  }

  @Override
  public Optional findIdentity(FindIdentityRequest request) {
    if (request.grantType == GrantType.AUTHORIZATION_CODE) {
      return Optional.of(new Identity("testUserID", "testUser", "test User", "User Family", "[email protected]", null, Collections.emptyMap()));
    } else {
      return Optional.of(new Identity("[email protected]", "[email protected]", "Customer Portal", "", "", "", Collections.emptyMap()));
    }
  }

  @Override
  public Optional load(String userId) {
    return Optional.of(new User("testUserID", "[email protected]", "Ivan Stefanov"));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy