Search in sources :

Example 21 with User

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

the class MutationHelpers method getDataSet.

public static DataSet getDataSet(DataFetchingEnvironment env, DataSetFetcher fetcher) {
    String dataSetId = env.getArgument("dataSetId");
    Tuple<String, String> userAndDataSet = DataSetMetaData.splitCombinedId(dataSetId);
    User user = getUser(env);
    String ownerId = userAndDataSet.getLeft();
    String dataSetName = userAndDataSet.getRight();
    return fetcher.getDataSet(user, ownerId, dataSetName).orElseThrow(() -> new RuntimeException("Dataset does not exist"));
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User)

Example 22 with User

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

the class DataSetRepositoryTest method createDataSetReturnsTheSamesDataSetForEachCall.

@Test
public void createDataSetReturnsTheSamesDataSetForEachCall() throws Exception {
    DataSet dataSet1 = dataSetRepository.createDataSet(User.create(null, "user"), "dataset");
    DataSet dataSet2 = dataSetRepository.createDataSet(User.create(null, "user"), "dataset");
    assertThat(dataSet1, is(sameInstance(dataSet2)));
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Test(org.junit.Test)

Example 23 with User

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

the class DataSetRepositoryTest method removeDataSetRemovesTheDataSetFromDisk.

@Test
public void removeDataSetRemovesTheDataSetFromDisk() throws Exception {
    User user = User.create(null, "user");
    final DataSet dataSet = dataSetRepository.createDataSet(user, "dataset");
    File dataSetPath = new File(new File(tempFile, dataSet.getMetadata().getOwnerId()), "dataset");
    assertThat(dataSetPath.exists(), is(true));
    given(permissionFetcher.getPermissions(user, dataSet.getMetadata())).willReturn(Sets.newHashSet(Permission.ADMIN));
    dataSetRepository.removeDataSet(dataSet.getMetadata().getOwnerId(), "dataset", user);
    assertThat(dataSetPath.exists(), is(false));
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) File(java.io.File) Test(org.junit.Test)

Example 24 with User

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

the class AuthCheckTest method checkAdminAccessReturnsNullIfTheUserIsAnAdminForTheDataSet.

@Test
public void checkAdminAccessReturnsNullIfTheUserIsAnAdminForTheDataSet() throws Exception {
    User notOwner = User.create(null, "user");
    UserValidator userValidator = mock(UserValidator.class);
    given(userValidator.getUserFromAccessToken(anyString())).willReturn(Optional.of(notOwner));
    PermissionFetcher permissionFetcher = mock(PermissionFetcher.class);
    given(permissionFetcher.getPermissions(any(User.class), any(BasicDataSetMetaData.class))).willReturn(permissionsForAdmin());
    Response response = checkAdminAccess(permissionFetcher, userValidator, "auth", new BasicDataSetMetaData("ownerid", "datasetid", "http://ex.org", "http://example.org/prefix/", false, false));
    assertThat(response.getStatus(), is(200));
}
Also used : Response(javax.ws.rs.core.Response) PermissionFetcher(nl.knaw.huygens.timbuctoo.v5.security.PermissionFetcher) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) UserValidator(nl.knaw.huygens.timbuctoo.v5.security.UserValidator) Test(org.junit.Test)

Example 25 with User

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

the class TwitterUserValidator method getUserFromAccessToken.

@Override
public Optional<User> getUserFromAccessToken(String accessToken) throws UserValidationException {
    String token = accessToken.substring(0, accessToken.indexOf("_"));
    String tokenSecret = accessToken.substring(accessToken.indexOf("_") + 1, accessToken.length());
    if (users.get(token) != null) {
        return Optional.of(users.get(token));
    } else {
        twitter.setOAuthAccessToken(new AccessToken(token, tokenSecret));
        twitter4j.User userTwitter;
        try {
            userTwitter = twitter.showUser(Long.valueOf(twitter.getId()));
        } catch (TwitterException e) {
            return Optional.empty();
        }
        User user = User.create(userTwitter.getName(), userTwitter.getId() + "", userTwitter.getId() + "");
        users.put(token, user);
        return Optional.of(user);
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) AccessToken(twitter4j.auth.AccessToken) TwitterException(twitter4j.TwitterException)

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