use of nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException in project timbuctoo by HuygensING.
the class LocalUserCreatorTest method createThrowsAUserCreationExceptionWhenTheAuthorizationCreatorThrowsAnAuthorizationCreationException.
@Test(expected = UserCreationException.class)
public void createThrowsAUserCreationExceptionWhenTheAuthorizationCreatorThrowsAnAuthorizationCreationException() throws Exception {
Mockito.doThrow(new AuthorizationCreationException("")).when(authorizationCreator).createAuthorization(anyString(), any(User.class), anyString());
instance.create(userInfo);
}
use of nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException in project timbuctoo by HuygensING.
the class DataSetRepository method createDataSet.
public DataSet createDataSet(User user, String dataSetId) throws DataStoreCreationException, IllegalDataSetNameException {
// The ownerId might not be valid (i.e. a safe string). We make it safe here:
// dataSetId is under the control of the user so we simply throw if it's not valid
String ownerPrefix = "u" + user.getPersistentId();
final String baseUri = rdfIdHelper.dataSetBaseUri(ownerPrefix, dataSetId);
String uriPrefix;
if (!baseUri.endsWith("/") && !baseUri.endsWith("#") && !baseUri.endsWith("?")) {
// #boo&foo=bar
if (baseUri.contains("#") || baseUri.contains("?")) {
if (baseUri.endsWith("&")) {
uriPrefix = baseUri;
} else {
uriPrefix = baseUri + "&";
}
} else {
uriPrefix = baseUri + "/";
}
} else {
uriPrefix = baseUri;
}
final DataSetMetaData dataSet = new BasicDataSetMetaData(ownerPrefix, dataSetId, baseUri, uriPrefix, false, publicByDefault);
try {
dataStorage.getDataSetStorage(ownerPrefix, dataSetId).saveMetaData(dataSet);
} catch (DataStorageSaveException e) {
throw new DataStoreCreationException(e);
}
synchronized (dataSetMap) {
Map<String, DataSet> userDataSets = dataSetMap.computeIfAbsent(ownerPrefix, key -> new HashMap<>());
if (!userDataSets.containsKey(dataSetId)) {
try {
permissionFetcher.initializeOwnerAuthorization(user, dataSet.getOwnerId(), dataSet.getDataSetId());
userDataSets.put(dataSetId, dataSet(dataSet, executorService, rdfBaseUri, dataStoreFactory, () -> onUpdated.accept(dataSet.getCombinedId()), dataStorage.getDataSetStorage(ownerPrefix, dataSetId)));
} catch (PermissionFetchingException | AuthorizationCreationException | IOException e) {
throw new DataStoreCreationException(e);
}
}
return userDataSets.get(dataSetId);
}
}
use of nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException in project timbuctoo by HuygensING.
the class LocalUserCreator method create.
public void create(Map<String, String> userInfo) throws UserCreationException {
String userPid = userInfo.get(USER_PID);
String userName = userInfo.get(USER_NAME);
String password = userInfo.get(PASSWORD);
String givenName = userInfo.get(GIVEN_NAME);
String surname = userInfo.get(SURNAME);
String emailAddress = userInfo.get(EMAIL_ADDRESS);
String organization = userInfo.get(ORGANIZATION);
String vreId = userInfo.get(VRE_ID);
String vreRole = userInfo.get(VRE_ROLE);
try {
loginCreator.createLogin(userPid, userName, password, givenName, surname, emailAddress, organization);
User user = userCreator.createUser(userPid, emailAddress, givenName, surname, organization);
authorizationCreator.createAuthorization(vreId, user, vreRole);
} catch (LoginCreationException e) {
throw new UserCreationException(e);
} catch (AuthorizationCreationException e) {
throw new UserCreationException(e);
}
}
Aggregations