org.trustedanalytics.user.secure.serializer.HashedStringRedisSerializer.java Source code

Java tutorial

Introduction

Here is the source code for org.trustedanalytics.user.secure.serializer.HashedStringRedisSerializer.java

Source

/**
 *  Copyright(c)2016 IntelCorporation
 *
 *  LicensedundertheApacheLicense,Version2.0(the"License");
 *  youmaynotusethisfileexceptincompliancewiththeLicense.
 *  YoumayobtainacopyoftheLicenseat
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unlessrequiredbyapplicablelaworagreedtoinwriting,software
 *  distributedundertheLicenseisdistributedonan"ASIS"BASIS,
 *  WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
 *  SeetheLicenseforthespecificlanguagegoverningpermissionsand
 *  limitationsundertheLicense.
 */

package org.trustedanalytics.user.secure.serializer;

import org.apache.commons.lang.NotImplementedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.trustedanalytics.user.secure.EncryptionService;

public class HashedStringRedisSerializer extends StringRedisSerializer {

    private EncryptionService encryptionService;

    @Autowired
    public HashedStringRedisSerializer(EncryptionService encryptionService) {
        super();
        this.encryptionService = encryptionService;
    }

    @Override
    public String deserialize(byte[] bytes) {
        throw new NotImplementedException("Hashed value cannot be deserialized");
    }

    @Override
    public byte[] serialize(String string) {
        return super.serialize(hash(string));
    }

    private String hash(String key) {
        return encryptionService.hash(key);
    }
}