use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class OpenAMTokenStore method updateDeviceCode.
@Override
public void updateDeviceCode(DeviceCode code, OAuth2Request request) throws ServerException, NotFoundException, InvalidGrantException {
try {
readDeviceCode(code.getClientId(), code.getDeviceCode(), request);
tokenStore.update(code);
} catch (CoreTokenException e) {
throw new ServerException("Could not update user code state");
}
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class OpenAMTokenStore method readAuthorizationCode.
/**
* {@inheritDoc}
*/
public AuthorizationCode readAuthorizationCode(OAuth2Request request, String code) throws InvalidGrantException, ServerException, NotFoundException {
AuthorizationCode loaded = request.getToken(AuthorizationCode.class);
if (loaded != null) {
return loaded;
}
logger.message("Reading Authorization code: {}", code);
final JsonValue token;
// Read from CTS
try {
token = tokenStore.read(code);
} catch (CoreTokenException e) {
logger.error("Unable to read authorization code corresponding to id: " + code, e);
throw new ServerException("Could not read token from CTS: " + e.getMessage());
}
if (token == null) {
logger.error("Unable to read authorization code corresponding to id: " + code);
throw new InvalidGrantException("The provided access grant is invalid, expired, or revoked.");
}
OpenAMAuthorizationCode authorizationCode = new OpenAMAuthorizationCode(token);
validateTokenRealm(authorizationCode.getRealm(), request);
request.setToken(AuthorizationCode.class, authorizationCode);
return authorizationCode;
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class OpenAMTokenStore method readAccessToken.
/**
* {@inheritDoc}
*/
public AccessToken readAccessToken(OAuth2Request request, String tokenId) throws ServerException, InvalidGrantException, NotFoundException {
AccessToken loaded = request.getToken(AccessToken.class);
if (loaded != null) {
return loaded;
}
logger.message("Reading access token");
JsonValue token;
// Read from CTS
try {
token = tokenStore.read(tokenId);
} catch (CoreTokenException e) {
logger.error("Unable to read access token corresponding to id: " + tokenId, e);
throw new ServerException("Could not read token in CTS: " + e.getMessage());
}
if (token == null) {
logger.error("Unable to read access token corresponding to id: " + tokenId);
throw new InvalidGrantException("Could not read token in CTS");
}
OpenAMAccessToken accessToken = new OpenAMAccessToken(token);
validateTokenRealm(accessToken.getRealm(), request);
request.setToken(AccessToken.class, accessToken);
return accessToken;
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class UmaTokenStore method deletePermissionTicket.
public void deletePermissionTicket(String id) throws NotFoundException, ServerException {
try {
// check token is permission ticket
readPermissionTicket(id);
cts.delete(id);
} catch (CoreTokenException e) {
throw new ServerException("Could not delete token: " + id);
}
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class CoreTokenAdapterTest method shouldReadToken.
@SuppressWarnings("unchecked")
@Test
public void shouldReadToken() throws Exception {
// Given
String tokenId = "badger";
Token token = new Token(tokenId, TokenType.SESSION);
ResultHandler<Token, CoreTokenException> mockResultHandler = mock(ResultHandler.class);
given(mockResultHandler.getResults()).willReturn(token);
given(mockResultHandlerFactory.getReadHandler()).willReturn(mockResultHandler);
// When
Token result = adapter.read(tokenId);
// Then
assertThat(result.getTokenId()).isEqualTo(tokenId);
}
Aggregations