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