Search in sources :

Example 16 with Client

use of io.gravitee.am.model.oidc.Client in project gravitee-access-management by gravitee-io.

the class IntrospectionTokenServiceTest method shouldIntrospect_validToken_offline_verification.

@Test
public void shouldIntrospect_validToken_offline_verification() {
    final String token = "token";
    final JWT jwt = new JWT();
    jwt.setJti("jti");
    jwt.setDomain("domain");
    jwt.setAud("client");
    final Client client = new Client();
    client.setClientId("client-id");
    when(jwtService.decode(token)).thenReturn(Single.just(jwt));
    when(clientService.findByDomainAndClientId(jwt.getDomain(), jwt.getAud())).thenReturn(Maybe.just(client));
    when(jwtService.decodeAndVerify(token, client)).thenReturn(Single.just(jwt));
    TestObserver testObserver = introspectionTokenService.introspect(token, true).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(accessTokenRepository, never()).findByToken(jwt.getJti());
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) Client(io.gravitee.am.model.oidc.Client) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 17 with Client

use of io.gravitee.am.model.oidc.Client in project gravitee-access-management by gravitee-io.

the class IntrospectionTokenServiceTest method shouldIntrospect_invalidValidToken_token_expired.

@Test
public void shouldIntrospect_invalidValidToken_token_expired() {
    final String token = "token";
    final JWT jwt = new JWT();
    jwt.setJti("jti");
    jwt.setDomain("domain");
    jwt.setAud("client");
    jwt.setIat(Instant.now().minus(1, ChronoUnit.DAYS).getEpochSecond());
    final Client client = new Client();
    client.setClientId("client-id");
    final AccessToken accessToken = new AccessToken();
    accessToken.setExpireAt(new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()));
    when(jwtService.decode(token)).thenReturn(Single.just(jwt));
    when(clientService.findByDomainAndClientId(jwt.getDomain(), jwt.getAud())).thenReturn(Maybe.just(client));
    when(jwtService.decodeAndVerify(token, client)).thenReturn(Single.just(jwt));
    when(accessTokenRepository.findByToken(jwt.getJti())).thenReturn(Maybe.just(accessToken));
    TestObserver testObserver = introspectionTokenService.introspect(token, false).test();
    testObserver.assertError(InvalidTokenException.class);
    verify(accessTokenRepository, times(1)).findByToken(jwt.getJti());
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) AccessToken(io.gravitee.am.repository.oauth2.model.AccessToken) Client(io.gravitee.am.model.oidc.Client) Date(java.util.Date) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 18 with Client

use of io.gravitee.am.model.oidc.Client in project gravitee-access-management by gravitee-io.

the class IntrospectionTokenServiceTest method shouldIntrospect_invalidValidToken_jwt_exception.

@Test
public void shouldIntrospect_invalidValidToken_jwt_exception() {
    final String token = "token";
    final JWT jwt = new JWT();
    jwt.setJti("jti");
    jwt.setDomain("domain");
    jwt.setAud("client");
    jwt.setIat(Instant.now().getEpochSecond());
    final Client client = new Client();
    client.setClientId("client-id");
    when(jwtService.decode(token)).thenReturn(Single.just(jwt));
    when(clientService.findByDomainAndClientId(jwt.getDomain(), jwt.getAud())).thenReturn(Maybe.just(client));
    when(jwtService.decodeAndVerify(token, client)).thenReturn(Single.error(new JWTException("invalid token")));
    TestObserver testObserver = introspectionTokenService.introspect(token, false).test();
    testObserver.assertError(InvalidTokenException.class);
    verify(accessTokenRepository, never()).findByToken(jwt.getJti());
}
Also used : JWTException(io.gravitee.am.common.exception.jwt.JWTException) JWT(io.gravitee.am.common.jwt.JWT) Client(io.gravitee.am.model.oidc.Client) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 19 with Client

use of io.gravitee.am.model.oidc.Client in project gravitee-access-management by gravitee-io.

the class IntrospectionTokenServiceTest method shouldIntrospect_invalidValidToken_token_revoked.

@Test
public void shouldIntrospect_invalidValidToken_token_revoked() {
    final String token = "token";
    final JWT jwt = new JWT();
    jwt.setJti("jti");
    jwt.setDomain("domain");
    jwt.setAud("client");
    jwt.setIat(Instant.now().minus(1, ChronoUnit.DAYS).getEpochSecond());
    final Client client = new Client();
    client.setClientId("client-id");
    when(jwtService.decode(token)).thenReturn(Single.just(jwt));
    when(clientService.findByDomainAndClientId(jwt.getDomain(), jwt.getAud())).thenReturn(Maybe.just(client));
    when(jwtService.decodeAndVerify(token, client)).thenReturn(Single.just(jwt));
    when(accessTokenRepository.findByToken(jwt.getJti())).thenReturn(Maybe.empty());
    TestObserver testObserver = introspectionTokenService.introspect(token, false).test();
    testObserver.assertError(InvalidTokenException.class);
    verify(accessTokenRepository, times(1)).findByToken(jwt.getJti());
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) Client(io.gravitee.am.model.oidc.Client) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 20 with Client

use of io.gravitee.am.model.oidc.Client in project gravitee-access-management by gravitee-io.

the class IntrospectionTokenServiceTest method shouldIntrospect_validToken_offline_verification_timer.

@Test
public void shouldIntrospect_validToken_offline_verification_timer() {
    final String token = "token";
    final JWT jwt = new JWT();
    jwt.setJti("jti");
    jwt.setDomain("domain");
    jwt.setAud("client");
    jwt.setIat(Instant.now().getEpochSecond());
    final Client client = new Client();
    client.setClientId("client-id");
    when(jwtService.decode(token)).thenReturn(Single.just(jwt));
    when(clientService.findByDomainAndClientId(jwt.getDomain(), jwt.getAud())).thenReturn(Maybe.just(client));
    when(jwtService.decodeAndVerify(token, client)).thenReturn(Single.just(jwt));
    TestObserver testObserver = introspectionTokenService.introspect(token, false).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    // repository should not be call because the token is too recent
    verify(accessTokenRepository, never()).findByToken(jwt.getJti());
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) Client(io.gravitee.am.model.oidc.Client) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Aggregations

Client (io.gravitee.am.model.oidc.Client)482 Test (org.junit.Test)351 User (io.gravitee.am.model.User)120 JWT (io.gravitee.am.common.jwt.JWT)81 TestObserver (io.reactivex.observers.TestObserver)71 RoutingContext (io.vertx.reactivex.ext.web.RoutingContext)46 DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)45 JWKSet (io.gravitee.am.model.oidc.JWKSet)43 ApplicationScopeSettings (io.gravitee.am.model.application.ApplicationScopeSettings)42 AuthorizationRequest (io.gravitee.am.gateway.handler.oauth2.service.request.AuthorizationRequest)41 Domain (io.gravitee.am.model.Domain)41 HttpServerRequest (io.vertx.reactivex.core.http.HttpServerRequest)40 WebClient (io.vertx.reactivex.ext.web.client.WebClient)40 Maybe (io.reactivex.Maybe)39 Single (io.reactivex.Single)38 OpenIDProviderMetadata (io.gravitee.am.gateway.handler.oidc.service.discovery.OpenIDProviderMetadata)34 Handler (io.vertx.core.Handler)31 ConstantKeys (io.gravitee.am.common.utils.ConstantKeys)29 JWTService (io.gravitee.am.gateway.handler.common.jwt.JWTService)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)28