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

com.clouway.oauth2.exampleapp.UserLoaderImpl Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package com.clouway.oauth2.exampleapp;

import com.clouway.oauth2.DateTime;
import com.clouway.oauth2.token.Token;
import com.clouway.oauth2.token.Tokens;
import com.clouway.oauth2.user.User;
import com.google.common.base.Optional;

import java.util.Date;

/**
 * @author Mihail Lesikov ([email protected])
 */
public class UserLoaderImpl implements UserLoader {

  private UserRepository repository;
  private Tokens tokens;

  public UserLoaderImpl(UserRepository repository, Tokens tokens) {
    this.repository = repository;
    this.tokens = tokens;
  }

  @Override
  public Optional load(String tokenValue) {

    Optional token = tokens.getNotExpiredToken(tokenValue, new DateTime());
    if (!token.isPresent()) {
      return Optional.absent();
    }

    Optional user = repository.load(token.get().identityId);
    if (!token.isPresent()) {
      return Optional.absent();
    }

    return user;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy