Java Code Examples for io.vertx.ext.auth.jwt.impl.JWTAuthProviderImpl

The following examples show how to use io.vertx.ext.auth.jwt.impl.JWTAuthProviderImpl. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: besu   Source File: AuthenticationUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void getUserFailsIfTokenDoesNotHaveExpiryClaim() {
  final AuthenticationService authenticationService = mock(AuthenticationService.class);
  final JWTAuth jwtAuth = new JWTAuthProviderImpl(null, new JWTAuthOptions());
  final StubUserHandler handler = new StubUserHandler();
  when(authenticationService.getJwtAuthProvider()).thenReturn(jwtAuth);

  AuthenticationUtils.getUser(
      Optional.of(authenticationService), INVALID_TOKEN_WITHOUT_EXP, handler);

  assertThat(handler.getEvent()).isEmpty();
}
 
Example 2
Source Project: besu   Source File: AuthenticationUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void getUserSucceedsWithValidToken() {
  final AuthenticationService authenticationService = mock(AuthenticationService.class);
  final JWTAuth jwtAuth = new JWTAuthProviderImpl(null, new JWTAuthOptions());
  final StubUserHandler handler = new StubUserHandler();
  when(authenticationService.getJwtAuthProvider()).thenReturn(jwtAuth);

  AuthenticationUtils.getUser(Optional.of(authenticationService), VALID_TOKEN, handler);

  assertThat(handler.getEvent().get().principal())
      .isEqualTo(new JsonObject(VALID_TOKEN_DECODED_PAYLOAD));
}
 
Example 3
Source Project: vertx-auth   Source File: JWTAuth.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a JWT auth provider
 *
 * @param vertx the Vertx instance
 * @param config  the config
 * @return the auth provider
 */
static JWTAuth create(Vertx vertx, JWTAuthOptions config) {
  return new JWTAuthProviderImpl(vertx, config);
}