use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenServiceIntegrationTest method shouldUpdateLastUsedTimeToDB.
@Test
public void shouldUpdateLastUsedTimeToDB() {
AccessToken createdToken = accessTokenService.create("This is my first Token", "BOB", authConfigId);
final AccessToken fetchedFromDB = accessTokenService.find(createdToken.getId(), createdToken.getUsername());
assertThat(fetchedFromDB.getLastUsed()).isNull();
accessTokenService.updateLastUsedCacheWith(createdToken);
accessTokenService.onTimer();
final AccessToken accessToken = accessTokenService.find(createdToken.getId(), createdToken.getUsername());
assertThat(accessToken.getLastUsed()).isNotNull();
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenServiceIntegrationTest method shouldGetAccessTokenProvidedTokenValue.
@Test
public void shouldGetAccessTokenProvidedTokenValue() {
String tokenDescription = "This is my first Token";
AccessToken.AccessTokenWithDisplayValue createdToken = accessTokenService.create(tokenDescription, "bob", authConfigId);
String accessTokenInString = createdToken.getDisplayValue();
AccessToken fetchedToken = accessTokenService.findByAccessToken(accessTokenInString);
assertThat(fetchedToken).isEqualTo(createdToken);
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDao method revokeTokensBecauseOfUserDelete.
@Override
public void revokeTokensBecauseOfUserDelete(Collection<String> usernames, String byWhom) {
transactionTemplate.execute(status -> {
Session currentSession = sessionFactory.getCurrentSession();
usernames.stream().flatMap(username -> findAllTokensForUser(username, AccessTokenFilter.all).stream()).forEach(accessToken -> {
accessToken.revokeBecauseOfUserDelete(byWhom, clock.currentTimestamp());
currentSession.saveOrUpdate(accessToken);
});
return Boolean.TRUE;
});
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AbstractUserAccessTokenControllerV1 method getAllAccessTokens.
public String getAllAccessTokens(Request request, Response response) throws Exception {
String filterValue = request.queryParams("filter");
AccessTokenFilter filter = AccessTokenFilter.fromString(filterValue);
if (filter == null) {
throw HaltApiResponses.haltBecauseQueryParamIsUnknown("filter", filterValue, Arrays.stream(AccessTokenFilter.values()).map(Object::toString).toArray(String[]::new));
}
List<AccessToken> allTokens = allTokens(filter);
return writerForTopLevelObject(request, response, outputWriter -> AccessTokensRepresenter.toJSON(outputWriter, urlContext(), allTokens));
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AbstractUserAccessTokenControllerV1 method revokeAccessToken.
public String revokeAccessToken(Request request, Response response) throws Exception {
long id = Long.parseLong(request.params(":id"));
final JsonReader reader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
String revokeCause = reader.optString("revoke_cause").orElse(null);
AccessToken revokeAccessToken = accessTokenService.revokeAccessToken(id, currentUsernameString(), revokeCause);
return renderAccessToken(request, response, revokeAccessToken);
}
Aggregations