Search in sources :

Example 76 with Token

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

the class TokenMonitoringResultHandlerTest method shouldInvokeStoreOnProcessResults.

@Test
public void shouldInvokeStoreOnProcessResults() {
    Token mockToken = mock(Token.class);
    handler.processResults(mockToken);
    verify(mockStore).addTokenOperation(eq(mockToken), eq(operation), eq(true));
}
Also used : Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 77 with Token

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

the class LdapTokenAttributeConversion method tokenFromEntry.

/**
     * Convert an Entry into a Token.
     *
     * The implication of function is that the Entry contains all the attributes of the
     * Token. If any required attributes are missing, this operation will fail.
     *
     * @param entry A non null Entry.
     *
     * @return A non null Token initialised with the contents of the Entry.
     *
     * @see #mapFromEntry(org.forgerock.opendj.ldap.Entry)
     */
public Token tokenFromEntry(Entry entry) {
    Map<CoreTokenField, Object> map = mapFromEntry(entry);
    String tokenId = (String) map.get(CoreTokenField.TOKEN_ID);
    TokenType type = (TokenType) map.get(CoreTokenField.TOKEN_TYPE);
    Token token = new Token(tokenId, type);
    for (Map.Entry<CoreTokenField, Object> e : map.entrySet()) {
        CoreTokenField key = e.getKey();
        Object value = e.getValue();
        if (Token.isFieldReadOnly(key)) {
            continue;
        }
        token.setAttribute(key, value);
    }
    return token;
}
Also used : TokenType(org.forgerock.openam.tokens.TokenType) CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) Token(org.forgerock.openam.cts.api.tokens.Token) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 78 with Token

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

the class CoreTokenAdapter method query.

/**
     * Queries the persistence layer using the given TokenFilter to constrain the values.
     *
     * @param tokenFilter A non null TokenFilter.
     * @return A non null, possibly empty collection of Tokens that match the Filter.
     *
     * @throws CoreTokenException If there was a problem processing the error or if there
     * was a problem waiting for the response from the processor.
     */
public Collection<Token> query(final TokenFilter tokenFilter) throws CoreTokenException {
    debug("Query: queued with Filter: {0}", tokenFilter);
    ResultHandler<Collection<Token>, CoreTokenException> handler = handlerFactory.getQueryHandler();
    dispatcher.query(tokenFilter, handler);
    try {
        Collection<Token> tokens = handler.getResults();
        for (Token token : tokens) {
            reverseBlobStrategy(token);
        }
        debug("Query: returned {0} Tokens with Filter: {1}", tokens.size(), tokenFilter);
        return tokens;
    } catch (CoreTokenException e) {
        throw new QueryFailedException(tokenFilter, e);
    }
}
Also used : Collection(java.util.Collection) Token(org.forgerock.openam.cts.api.tokens.Token) PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken)

Example 79 with Token

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

the class SAML2CTSPersistentStore method saveSAML2Token.

/**
     * {@inheritDoc}
     */
@Override
public void saveSAML2Token(String primaryKey, String secondaryKey, Object samlObj, long expirationTime) throws SAML2TokenRepositoryException {
    // Save the SAML2 Token.
    try {
        // Perform the Save of the Token to the Token Repository.
        SAMLToken samlToken = new SAMLToken(primaryKey, secondaryKey, expirationTime, samlObj);
        Token token = tokenAdapter.toToken(samlToken);
        persistentStore.createAsync(token);
    } catch (CoreTokenException e) {
        debug.error("SAML2CTSPersistentStore.saveSAML2Token(): failed to save SAML2 " + "token using primary key:" + primaryKey, e);
        throw new SAML2TokenRepositoryException(e.getMessage(), e);
    }
}
Also used : CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) SAMLToken(org.forgerock.openam.cts.api.tokens.SAMLToken) Token(org.forgerock.openam.cts.api.tokens.Token) SAML2TokenRepositoryException(org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException) SAMLToken(org.forgerock.openam.cts.api.tokens.SAMLToken)

Example 80 with Token

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

the class CTSOperationsTest method shouldReadTokenFromCTS.

@Test
public void shouldReadTokenFromCTS() 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);
    SessionInfo mockSessionInfo = mock(SessionInfo.class);
    given(mockInfoFactory.getSessionInfo(eq(mockInternalSession), any(SessionID.class))).willReturn(mockSessionInfo);
    // When
    SessionInfo result = ctsOperations.refresh(mockSession, false);
    // Then
    assertThat(result).isEqualTo(mockSessionInfo);
}
Also used : InternalSession(com.iplanet.dpro.session.service.InternalSession) SessionInfo(com.iplanet.dpro.session.share.SessionInfo) 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