Skip to content

Commit

Permalink
Add authentication service
Browse files Browse the repository at this point in the history
  • Loading branch information
jc064522 committed Mar 3, 2020
1 parent 0b42f81 commit d40e1c9
Show file tree
Hide file tree
Showing 5 changed files with 543 additions and 446 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ public class TokenVerifier {
private static final Logger LOGGER = LoggerFactory.getLogger(TokenDao.class);

private AuthenticationConfig config;
private TokenDao tokenDao;
private JwkDao jwkDao;

private JwtConsumer consumer;
private PublicJsonWebKey jwk;

@Inject
public TokenVerifier(AuthenticationConfig config, TokenDao tokenDao, JwkDao jwkDao) {
public TokenVerifier(AuthenticationConfig config, JwkDao jwkDao) {
this.config = config;
this.tokenDao = tokenDao;
this.jwkDao = jwkDao;
}

Expand Down Expand Up @@ -83,7 +81,7 @@ public void init() throws NoSuchAlgorithmException, JoseException {
consumer = builder.build();
}

public Optional<String> verifyToken(String token) {
public Optional<String> verifyToken(String token, Optional<Token> tokenRecord) {
try {
final JwtClaims claims = consumer.processToClaims(token);
claims.getSubject();
Expand All @@ -92,12 +90,6 @@ public Optional<String> verifyToken(String token) {
return Optional.empty();
}

Optional<Token> tokenRecord = tokenDao.readByToken(token);
if (!tokenRecord.isPresent()) {
LOGGER.warn("I tried to verify a token but that token doesn't exist.");
return Optional.empty();
}

if (!tokenRecord.get().isEnabled()) {
LOGGER.warn("Someone tried to verify a token that is not enabled.");
return Optional.empty();
Expand Down
Loading

0 comments on commit d40e1c9

Please sign in to comment.