Search in sources :

Example 51 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class LdapAdapterTest method shouldUseConnectionForCreate.

@Test
public void shouldUseConnectionForCreate() throws Exception {
    // Given
    Token token = new Token("badger", TokenType.SESSION);
    Result successResult = mockSuccessfulResult();
    given(mockConnection.add(any(Entry.class))).willReturn(successResult);
    given(mockConversion.getEntry(any(Token.class))).willReturn(mock(Entry.class));
    // When
    adapter.create(mockConnection, token);
    // Then
    verify(mockConnection).add(any(Entry.class));
}
Also used : Entry(org.forgerock.opendj.ldap.Entry) PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) Token(org.forgerock.openam.cts.api.tokens.Token) Result(org.forgerock.opendj.ldap.responses.Result) Test(org.testng.annotations.Test)

Example 52 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class SessionAdapterTest method shouldAssignSessionHandle.

public void shouldAssignSessionHandle() {
    // Given
    long timestamp = 12345l;
    InternalSession mockSession = mock(InternalSession.class);
    SessionID mockSessionID = mock(SessionID.class);
    String sessionId = "badger";
    String sessionHandle = SessionID.SHANDLE_SCHEME_PREFIX + "ferret";
    given(mockSessionID.toString()).willReturn(sessionId);
    given(jsonSerialisation.deserialise(anyString(), any(Class.class))).willReturn(mockSession);
    given(mockSession.getExpirationTime()).willReturn(timestamp);
    given(mockSession.getID()).willReturn(mockSessionID);
    given(mockSession.getSessionHandle()).willReturn(sessionHandle);
    // some additional required mocking
    given(tokenIdFactory.toSessionTokenId(eq(mockSession))).willReturn(sessionId);
    given(jsonSerialisation.serialise(any())).willReturn("");
    // When
    Token token = adapter.toToken(mockSession);
    // Then
    assertThat(token.<String>getValue(SessionTokenField.SESSION_HANDLE.getField())).isEqualTo(sessionHandle);
}
Also used : InternalSession(com.iplanet.dpro.session.service.InternalSession) Token(org.forgerock.openam.cts.api.tokens.Token) SessionID(com.iplanet.dpro.session.SessionID)

Example 53 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class SessionAdapterTest method shouldHandleMissingCommaInBlob.

@Test
public void shouldHandleMissingCommaInBlob() {
    // Given
    String latestAccessTime = "1376308558";
    Token token = new Token("badger", TokenType.SESSION);
    String someJSONLikeText = "{\"latestAccessTime\":" + latestAccessTime + "}";
    token.setBlob(someJSONLikeText.getBytes());
    // When
    String result = adapter.filterLatestAccessTime(token);
    // Then
    assertEquals(result, latestAccessTime);
}
Also used : Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 54 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class SessionAdapterTest method shouldAssignSessionID.

@Test
public void shouldAssignSessionID() {
    // Given
    long timestamp = 12345l;
    InternalSession mockSession = mock(InternalSession.class);
    SessionID mockSessionID = mock(SessionID.class);
    String sessionId = "badger";
    String sessionHandle = SessionID.SHANDLE_SCHEME_PREFIX + "ferret";
    given(mockSessionID.toString()).willReturn(sessionId);
    given(jsonSerialisation.deserialise(anyString(), any(Class.class))).willReturn(mockSession);
    given(mockSession.getExpirationTime()).willReturn(timestamp);
    given(mockSession.getID()).willReturn(mockSessionID);
    given(mockSession.getSessionHandle()).willReturn(sessionHandle);
    // some additional required mocking
    given(tokenIdFactory.toSessionTokenId(eq(mockSession))).willReturn(sessionId);
    given(jsonSerialisation.serialise(any())).willReturn("");
    // When
    Token token = adapter.toToken(mockSession);
    // Then
    assertThat(token.<String>getValue(SessionTokenField.SESSION_ID.getField())).isEqualTo(sessionId);
}
Also used : InternalSession(com.iplanet.dpro.session.service.InternalSession) Token(org.forgerock.openam.cts.api.tokens.Token) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

Example 55 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class SessionAdapterTest method shouldAssignAttributeFromSessionLatestAccessTime.

@Test
public void shouldAssignAttributeFromSessionLatestAccessTime() {
    // Given
    long timestamp = 12345l;
    InternalSession mockSession = mock(InternalSession.class);
    SessionID mockSessionID = mock(SessionID.class);
    String sessionHandle = SessionID.SHANDLE_SCHEME_PREFIX + "ferret";
    given(mockSessionID.toString()).willReturn("badger");
    given(jsonSerialisation.deserialise(anyString(), any(Class.class))).willReturn(mockSession);
    given(mockSession.getExpirationTime()).willReturn(timestamp);
    given(mockSession.getID()).willReturn(mockSessionID);
    given(mockSession.getSessionHandle()).willReturn(sessionHandle);
    // some additional required mocking
    given(tokenIdFactory.toSessionTokenId(eq(mockSession))).willReturn("badger");
    given(jsonSerialisation.serialise(any())).willReturn("");
    // When
    Token token = adapter.toToken(mockSession);
    // Then
    assertThat(token.getExpiryTimestamp()).isNotNull();
}
Also used : InternalSession(com.iplanet.dpro.session.service.InternalSession) Token(org.forgerock.openam.cts.api.tokens.Token) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

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