Search in sources :

Example 1 with TokenRestrictionsBO

use of com.nexblocks.authguard.service.model.TokenRestrictionsBO in project AuthGuard by AuthGuard.

the class AuthorizationCodeToAccessToken method generateToken.

private Either<Exception, AuthResponseBO> generateToken(final AccountTokenDO accountToken) {
    final TokenOptionsBO options = TokenOptionsBO.builder().source("aut_code").build();
    final TokenRestrictionsBO restrictions = getRestrictions(accountToken);
    return accountsServiceAdapter.getAccount(accountToken.getAssociatedAccountId()).map(account -> accessTokenProvider.generateToken(account, restrictions, options));
}
Also used : TokenOptionsBO(com.nexblocks.authguard.service.model.TokenOptionsBO) TokenRestrictionsBO(com.nexblocks.authguard.service.model.TokenRestrictionsBO)

Example 2 with TokenRestrictionsBO

use of com.nexblocks.authguard.service.model.TokenRestrictionsBO in project AuthGuard by AuthGuard.

the class JwtPermissionsMapperTest method map.

@Test
void map() {
    final AccountBO account = AccountBO.builder().permissions(Arrays.asList(PermissionBO.builder().group("test").name("read").build(), PermissionBO.builder().group("test").name("write").build(), PermissionBO.builder().group("test").name("nothing").build())).build();
    final TokenRestrictionsBO restrictions = TokenRestrictionsBO.builder().addPermissions("test:read", "test:nothing").build();
    final String[] expected = new String[] { "test:read", "test:nothing" };
    final String[] actual = JwtPermissionsMapper.map(account, restrictions);
    assertThat(Arrays.asList(actual)).isEqualTo(Arrays.asList(expected));
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) TokenRestrictionsBO(com.nexblocks.authguard.service.model.TokenRestrictionsBO) Test(org.junit.jupiter.api.Test)

Example 3 with TokenRestrictionsBO

use of com.nexblocks.authguard.service.model.TokenRestrictionsBO in project AuthGuard by AuthGuard.

the class JwtPermissionsMapperTest method mapNoPermissionRestrictions.

@Test
void mapNoPermissionRestrictions() {
    final AccountBO account = AccountBO.builder().permissions(Arrays.asList(PermissionBO.builder().group("test").name("read").build(), PermissionBO.builder().group("test").name("write").build(), PermissionBO.builder().group("test").name("nothing").build())).build();
    final TokenRestrictionsBO restrictions = TokenRestrictionsBO.builder().build();
    final String[] expected = new String[] { "test:read", "test:write", "test:nothing" };
    final String[] actual = JwtPermissionsMapper.map(account, restrictions);
    assertThat(Arrays.asList(actual)).isEqualTo(Arrays.asList(expected));
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) TokenRestrictionsBO(com.nexblocks.authguard.service.model.TokenRestrictionsBO) Test(org.junit.jupiter.api.Test)

Aggregations

TokenRestrictionsBO (com.nexblocks.authguard.service.model.TokenRestrictionsBO)3 AccountBO (com.nexblocks.authguard.service.model.AccountBO)2 Test (org.junit.jupiter.api.Test)2 TokenOptionsBO (com.nexblocks.authguard.service.model.TokenOptionsBO)1