use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class TokenDataStoreTest method testReadNotExisting.
@Test(expectedExceptions = NotFoundException.class)
public void testReadNotExisting() throws Exception {
// Given
final Token token = new Token("123", TokenType.GENERIC);
Object returned = new Object();
final Task task = mock(Task.class);
when(adapter.fromToken(token)).thenReturn(returned);
when(taskFactory.read(anyString(), any(ResultHandler.class))).thenAnswer(new Answer<Task>() {
@Override
public Task answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processResults(null);
return task;
}
});
// When
store.read("123");
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class TokenDataStoreTest method testReadError.
@Test(expectedExceptions = ServerException.class)
public void testReadError() throws Exception {
// Given
final Token token = new Token("123", TokenType.GENERIC);
Object returned = new Object();
final Task task = mock(Task.class);
when(adapter.fromToken(token)).thenReturn(returned);
when(taskFactory.read(anyString(), any(ResultHandler.class))).thenAnswer(new Answer<Task>() {
@Override
public Task answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processError(new Exception());
return task;
}
});
// When
store.read("123");
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class CTSTokenPersistenceImpl method generateToken.
private Token generateToken(String stsId, byte[] tokenBytes, String tokenId, String subjectId, long issueInstantMillis, long tokenLifetimeSeconds, TokenType tokenType) {
final Token ctsToken = new Token(tokenId, org.forgerock.openam.tokens.TokenType.STS);
ctsToken.setAttribute(CoreTokenField.BLOB, tokenBytes);
ctsToken.setAttribute(CoreTokenField.USER_ID, subjectId);
ctsToken.setAttribute(CoreTokenField.EXPIRY_DATE, timeOf(issueInstantMillis + (tokenLifetimeSeconds * 1000)));
ctsToken.setAttribute(CTS_TOKEN_FIELD_STS_ID, stsId);
ctsToken.setAttribute(CTS_TOKEN_FIELD_STS_TOKEN_TYPE, tokenType.name());
return ctsToken;
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class UmaTokenStore method readToken.
public UmaToken readToken(String ticketId, JavaBeanAdapter<? extends UmaToken> adapter) throws NotFoundException {
try {
Token token = cts.read(ticketId);
if (token == null) {
throw new NotFoundException("No valid ticket exists with ticketId");
}
UmaToken ticket = adapter.fromToken(token);
if (!realm.equals(ticket.getRealm())) {
throw new NotFoundException("No valid ticket exists with ticketId in the realm, " + realm);
}
return ticket;
} catch (CoreTokenException e) {
throw new NotFoundException("No valid ticket exists with ticketId");
}
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class OpenAMOpenIDConnectProvider method destroySession.
/**
* {@inheritDoc}
*/
public void destroySession(String opsId) throws ServerException {
try {
final Token opsToken = cts.read(opsId);
if (opsToken == null) {
throw new CoreTokenException("Unable to find id_token");
}
JsonValue idTokenUserSessionToken = tokenAdapter.fromToken(opsToken);
cts.delete(opsId);
String sessionId = idTokenUserSessionToken.get(OAuth2Constants.JWTTokenParams.LEGACY_OPS).asSet(String.class).iterator().next();
// for some grant type, there is no OpenAM session associated with a id_token
if (sessionId != null) {
final SSOToken token = tokenManager.createSSOToken(sessionId);
tokenManager.destroyToken(token);
}
} catch (CoreTokenException e) {
logger.error("Unable to get id_token meta data", e);
throw new ServerException("Unable to get id_token meta data");
} catch (Exception e) {
logger.error("Unable to get SsoTokenManager", e);
throw new ServerException("Unable to get SsoTokenManager");
}
}
Aggregations