Search in sources :

Example 1 with TokenService

use of io.gravitee.am.gateway.handler.oauth2.service.token.TokenService in project gravitee-access-management by gravitee-io.

the class RevocationServiceTest method shouldNotRevoke_WrongRequestedClientId.

@Test
public void shouldNotRevoke_WrongRequestedClientId() {
    final RevocationTokenRequest revocationTokenRequest = new RevocationTokenRequest("token");
    AccessToken accessToken = new AccessToken("token");
    accessToken.setClientId("client-id");
    Client client = new Client();
    client.setClientId("wrong-client-id");
    when(tokenService.getAccessToken("token", client)).thenReturn(Maybe.just(accessToken));
    TestObserver testObserver = revocationTokenService.revoke(revocationTokenRequest, client).test();
    testObserver.assertNotComplete();
    testObserver.assertError(InvalidGrantException.class);
    verify(tokenService, times(1)).getAccessToken("token", client);
    verify(tokenService, never()).deleteAccessToken(anyString());
    verify(tokenService, never()).getRefreshToken("token", client);
    verify(tokenService, never()).deleteRefreshToken(anyString());
}
Also used : AccessToken(io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken) Client(io.gravitee.am.model.oidc.Client) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 2 with TokenService

use of io.gravitee.am.gateway.handler.oauth2.service.token.TokenService in project gravitee-access-management by gravitee-io.

the class RevocationServiceTest method shouldRevoke_refreshToken.

@Test
public void shouldRevoke_refreshToken() {
    final RevocationTokenRequest revocationTokenRequest = new RevocationTokenRequest("token");
    revocationTokenRequest.setHint(TokenTypeHint.REFRESH_TOKEN);
    Client client = new Client();
    client.setClientId("client-id");
    Token refreshToken = new RefreshToken("token");
    refreshToken.setClientId("client-id");
    when(tokenService.getRefreshToken("token", client)).thenReturn(Maybe.just(refreshToken));
    when(tokenService.deleteRefreshToken("token")).thenReturn(Completable.complete());
    TestObserver testObserver = revocationTokenService.revoke(revocationTokenRequest, client).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(tokenService, times(1)).getRefreshToken("token", client);
    verify(tokenService, times(1)).deleteRefreshToken("token");
    verify(tokenService, never()).getAccessToken("token", client);
    verify(tokenService, never()).deleteAccessToken("token");
}
Also used : RefreshToken(io.gravitee.am.gateway.handler.oauth2.service.token.impl.RefreshToken) AccessToken(io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken) Token(io.gravitee.am.gateway.handler.oauth2.service.token.Token) RefreshToken(io.gravitee.am.gateway.handler.oauth2.service.token.impl.RefreshToken) Client(io.gravitee.am.model.oidc.Client) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 3 with TokenService

use of io.gravitee.am.gateway.handler.oauth2.service.token.TokenService in project gravitee-access-management by gravitee-io.

the class RevocationServiceTest method shouldRevoke_accessToken.

@Test
public void shouldRevoke_accessToken() {
    final RevocationTokenRequest revocationTokenRequest = new RevocationTokenRequest("token");
    Client client = new Client();
    client.setClientId("client-id");
    AccessToken accessToken = new AccessToken("token");
    accessToken.setClientId("client-id");
    when(tokenService.getAccessToken("token", client)).thenReturn(Maybe.just(accessToken));
    when(tokenService.deleteAccessToken("token")).thenReturn(Completable.complete());
    TestObserver testObserver = revocationTokenService.revoke(revocationTokenRequest, client).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(tokenService, times(1)).getAccessToken("token", client);
    verify(tokenService, times(1)).deleteAccessToken("token");
    verify(tokenService, never()).getRefreshToken(anyString(), any());
    verify(tokenService, never()).deleteRefreshToken(anyString());
}
Also used : AccessToken(io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken) Client(io.gravitee.am.model.oidc.Client) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 4 with TokenService

use of io.gravitee.am.gateway.handler.oauth2.service.token.TokenService in project gravitee-access-management by gravitee-io.

the class ExtensionGrantManagerImpl method updateExtensionGrantProvider.

