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);
}
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);
}
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;
}
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;
}
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());
}
Aggregations