Search in sources :

Example 26 with TokenType

use of org.forgerock.openam.tokens.TokenType in project OpenAM by OpenRock.

the class TokenOperationsStoreTest method shouldGetAverageOperationsPerPeriodForSpecificTokenType.

@Test
public void shouldGetAverageOperationsPerPeriodForSpecificTokenType() {
    //Given
    TokenType tokenType = TokenType.OAUTH;
    CTSOperation operation = CTSOperation.CREATE;
    OperationStore typeOperationStore = mock(OperationStore.class);
    tokenOperations.put(TokenType.OAUTH, typeOperationStore);
    given(typeOperationStore.getAverageRate(operation)).willReturn(1D);
    //When
    double result = tokenOperationsStore.getAverageOperationsPerPeriod(tokenType, operation);
    //Then
    assertEquals(result, 1D);
}
Also used : CTSOperation(org.forgerock.openam.cts.CTSOperation) TokenType(org.forgerock.openam.tokens.TokenType) Test(org.testng.annotations.Test)

Example 27 with TokenType

use of org.forgerock.openam.tokens.TokenType in project OpenAM by OpenRock.

the class CTSMonitoringStoreImplTest method shouldGetOperationsCumulativeCountForSpecificTokenType.

@Test
public void shouldGetOperationsCumulativeCountForSpecificTokenType() {
    //Given
    TokenType tokenType = TokenType.OAUTH;
    CTSOperation operation = CTSOperation.READ;
    given(tokenOperationsStore.getOperationsCumulativeCount(tokenType, operation)).willReturn(1L);
    //When
    long result = ctsOperationsMonitoringStore.getOperationsCumulativeCount(tokenType, operation);
    //Then
    assertEquals(result, 1);
}
Also used : CTSOperation(org.forgerock.openam.cts.CTSOperation) TokenType(org.forgerock.openam.tokens.TokenType) Test(org.testng.annotations.Test)

Example 28 with TokenType

use of org.forgerock.openam.tokens.TokenType in project OpenAM by OpenRock.

the class LdapTokenAttributeConversion method getEntry.

/**
     * Generate an Entry based on the given Token.
     *
     * @param token Non null Token to base the Entry on.
     *
     * @return An Entry suitable for LDAP operations. Includes the Object Class.
     */
public Entry getEntry(Token token) {
    Entry entry = new LinkedHashMapEntry(generateTokenDN(token));
    addObjectClass(entry);
    for (CoreTokenField field : token.getAttributeNames()) {
        String key = field.toString();
        // Token Type special case is an Enum
        if (CoreTokenField.TOKEN_TYPE.equals(field)) {
            TokenType type = token.getValue(field);
            entry.addAttribute(key, type.name());
            continue;
        }
        if (CoreTokenFieldTypes.isCalendar(field)) {
            Calendar calendar = token.getValue(field);
            String dateString = conversion.toLDAPDate(calendar);
            entry.addAttribute(key, dateString);
        } else if (CoreTokenFieldTypes.isByteArray(field)) {
            byte[] array = token.getValue(field);
            entry.addAttribute(key, array);
        } else if (CoreTokenFieldTypes.isInteger(field)) {
            Integer value = token.getValue(field);
            entry.addAttribute(key, value);
        } else if (CoreTokenFieldTypes.isString(field)) {
            String value = token.getValue(field);
            if (!value.isEmpty()) {
                entry.addAttribute(key, value);
            }
        } else {
            throw new IllegalStateException();
        }
    }
    return entry;
}
Also used : LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) Entry(org.forgerock.opendj.ldap.Entry) TokenType(org.forgerock.openam.tokens.TokenType) LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) Calendar(java.util.Calendar) CoreTokenField(org.forgerock.openam.tokens.CoreTokenField)

Example 29 with TokenType

use of org.forgerock.openam.tokens.TokenType 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 30 with TokenType

use of org.forgerock.openam.tokens.TokenType in project OpenAM by OpenRock.

the class CtsCRUDOperationsPerTokenTypeEntryImpl method getDAverage.

/**
     * Gets the average rate that the specified CTS operation, on the specified Token type has been made on the CTS.
     *
     * @return The average rate.
     */
@Override
public Long getDAverage() throws SnmpStatusException {
    final TokenType tokenType = getTokenType();
    final CTSOperation operation = getCTSOperation();
    if (tokenType == null || operation == null) {
        throw new InvalidSNMPQueryException();
    }
    return (long) monitoringStore.getAverageOperationsPerPeriod(getTokenType(), getCTSOperation());
}
Also used : CTSOperation(org.forgerock.openam.cts.CTSOperation) TokenType(org.forgerock.openam.tokens.TokenType)

Aggregations

TokenType (org.forgerock.openam.tokens.TokenType)30 Test (org.testng.annotations.Test)22 CTSOperation (org.forgerock.openam.cts.CTSOperation)20 ArrayList (java.util.ArrayList)3 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)2 Token (org.forgerock.openam.cts.api.tokens.Token)2 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)2 CoreTokenField (org.forgerock.openam.tokens.CoreTokenField)2 Calendar (java.util.Calendar)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Entry (org.forgerock.opendj.ldap.Entry)1 LinkedHashMapEntry (org.forgerock.opendj.ldap.LinkedHashMapEntry)1