use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class TaskDispatcherTest method shouldCreate.
@Test
public void shouldCreate() throws Exception {
// Given
Token token = mock(Token.class);
given(token.getTokenId()).willReturn("123");
Task task = mock(Task.class);
given(mockTaskFactory.create(token, mockHandler)).willReturn(task);
// When
queue.create(token, mockHandler);
// Then
verify(mockExecutor).execute("123", task);
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class LdapAdapterTest method shouldPerformUpdate.
@Test
public void shouldPerformUpdate() throws Exception {
// Given
Token first = new Token("weasel", TokenType.OAUTH);
Token second = new Token("badger", TokenType.OAUTH);
Connection mockConnection = mock(Connection.class);
Result successResult = mockSuccessfulResult();
given(mockConnection.modify(any(ModifyRequest.class))).willReturn(successResult);
LdapDataLayerConfiguration config = mock(LdapDataLayerConfiguration.class);
when(config.getTokenStoreRootSuffix()).thenReturn(DN.valueOf("ou=unit-test"));
LDAPDataConversion dataConversion = new LDAPDataConversion();
LdapTokenAttributeConversion conversion = new LdapTokenAttributeConversion(dataConversion, config);
LdapAdapter adapter = new LdapAdapter(conversion, null, null);
// When
adapter.update(mockConnection, first, second);
// Then
verify(mockConnection).modify(any(ModifyRequest.class));
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class TaskDispatcherTest method shouldUpdate.
@Test
public void shouldUpdate() throws Exception {
// Given
Token token = mock(Token.class);
given(token.getTokenId()).willReturn("123");
Task task = mock(Task.class);
given(mockTaskFactory.update(token, mockHandler)).willReturn(task);
// When
queue.update(token, mockHandler);
// Then
verify(mockExecutor).execute("123", task);
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class CTSMonitoringStoreImplTest method shouldAddTokenOperationForSpecificTokenType.
@Test
public void shouldAddTokenOperationForSpecificTokenType() throws InterruptedException {
//Given
Token token = mock(Token.class);
CTSOperation operation = CTSOperation.READ;
TokenType tokenType = TokenType.OAUTH;
boolean successful = true;
given(token.getType()).willReturn(tokenType);
//When
ctsOperationsMonitoringStore.addTokenOperation(token, operation, successful);
//Then
verify(tokenOperationsStore).addTokenOperation(tokenType, operation, successful);
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class CTSTokenPersistenceImpl method persistToken.
@Override
public void persistToken(String stsId, TokenType tokenType, String tokenString, String subjectId, long issueInstantMillis, long tokenLifetimeSeconds) throws CTSTokenPersistenceException {
try {
final String tokenId = ctsTokenIdGenerator.generateTokenId(tokenType, tokenString);
final Token ctsToken = generateToken(stsId, tokenString.getBytes(AMSTSConstants.UTF_8_CHARSET_ID), tokenId, subjectId, issueInstantMillis, tokenLifetimeSeconds, tokenType);
ctsPersistentStore.create(ctsToken);
} catch (TokenIdGenerationException e) {
throw new CTSTokenPersistenceException(e.getCode(), "Exception caught generating id for CTS-persisted " + tokenType + " token: " + e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
throw new CTSTokenPersistenceException(ResourceException.INTERNAL_ERROR, "Exception caught getting byte[] " + "representation of issued " + tokenType + " token for CTS persistence: " + e, e);
} catch (CoreTokenException e) {
throw new CTSTokenPersistenceException(ResourceException.INTERNAL_ERROR, "Exception caught persisting issued " + tokenType + " token in the CTS: " + e.getMessage(), e);
}
}
Aggregations