1 package org.kuali.common.util.enc.spring; 2 3 import org.jasypt.util.text.TextEncryptor; 4 import org.kuali.common.util.enc.DefaultEncryptionService; 5 import org.kuali.common.util.enc.EncContext; 6 import org.kuali.common.util.enc.EncryptionService; 7 import org.kuali.common.util.enc.NoOpEncryptionService; 8 import org.kuali.common.util.spring.env.EnvironmentService; 9 import org.kuali.common.util.spring.service.SpringServiceConfig; 10 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.context.annotation.Bean; 12 import org.springframework.context.annotation.Configuration; 13 import org.springframework.context.annotation.Import; 14 15 import com.google.common.base.Optional; 16 17 @Configuration 18 @Import({ SpringServiceConfig.class }) 19 public class DefaultEncryptionServiceConfig implements EncryptionServiceConfig { 20 21 @Autowired 22 EnvironmentService env; 23 24 @Override 25 @Bean 26 public EncryptionService encryptionService() { 27 EncContext context = new EncContext.Builder(env).build(); 28 Optional<TextEncryptor> optional = context.getTextEncryptor(); 29 if (optional.isPresent()) { 30 return new DefaultEncryptionService(optional.get()); 31 } else { 32 return NoOpEncryptionService.INSTANCE; 33 } 34 } 35 }