001package org.kuali.common.util.enc.spring; 002 003import org.jasypt.util.text.TextEncryptor; 004import org.kuali.common.util.enc.DefaultEncryptionService; 005import org.kuali.common.util.enc.EncContext; 006import org.kuali.common.util.enc.EncryptionService; 007import org.kuali.common.util.enc.NoOpEncryptionService; 008import org.kuali.common.util.spring.env.EnvironmentService; 009import org.kuali.common.util.spring.service.SpringServiceConfig; 010import org.springframework.beans.factory.annotation.Autowired; 011import org.springframework.context.annotation.Bean; 012import org.springframework.context.annotation.Configuration; 013import org.springframework.context.annotation.Import; 014 015import com.google.common.base.Optional; 016 017@Configuration 018@Import({ SpringServiceConfig.class }) 019public class DefaultEncryptionServiceConfig implements EncryptionServiceConfig { 020 021 @Autowired 022 EnvironmentService env; 023 024 @Override 025 @Bean 026 public EncryptionService encryptionService() { 027 EncContext context = new EncContext.Builder(env).build(); 028 Optional<TextEncryptor> optional = context.getTextEncryptor(); 029 if (optional.isPresent()) { 030 return new DefaultEncryptionService(optional.get()); 031 } else { 032 return NoOpEncryptionService.INSTANCE; 033 } 034 } 035}