Search in sources :

Example 81 with Token

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

the class CTSOperationsTest method shouldInvokeRemoteActionDuringSetProperty.

@Test
public void shouldInvokeRemoteActionDuringSetProperty() throws SessionException, CoreTokenException {
    // Given
    String name = "name";
    String value = "value";
    SessionID mockSessionID = mock(SessionID.class);
    given(mockSession.getID()).willReturn(mockSessionID);
    Token mockToken = mock(Token.class);
    given(mockCTS.read(anyString())).willReturn(mockToken);
    InternalSession mockInternalSession = mock(InternalSession.class);
    given(mockAdapter.fromToken(eq(mockToken))).willReturn(mockInternalSession);
    // When
    ctsOperations.setProperty(mockSession, name, value);
    // Then
    verify(mockRemote).setProperty(mockSession, name, value);
}
Also used : InternalSession(com.iplanet.dpro.session.service.InternalSession) Token(org.forgerock.openam.cts.api.tokens.Token) Mockito.anyString(org.mockito.Mockito.anyString) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

Example 82 with Token

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

the class CTSOperationsTest method shouldResetLastAccessTimeRemotely.

@Test
public void shouldResetLastAccessTimeRemotely() throws CoreTokenException, SessionException {
    // Given
    Token mockToken = mock(Token.class);
    given(mockCTS.read(anyString())).willReturn(mockToken);
    InternalSession mockInternalSession = mock(InternalSession.class);
    given(mockAdapter.fromToken(eq(mockToken))).willReturn(mockInternalSession);
    // When
    ctsOperations.refresh(mockSession, true);
    // Then
    verify(mockRemote).refresh(mockSession, true);
}
Also used : InternalSession(com.iplanet.dpro.session.service.InternalSession) Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 83 with Token

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

the class LdapQueryBuilderTest method shouldReturnTokensFromSearch.

@Test
public void shouldReturnTokensFromSearch() throws CoreTokenException {
    // Given
    final Collection<Entry> entries = new LinkedList<Entry>();
    entries.add(new LinkedHashMapEntry());
    entries.add(new LinkedHashMapEntry());
    // Slightly more fiddly mocking to provide behaviour when the mock is called.
    given(searchHandler.performSearch(any(Connection.class), any(SearchRequest.class), any(Collection.class))).will(new Answer() {

        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            Collection<Entry> list = (Collection<Entry>) invocationOnMock.getArguments()[2];
            list.addAll(entries);
            return null;
        }
    });
    // Ensure that the Token Conversion returns a Token
    given(tokenEntryConverter.convert(any(Entry.class), any(String[].class))).willReturn(new Token(Long.toString(System.currentTimeMillis()), TokenType.SESSION));
    // When
    Iterator<Collection<Token>> results = builder.execute(mockConnection);
    // Then
    verifyZeroInteractions(tokenEntryConverter);
    assertThat(results.next().size()).isEqualTo(entries.size());
    verify(tokenEntryConverter, times(2)).convert(any(Entry.class), any(String[].class));
}
Also used : SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) Connection(org.forgerock.opendj.ldap.Connection) PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) Token(org.forgerock.openam.cts.api.tokens.Token) LinkedList(java.util.LinkedList) Answer(org.mockito.stubbing.Answer) LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) Entry(org.forgerock.opendj.ldap.Entry) LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Collection(java.util.Collection) Test(org.testng.annotations.Test)

Example 84 with Token

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");
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) JsonValue(org.forgerock.json.JsonValue) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Token(org.forgerock.openam.cts.api.tokens.Token) SSOToken(com.iplanet.sso.SSOToken) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Example 85 with Token

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

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