Search in sources :

Example 26 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.

the class DataSetRepository method publishDataSet.

public void publishDataSet(User user, String ownerId, String dataSetName) throws DataSetPublishException {
    Optional<DataSet> dataSet = getDataSet(user, ownerId, dataSetName);
    try {
        if (dataSet.isPresent() && permissionFetcher.getPermissions(user, dataSet.get().getMetadata()).contains(Permission.ADMIN)) {
            DataSetMetaData dataSetMetaData = dataSet.get().getMetadata();
            dataSetMetaData.publish();
            try {
                dataStorage.getDataSetStorage(ownerId, dataSetName).saveMetaData(dataSetMetaData);
            } catch (DataStorageSaveException e) {
                throw new DataSetPublishException(e);
            }
        }
    } catch (PermissionFetchingException e) {
        throw new DataSetPublishException(e);
    }
}
Also used : DataStorageSaveException(nl.knaw.huygens.timbuctoo.v5.datastorage.exceptions.DataStorageSaveException) DataSetPublishException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetPublishException) PermissionFetchingException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)

Example 27 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User 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);
    }
}
Also used : DataStorageSaveException(nl.knaw.huygens.timbuctoo.v5.datastorage.exceptions.DataStorageSaveException) PermissionFetchingException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) IOException(java.io.IOException) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException) AuthorizationCreationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException)

Example 28 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User 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);
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) UserCreationException(nl.knaw.huygens.timbuctoo.security.exceptions.UserCreationException) LoginCreationException(nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException) AuthorizationCreationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException)

Example 29 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.

the class CreateDataSetMutation method get.

@Override
public Object get(DataFetchingEnvironment environment) {
    User currentUser = getUser(environment);
    String dataSetName = environment.getArgument("dataSetName");
    try {
        return new DataSetWithDatabase(dataSetRepository.createDataSet(currentUser, dataSetName));
    } catch (DataStoreCreationException e) {
        LOG.error("Data set creation exception", e);
        throw new RuntimeException("Data set could not be created");
    } catch (IllegalDataSetNameException e) {
        throw new RuntimeException("Data set id is not supported: " + e.getMessage());
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) MutationHelpers.getUser(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MutationHelpers.getUser) DataSetWithDatabase(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase) IllegalDataSetNameException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.IllegalDataSetNameException) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)

Example 30 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.

the class DeleteDataSetMutation method get.

@Override
public Object get(DataFetchingEnvironment environment) {
    String combinedId = environment.getArgument("dataSetId");
    Tuple<String, String> userAndDataSet = DataSetMetaData.splitCombinedId(combinedId);
    User user = MutationHelpers.getUser(environment);
    try {
        dataSetRepository.removeDataSet(userAndDataSet.getLeft(), userAndDataSet.getRight(), user);
        return new RemovedDataSet(combinedId);
    } catch (IOException e) {
        LOG.error("Data set deletion exception", e);
        throw new RuntimeException("Data set could not be deleted");
    } catch (NotEnoughPermissionsException e) {
        throw new RuntimeException("You do not have enough permissions");
    } catch (DataSetRepository.DataSetDoesNotExistException e) {
        throw new RuntimeException(e.getMessage());
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) NotEnoughPermissionsException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.NotEnoughPermissionsException) DataSetRepository(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository) IOException(java.io.IOException)

Aggregations

User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)42 Test (org.junit.Test)22 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)19 IOException (java.io.IOException)11 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)9 UserValidationException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException)7 PermissionFetchingException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException)6 Path (javax.ws.rs.Path)5 Urlset (nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset)5 ImportStatus (nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus)5 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 GET (javax.ws.rs.GET)4 Response (javax.ws.rs.core.Response)4 BasicDataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 GraphQLSchema (graphql.schema.GraphQLSchema)3 Optional (java.util.Optional)3 DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)3 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)3