Search in sources :

Example 1 with Token

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);
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 2 with Token

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));
}
Also used : LdapTokenAttributeConversion(org.forgerock.openam.cts.utils.LdapTokenAttributeConversion) LdapDataLayerConfiguration(org.forgerock.openam.sm.datalayer.impl.ldap.LdapDataLayerConfiguration) Connection(org.forgerock.opendj.ldap.Connection) PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) Token(org.forgerock.openam.cts.api.tokens.Token) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) LDAPDataConversion(org.forgerock.openam.cts.utils.LDAPDataConversion) Result(org.forgerock.opendj.ldap.responses.Result) Test(org.testng.annotations.Test)

Example 3 with Token

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);
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 4 with Token

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);
}
Also used : CTSOperation(org.forgerock.openam.cts.CTSOperation) TokenType(org.forgerock.openam.tokens.TokenType) Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 5 with Token

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);
    }
}
Also used : TokenIdGenerationException(org.forgerock.openam.sts.TokenIdGenerationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Token(org.forgerock.openam.cts.api.tokens.Token) PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) CTSTokenPersistenceException(org.forgerock.openam.sts.CTSTokenPersistenceException)

Aggregations

Token (org.forgerock.openam.cts.api.tokens.Token)86 Test (org.testng.annotations.Test)58 Task (org.forgerock.openam.sm.datalayer.api.Task)17 ResultHandler (org.forgerock.openam.sm.datalayer.api.ResultHandler)16 PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)16 InvocationOnMock (org.mockito.invocation.InvocationOnMock)14 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)13 InternalSession (com.iplanet.dpro.session.service.InternalSession)8 DataLayerException (org.forgerock.openam.sm.datalayer.api.DataLayerException)8 Calendar (java.util.Calendar)7 JsonValue (org.forgerock.json.JsonValue)7 SessionID (com.iplanet.dpro.session.SessionID)6 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)6 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 Entry (org.forgerock.opendj.ldap.Entry)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 SAMLToken (org.forgerock.openam.cts.api.tokens.SAMLToken)4 Connection (org.forgerock.opendj.ldap.Connection)4 LinkedHashMapEntry (org.forgerock.opendj.ldap.LinkedHashMapEntry)4