Search in sources :

Example 1 with TokenStrategyFailedException

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

the class CompressionStrategy method reverse.

/**
     * Decompress the Tokens binary object.
     *
     * @param blob Non null Token to modify.
     *
     * @throws TokenStrategyFailedException {@inheritDoc}
     */
@Override
public byte[] reverse(byte[] blob) throws TokenStrategyFailedException {
    Reject.ifNull(blob);
    final int lengthGuess = blob.length * 2;
    final ByteArrayOutputStream bout = new ByteArrayOutputStream(lengthGuess);
    try {
        GZIPInputStream inputStream = new GZIPInputStream(new ByteArrayInputStream(blob));
        IOUtils.copy(inputStream, bout);
        inputStream.close();
    } catch (IOException e) {
        throw new TokenStrategyFailedException(e);
    }
    return bout.toByteArray();
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TokenStrategyFailedException(org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException)

Example 2 with TokenStrategyFailedException

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

the class CompressionStrategy method perform.

/**
     * Compress the Tokens binary object.
     *
     * @param blob Non null Token to modify.
     *
     * @throws TokenStrategyFailedException {@inheritDoc}
     */
@Override
public byte[] perform(byte[] blob) throws TokenStrategyFailedException {
    Reject.ifNull(blob);
    final ByteArrayOutputStream bout = new ByteArrayOutputStream(blob.length);
    try {
        final GZIPOutputStream out = new GZIPOutputStream(bout);
        out.write(blob);
        out.flush();
        out.close();
    } catch (IOException e) {
        throw new TokenStrategyFailedException(e);
    }
    return bout.toByteArray();
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TokenStrategyFailedException(org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException)

Example 3 with TokenStrategyFailedException

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

the class CoreTokenAdapter method attributeQuery.

/**
     * Queries the persistence layer using the given TokenFilter which must have the required
     * 'return attributes' defined within it. The results of this query will consist of PartialTokens
     * that match the requested CoreTokenFields.
     *
     * @see TokenFilter#addReturnAttribute(org.forgerock.openam.tokens.CoreTokenField)
     * @see org.forgerock.openam.tokens.CoreTokenField
     *
     * @param filter Non null TokenFilter with return attributes defined.
     * @return Non null, but possibly empty results.
     * @throws CoreTokenException If there was an error performing the query.
     * @throws IllegalArgumentException If the filter did not define any Return Fields.
     */
public Collection<PartialToken> attributeQuery(final TokenFilter filter) throws CoreTokenException, IllegalArgumentException {
    ResultHandler<Collection<PartialToken>, CoreTokenException> handler = handlerFactory.getPartialQueryHandler();
    try {
        attributeQueryWithHandler(filter, handler);
        Collection<PartialToken> partialTokens = handler.getResults();
        Collection<PartialToken> results = new ArrayList<PartialToken>();
        if (filter.getReturnFields().contains(CoreTokenField.BLOB)) {
            for (PartialToken p : partialTokens) {
                try {
                    byte[] value = p.getValue(CoreTokenField.BLOB);
                    results.add(new PartialToken(p, CoreTokenField.BLOB, strategy.reverse(value)));
                } catch (TokenStrategyFailedException e) {
                    throw new CoreTokenException("Failed to reverse Blob strategy", e);
                }
            }
        } else {
            results = partialTokens;
        }
        debug("AttributeQuery: returned {0} Partial Tokens: {1}", results.size(), filter);
        return results;
    } catch (CoreTokenException e) {
        throw new QueryFailedException(filter, e);
    }
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) ArrayList(java.util.ArrayList) Collection(java.util.Collection) TokenStrategyFailedException(org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException)

Aggregations

TokenStrategyFailedException (org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)1