Search in sources :

Example 1 with AppBO

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

the class ApiKeysRoute method verify.

@Override
public void verify(final Context context) {
    final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
    final Optional<AppBO> app = apiKeysService.validateApiKey(authenticationRequest.getToken());
    if (app.isPresent()) {
        context.status(200).json(app.get());
    } else {
        context.status(404).json(new Error(ErrorCode.API_KEY_DOES_NOT_EXIST.getCode(), "API key does not exist"));
    }
}
Also used : AppBO(com.nexblocks.authguard.service.model.AppBO) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 2 with AppBO

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

the class JwtApiKeyProviderTest method generateTokenApp.

@Test
void generateTokenApp() {
    final JtiProvider jtiProvider = Mockito.mock(JtiProvider.class);
    final JwtApiKeyProvider tokenProvider = newProviderInstance(jtiProvider);
    final String jti = "tokenId";
    final AppBO app = RANDOM.nextObject(AppBO.class);
    Mockito.when(jtiProvider.next()).thenReturn(jti);
    final AuthResponseBO tokens = tokenProvider.generateToken(app);
    assertThat(tokens).isNotNull();
    assertThat(tokens.getToken()).isNotNull();
    assertThat(tokens.getRefreshToken()).isNull();
    verifyToken(tokens.getToken().toString(), app.getId(), jti);
}
Also used : AppBO(com.nexblocks.authguard.service.model.AppBO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) Test(org.junit.jupiter.api.Test)

Example 3 with AppBO

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

the class ActorDomainVerifier method verifyActorDomain.

public static boolean verifyActorDomain(final Context context, final String domain) {
    if (context.attribute("actor") instanceof AppBO) {
        final AppBO actor = context.attribute("actor");
        final boolean isAuthClient = actor.getRoles().contains(AuthGuardRoles.AUTH_CLIENT);
        if (isAuthClient && !actor.getDomain().equals(domain)) {
            context.status(403).json(new Error("", "An auth client violated its restrictions in the request"));
            return false;
        }
        return true;
    }
    return true;
}
Also used : AppBO(com.nexblocks.authguard.service.model.AppBO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 4 with AppBO

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

the class ApiKeysServiceImplTest method validateApiKey.

@Test
void validateApiKey() {
    final String appId = "app";
    final String key = "key";
    final AppBO app = AppBO.builder().id(appId).build();
    Mockito.when(apiKeyExchange.verifyAndGetAppId(key)).thenReturn(CompletableFuture.completedFuture(Optional.of(appId)));
    Mockito.when(applicationsService.getById(appId)).thenReturn(Optional.of(app));
    final Optional<AppBO> actual = apiKeysService.validateApiKey(key);
    assertThat(actual).contains(app);
}
Also used : AppBO(com.nexblocks.authguard.service.model.AppBO) Test(org.junit.jupiter.api.Test)

Example 5 with AppBO

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

the class ApplicationsServiceImplTest method deactivate.

@Test
void deactivate() {
    final AppDO app = random.nextObject(AppDO.class);
    app.setActive(true);
    Mockito.when(applicationsRepository.getById(app.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(app)));
    Mockito.when(applicationsRepository.update(any())).thenAnswer(invocation -> CompletableFuture.completedFuture(Optional.of(invocation.getArgument(0, AppDO.class))));
    final AppBO updated = applicationsService.deactivate(app.getId()).orElse(null);
    assertThat(updated).isNotNull();
    assertThat(updated.isActive()).isFalse();
}
Also used : AppDO(com.nexblocks.authguard.dal.model.AppDO) AppBO(com.nexblocks.authguard.service.model.AppBO) Test(org.junit.jupiter.api.Test)

Aggregations

AppBO (com.nexblocks.authguard.service.model.AppBO)12 Test (org.junit.jupiter.api.Test)8 AppDO (com.nexblocks.authguard.dal.model.AppDO)4 Error (com.nexblocks.authguard.api.dto.entities.Error)3 ApplicationsRepository (com.nexblocks.authguard.dal.persistence.ApplicationsRepository)2 MessageBus (com.nexblocks.authguard.emb.MessageBus)2 AccountsService (com.nexblocks.authguard.service.AccountsService)2 ApplicationsService (com.nexblocks.authguard.service.ApplicationsService)2 IdempotencyService (com.nexblocks.authguard.service.IdempotencyService)2 ServiceMapper (com.nexblocks.authguard.service.mappers.ServiceMapper)2 ServiceMapperImpl (com.nexblocks.authguard.service.mappers.ServiceMapperImpl)2 AccountBO (com.nexblocks.authguard.service.model.AccountBO)2 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)2 PermissionBO (com.nexblocks.authguard.service.model.PermissionBO)2 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)2 List (java.util.List)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Supplier (java.util.function.Supplier)2 Collectors (java.util.stream.Collectors)2