Search in sources :

Example 1 with TokenIdFactory

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

the class SAMLAdapterTest method shouldSerialiseAndDeserialiseToken.

@Test
public void shouldSerialiseAndDeserialiseToken() {
    // Given
    // Need real delegates for this test.
    serialisation = new JSONSerialisation(new ObjectMapper());
    adapter = new SAMLAdapter(new TokenIdFactory(encoding), new JSONSerialisation(new ObjectMapper()), new TokenBlobUtils());
    String tokenId = encoding.encodeKey("badger");
    Token token = new Token(tokenId, TokenType.SAML2);
    // SAML tokens only store time to seconds resolution
    Calendar now = Calendar.getInstance();
    now.set(Calendar.MILLISECOND, 0);
    token.setExpiryTimestamp(now);
    // SAML implementation detail around stored object
    String blob = "woodland forrest";
    token.setBlob(serialisation.serialise(blob).getBytes());
    token.setAttribute(SAMLTokenField.OBJECT_CLASS.getField(), String.class.getName());
    // SAML detail for secondary key
    String secondaryKey = encoding.encodeKey("weasel");
    token.setAttribute(SAMLTokenField.SECONDARY_KEY.getField(), secondaryKey);
    // When
    Token result = adapter.toToken(adapter.fromToken(token));
    // Then
    TokenTestUtils.assertTokenEquals(result, token);
}
Also used : JSONSerialisation(org.forgerock.openam.cts.utils.JSONSerialisation) Calendar(java.util.Calendar) TokenIdFactory(org.forgerock.openam.cts.api.tokens.TokenIdFactory) SAMLToken(org.forgerock.openam.cts.api.tokens.SAMLToken) Token(org.forgerock.openam.cts.api.tokens.Token) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TokenBlobUtils(org.forgerock.openam.cts.utils.blob.TokenBlobUtils) Test(org.testng.annotations.Test)

Example 2 with TokenIdFactory

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

the class OAuthAdapterTest method generateOAuthAdapter.

/**
     * @return Makes a standard OAuthAdapter with real dependencies.
     */
private OAuthAdapter generateOAuthAdapter() {
    JSONSerialisation serialisation = new JSONSerialisation(new ObjectMapper());
    KeyConversion keyConversion = new KeyConversion();
    OAuthValues oAuthValues = new OAuthValues();
    TokenBlobUtils blobUtils = new TokenBlobUtils();
    return new OAuthAdapter(new TokenIdFactory(keyConversion), serialisation, oAuthValues, blobUtils);
}
Also used : JSONSerialisation(org.forgerock.openam.cts.utils.JSONSerialisation) KeyConversion(org.forgerock.openam.cts.utils.KeyConversion) TokenIdFactory(org.forgerock.openam.cts.api.tokens.TokenIdFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TokenBlobUtils(org.forgerock.openam.cts.utils.blob.TokenBlobUtils)

Example 3 with TokenIdFactory

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

the class SessionAdapterTest method setup.

@BeforeMethod
public void setup() {
    tokenIdFactory = mock(TokenIdFactory.class);
    coreTokenConfig = mock(CoreTokenConfig.class);
    jsonSerialisation = mock(JSONSerialisation.class);
    blobUtils = new TokenBlobUtils();
    adapter = new SessionAdapter(tokenIdFactory, coreTokenConfig, jsonSerialisation, blobUtils);
}
Also used : CoreTokenConfig(org.forgerock.openam.cts.CoreTokenConfig) JSONSerialisation(org.forgerock.openam.cts.utils.JSONSerialisation) TokenIdFactory(org.forgerock.openam.cts.api.tokens.TokenIdFactory) TokenBlobUtils(org.forgerock.openam.cts.utils.blob.TokenBlobUtils) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with TokenIdFactory

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

the class SAMLAdapterTest method setup.

@BeforeMethod
public void setup() {
    serialisation = mock(JSONSerialisation.class);
    tokenIdFactory = mock(TokenIdFactory.class);
    blobUtils = mock(TokenBlobUtils.class);
    encoding = new KeyConversion();
    adapter = new SAMLAdapter(tokenIdFactory, serialisation, blobUtils);
}
Also used : JSONSerialisation(org.forgerock.openam.cts.utils.JSONSerialisation) KeyConversion(org.forgerock.openam.cts.utils.KeyConversion) TokenIdFactory(org.forgerock.openam.cts.api.tokens.TokenIdFactory) TokenBlobUtils(org.forgerock.openam.cts.utils.blob.TokenBlobUtils) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

TokenIdFactory (org.forgerock.openam.cts.api.tokens.TokenIdFactory)4 JSONSerialisation (org.forgerock.openam.cts.utils.JSONSerialisation)4 TokenBlobUtils (org.forgerock.openam.cts.utils.blob.TokenBlobUtils)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 KeyConversion (org.forgerock.openam.cts.utils.KeyConversion)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Calendar (java.util.Calendar)1 CoreTokenConfig (org.forgerock.openam.cts.CoreTokenConfig)1 SAMLToken (org.forgerock.openam.cts.api.tokens.SAMLToken)1 Token (org.forgerock.openam.cts.api.tokens.Token)1 Test (org.testng.annotations.Test)1