private void updateExtensionGrantProvider(ExtensionGrant extensionGrant) {
    try {
        AuthenticationProvider authenticationProvider = null;
        if (extensionGrant.getIdentityProvider() != null) {
            logger.info("\tLooking for extension grant identity provider: {}", extensionGrant.getIdentityProvider());
            authenticationProvider = identityProviderManager.get(extensionGrant.getIdentityProvider()).blockingGet();
            if (authenticationProvider != null) {
                logger.info("\tExtension grant identity provider: {}, loaded", extensionGrant.getIdentityProvider());
            }
        }
        ExtensionGrantProvider extensionGrantProvider = extensionGrantPluginManager.create(extensionGrant.getType(), extensionGrant.getConfiguration(), authenticationProvider);
        ExtensionGrantGranter extensionGrantGranter = new ExtensionGrantGranter(extensionGrantProvider, extensionGrant, userAuthenticationManager, tokenService, tokenRequestResolver, identityProviderManager, userService);
        // backward compatibility, set min date to the extension grant granter to choose the good one for the old clients
        extensionGrantGranter.setMinDate(minDate);
        ((CompositeTokenGranter) tokenGranter).addTokenGranter(extensionGrant.getId(), extensionGrantGranter);
        extensionGrants.put(extensionGrant.getId(), extensionGrant);
        extensionGrantGranters.put(extensionGrant.getId(), extensionGrantGranter);
    } catch (Exception ex) {
        // failed to load the plugin
        logger.error("An error occurs while initializing the extension grant : {}", extensionGrant.getName(), ex);
        removeExtensionGrant(extensionGrant.getId());
    }
}
Also used : CompositeTokenGranter(io.gravitee.am.gateway.handler.oauth2.service.granter.CompositeTokenGranter) AuthenticationProvider(io.gravitee.am.identityprovider.api.AuthenticationProvider) ExtensionGrantProvider(io.gravitee.am.extensiongrant.api.ExtensionGrantProvider) ExtensionGrantGranter(io.gravitee.am.gateway.handler.oauth2.service.granter.extensiongrant.ExtensionGrantGranter)

Example 5 with TokenService

use of io.gravitee.am.gateway.handler.oauth2.service.token.TokenService in project gravitee-access-management by gravitee-io.

the class CompositeTokenGranter method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    this.tokenRequestResolver.setScopeManager(this.scopeManager);
    addTokenGranter(GrantType.CLIENT_CREDENTIALS, new ClientCredentialsTokenGranter(tokenRequestResolver, tokenService));
    addTokenGranter(GrantType.PASSWORD, new ResourceOwnerPasswordCredentialsTokenGranter(tokenRequestResolver, tokenService, userAuthenticationManager));
    addTokenGranter(GrantType.AUTHORIZATION_CODE, new AuthorizationCodeTokenGranter(tokenRequestResolver, tokenService, authorizationCodeService, userAuthenticationManager, authenticationFlowContextService, environment));
    addTokenGranter(GrantType.REFRESH_TOKEN, new RefreshTokenGranter(tokenRequestResolver, tokenService, userAuthenticationManager));
    addTokenGranter(GrantType.UMA, new UMATokenGranter(tokenService, userAuthenticationManager, permissionTicketService, resourceService, jwtService, domain, rulesEngine, executionContextFactory));
    addTokenGranter(GrantType.CIBA_GRANT_TYPE, new CibaTokenGranter(tokenRequestResolver, tokenService, userAuthenticationManager, authenticationRequestService, domain));
}
Also used : UMATokenGranter(io.gravitee.am.gateway.handler.oauth2.service.granter.uma.UMATokenGranter) ResourceOwnerPasswordCredentialsTokenGranter(io.gravitee.am.gateway.handler.oauth2.service.granter.password.ResourceOwnerPasswordCredentialsTokenGranter) AuthorizationCodeTokenGranter(io.gravitee.am.gateway.handler.oauth2.service.granter.code.AuthorizationCodeTokenGranter) CibaTokenGranter(io.gravitee.am.gateway.handler.oauth2.service.granter.ciba.CibaTokenGranter) ClientCredentialsTokenGranter(io.gravitee.am.gateway.handler.oauth2.service.granter.client.ClientCredentialsTokenGranter) RefreshTokenGranter(io.gravitee.am.gateway.handler.oauth2.service.granter.refresh.RefreshTokenGranter)

Aggregations

AccessToken (io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken)3 Client (io.gravitee.am.model.oidc.Client)3 TestObserver (io.reactivex.observers.TestObserver)3 Test (org.junit.Test)3 ExtensionGrantProvider (io.gravitee.am.extensiongrant.api.ExtensionGrantProvider)1 CompositeTokenGranter (io.gravitee.am.gateway.handler.oauth2.service.granter.CompositeTokenGranter)1 CibaTokenGranter (io.gravitee.am.gateway.handler.oauth2.service.granter.ciba.CibaTokenGranter)1 ClientCredentialsTokenGranter (io.gravitee.am.gateway.handler.oauth2.service.granter.client.ClientCredentialsTokenGranter)1 AuthorizationCodeTokenGranter (io.gravitee.am.gateway.handler.oauth2.service.granter.code.AuthorizationCodeTokenGranter)1 ExtensionGrantGranter (io.gravitee.am.gateway.handler.oauth2.service.granter.extensiongrant.ExtensionGrantGranter)1 ResourceOwnerPasswordCredentialsTokenGranter (io.gravitee.am.gateway.handler.oauth2.service.granter.password.ResourceOwnerPasswordCredentialsTokenGranter)1 RefreshTokenGranter (io.gravitee.am.gateway.handler.oauth2.service.granter.refresh.RefreshTokenGranter)1 UMATokenGranter (io.gravitee.am.gateway.handler.oauth2.service.granter.uma.UMATokenGranter)1 Token (io.gravitee.am.gateway.handler.oauth2.service.token.Token)1 RefreshToken (io.gravitee.am.gateway.handler.oauth2.service.token.impl.RefreshToken)1 AuthenticationProvider (io.gravitee.am.identityprovider.api.AuthenticationProvider)1