Search in sources :

Example 1 with TokenBlobUtils

use of org.forgerock.openam.cts.utils.blob.TokenBlobUtils 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 TokenBlobUtils

use of org.forgerock.openam.cts.utils.blob.TokenBlobUtils in project OpenAM by OpenRock.

the class SessionAdapterTest method shouldFilterLatestAccessTime.

@Test
public void shouldFilterLatestAccessTime() throws CoreTokenException {
    // Given
    Token token = new Token("badger", TokenType.SESSION);
    String latestAccessTime = "\"latestAccessTime\":1376308558,";
    String someJSONLikeText = "{\"clientDomain\":null,\"creationTime\":1376307674,\"isISStored\":true," + latestAccessTime + "\"maxCachingTime\":3}";
    token.setBlob(someJSONLikeText.getBytes());
    TokenBlobUtils utils = new TokenBlobUtils();
    // When
    adapter.filterLatestAccessTime(token);
    // Then
    String contents = utils.getBlobAsString(token);
    // Present in the original json text.
    assertTrue(someJSONLikeText.contains(latestAccessTime));
    // Removed in the treated json text.
    assertFalse(contents.contains(latestAccessTime));
}
Also used : Token(org.forgerock.openam.cts.api.tokens.Token) TokenBlobUtils(org.forgerock.openam.cts.utils.blob.TokenBlobUtils) Test(org.testng.annotations.Test)

Example 3 with TokenBlobUtils

use of org.forgerock.openam.cts.utils.blob.TokenBlobUtils 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 4 with TokenBlobUtils

use of org.forgerock.openam.cts.utils.blob.TokenBlobUtils in project OpenAM by OpenRock.

the class AttributeCompressionStrategyTest method setup.

@BeforeMethod
public void setup() {
    blobUtils = new TokenBlobUtils();
    compression = new AttributeCompressionStrategy(blobUtils);
}
Also used : TokenBlobUtils(org.forgerock.openam.cts.utils.blob.TokenBlobUtils) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with TokenBlobUtils

use of org.forgerock.openam.cts.utils.blob.TokenBlobUtils 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)

Aggregations

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