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"));
}
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)));
}
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));
}
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));
}
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);
}
}
Aggregations