use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.
the class LoggedInUsersTest method willReturnTheSameUserForATokenEachTime.
@Test
public void willReturnTheSameUserForATokenEachTime() throws Exception {
LoggedInUsers instance = userStoreWithUserA;
String token = instance.userTokenFor("a", "b").get();
User user = instance.userFor(token).get();
User sameUser = instance.userFor(token).get();
assertThat(user, is(sameUser));
}
use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.
the class SingleEntity method delete.
@DELETE
public Response delete(@PathParam("collection") String collectionName, @HeaderParam("Authorization") String authHeader, @PathParam("id") UUIDParam id) {
Optional<User> user;
try {
user = userValidator.getUserFromAccessToken(authHeader);
} catch (UserValidationException e) {
user = Optional.empty();
}
Optional<User> newUser = user;
if (!newUser.isPresent()) {
return Response.status(Response.Status.UNAUTHORIZED).build();
} else {
return transactionEnforcer.executeAndReturn(timbuctooActions -> {
JsonCrudService jsonCrudService = crudServiceFactory.newJsonCrudService(timbuctooActions);
try {
jsonCrudService.delete(collectionName, id.get(), newUser.get());
return commitAndReturn(Response.noContent().build());
} catch (InvalidCollectionException e) {
return rollbackAndReturn(Response.status(Response.Status.NOT_FOUND).entity(jsnO("message", jsn(e.getMessage()))).build());
} catch (NotFoundException e) {
return rollbackAndReturn(Response.status(Response.Status.NOT_FOUND).entity(jsnO("message", jsn("not found"))).build());
} catch (PermissionFetchingException e) {
return rollbackAndReturn(Response.status(Response.Status.FORBIDDEN).entity(jsnO("message", jsn(e.getMessage()))).build());
} catch (IOException e) {
return rollbackAndReturn(Response.status(Response.Status.BAD_REQUEST).entity(jsnO("message", jsn(e.getMessage()))).build());
}
});
}
}
use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.
the class JsonBasedUserStore method saveNew.
@Override
public User saveNew(String displayName, String persistentId) throws AuthenticationUnavailableException {
User nw = User.create(displayName, persistentId);
userAccess.addUser(nw);
return nw;
}
use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.
the class RootQuery method getCollections.
public CollectionMetadataList getCollections(DataSetMetaData input, Optional<User> userOpt) {
final User user = userOpt.orElse(null);
final DataSet dataSet = dataSetRepository.getDataSet(user, input.getOwnerId(), input.getDataSetId()).get();
final TypeNameStore typeNameStore = dataSet.getTypeNameStore();
final List<CollectionMetadata> colls = dataSet.getSchemaStore().getStableTypes().values().stream().map(x -> {
return getCollection(dataSet, typeNameStore, x);
}).collect(Collectors.toList());
return ImmutableCollectionMetadataList.builder().nextCursor(Optional.empty()).prevCursor(Optional.empty()).items(colls).build();
}
use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.
the class DataSetRepositoryTest method removeDataSetRemovesTheDataSetsAuthorizations.
@Test
public void removeDataSetRemovesTheDataSetsAuthorizations() throws Exception {
User user = User.create(null, "user");
final DataSet dataSet = dataSetRepository.createDataSet(user, "dataset");
DataSetMetaData metadata = dataSet.getMetadata();
String owner = metadata.getOwnerId();
given(permissionFetcher.getPermissions(user, metadata)).willReturn(Sets.newHashSet(Permission.ADMIN));
dataSetRepository.removeDataSet(owner, "dataset", user);
verify(permissionFetcher).removeAuthorizations(metadata.getCombinedId());
}
Aggregations