Package com.sparc.knappsack.components.entities

Source Code of com.sparc.knappsack.components.entities.S3StorageConfiguration

package com.sparc.knappsack.components.entities;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.jasypt.util.text.BasicTextEncryptor;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Transient;

/**
* S3StorageConfiguration contains the account settings in order to store files in Amazon's S3 storage service.
* @see StorageConfiguration
*/
@Entity
@DiscriminatorValue("S3")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class S3StorageConfiguration extends StorageConfiguration {

    private static final long serialVersionUID = -4486931189704366819L;

    @Transient
    private static final String HASH_KEY = "3kLZX^ZF$B";

    @Transient
    private BasicTextEncryptor encryptor;

    @Column(name = "BUCKET_NAME")
    private String bucketName;

    @Column(name = "ACCESS_KEY")
    private String accessKey;

    @Column(name = "SECRET_KEY")
    private String secretKey;

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return decrypt(this.secretKey);
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = encrypt(secretKey);
    }

    private String encrypt(String message) {
        return getEncryptor().encrypt(message);
    }

    private String decrypt(String message) {
        return getEncryptor().decrypt(message);
    }

    private BasicTextEncryptor getEncryptor() {
        if (encryptor == null) {
            encryptor = new BasicTextEncryptor();
            encryptor.setPassword(this.getUuid() + HASH_KEY);
        }
        return encryptor;
    }


}
TOP

Related Classes of com.sparc.knappsack.components.entities.S3StorageConfiguration

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.