Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jasypt-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jasypt-spring-boot-parent</artifactId>
<groupId>com.github.ulisesbocchio</groupId>
<version>3.0.6-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>jasypt-maven-plugin</artifactId>
Expand Down
5 changes: 3 additions & 2 deletions jasypt-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-parent</artifactId>
<version>3.0.6-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>jasypt-spring-boot-starter</artifactId>
Expand All @@ -30,6 +30,7 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-rsa</artifactId>
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -50,7 +51,7 @@
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-jupiter</artifactId>
<version>2.0.1</version>
<version>2.1.7</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ default boolean hasError(ClientHttpResponse response) throws IOException {
}

@Override
@SuppressWarnings("removal")
default void handleError(ClientHttpResponse response) throws IOException {
// Do nothing by default
}
Expand Down
2 changes: 1 addition & 1 deletion jasypt-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-parent</artifactId>
<version>3.0.6-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>jasypt-spring-boot</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/**
* <p>EncryptablePropertySource interface.</p>
*
* @param <T> delegate.
*
* @author Ulises Bocchio
* @version $Id: $Id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
* @version $Id: $Id
*/
public enum InterceptionMode {
/**
* Wrapper.
*/
WRAPPER,
/**
* Proxy.
*/
PROXY
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* <p>Annotation that enables Jasypt for properties decryption by annotating {@link org.springframework.context.annotation.Configuration} classes.
* Only one occurrence of this annotation is needed.</p>
* <p>
* <p>&nbsp;</p>
* <p>This works well in conjunction with the {@link org.springframework.context.annotation.PropertySource} annotation.
* For instance:</p>
* <pre>
Expand All @@ -35,7 +35,7 @@
* not only the ones defined with the {@link org.springframework.context.annotation.PropertySource} annotation, but also
* all system properties, command line properties, and those auto-magically picked up from application.properties and application.yml
* if they exist.</p>
* <p>
* <p>&nbsp;</p>
* <p>This Configuration class basically registers a {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor} that wraps all {@link org.springframework.core.env.PropertySource} defined in the {@link org.springframework.core.env.Environment}
* with {@link com.ulisesbocchio.jasyptspringboot.wrapper.EncryptablePropertySourceWrapper} and defines a default {@link org.jasypt.encryption.StringEncryptor} for decrypting properties
* that can be configured through the same properties it wraps.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* will be generated based on the description of the underlying
* resource.
*
* @return name.
*
* @see org.springframework.core.env.PropertySource#getName()
* @see org.springframework.core.io.Resource#getDescription()
*/
Expand All @@ -38,6 +40,8 @@
* examples.
* <p>Each location will be added to the enclosing {@code Environment} as its own
* property source, and in the order declared.
*
* @return value.
*/
String[] value();

Expand All @@ -46,6 +50,8 @@
* ignored.
* <p>{@code true} is appropriate if the properties file is completely optional.
* Default is {@code false}.
*
* @return whether to ignore not found resource.
*/
boolean ignoreResourceNotFound() default false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
@Retention(RetentionPolicy.RUNTIME)
@Import(EncryptablePropertySourceConfiguration.class)
public @interface EncryptablePropertySources {

/**
* EncryptablePropertySource.
*
* @return value.
*/
EncryptablePropertySource[] value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/**
* <p>EncryptablePropertySourceMethodInterceptor class.</p>
*
* @param <T> propertySource delegate.
*
* @author Ulises Bocchio
* @version $Id: $Id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* <p>CachingDelegateEncryptablePropertySource class.</p>
*
* @param <T> propertySource delegate.
*
* @author Sergio.U.Bocchio
* @version $Id: $Id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* with {@link com.ulisesbocchio.jasyptspringboot.wrapper.EncryptablePropertySourceWrapper} and defines a default {@link
* EncryptablePropertyResolver} for decrypting properties
* that can be configured through the same properties it wraps.</p>
* <p>
* <p>&nbsp;</p>
* <p>It takes the lowest precedence so it does not interfere with Spring Boot's own post processors</p>
*
* @author Ulises Bocchio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* bean of type {@link org.jasypt.encryption.StringEncryptor} is present in the Application Context, thus allowing for custom definition if required.</p>
* <p>The default {@link org.jasypt.encryption.StringEncryptor} can be configured through the following properties: </p>
* <table border="1">
* <caption>Table of Defaults</caption>
* <tr>
* <td>Key</td><td>Required</td><td>Default Value</td>
* </tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ public String decrypt(String encryptedMessage) {
return robin(e -> e.decrypt(encryptedMessage));
}

/**
* ThreadSafeStringEncryptor.
*/
public static class ThreadSafeStringEncryptor implements StringEncryptor {
private final StringEncryptor delegate;

/**
* ThreadSafeStringEncryptor.
*
* @param delegate encryptor.
*/
public ThreadSafeStringEncryptor(StringEncryptor delegate) {
this.delegate = delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static String generateBase64EncodedSecretKey() {
/**
* <p>getAESKeyFromPassword.</p>
*
* @param password an array of {@link char} objects
* @param password an array of char objects
* @param saltGenerator a {@link org.jasypt.salt.SaltGenerator} object
* @param iterations a int
* @param algorithm a {@link java.lang.String} object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Resource loadSecretKeyResource() {
/**
* <p>getSecretKeyPasswordChars.</p>
*
* @return an array of {@link char} objects
* @return an array of char objects
*/
public char[] getSecretKeyPasswordChars() {
return secretKeyPassword.toCharArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class AsymmetricCryptography {
private static final String PUBLIC_KEY_HEADER = "-----BEGIN PUBLIC KEY-----";
private static final String PRIVATE_KEY_FOOTER = "-----END PRIVATE KEY-----";
private static final String PUBLIC_KEY_FOOTER = "-----END PUBLIC KEY-----";
private static final String KEYFACTORY_RSA = "RSA";
private static final String CIPHER_RSA = "RSA";
private final ResourceLoader resourceLoader;

/**
Expand Down Expand Up @@ -77,7 +79,7 @@ public PrivateKey getPrivateKey(Resource resource, KeyFormat format) {
keyBytes = decodePem(keyBytes, PRIVATE_KEY_HEADER, PRIVATE_KEY_FOOTER);
}
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
KeyFactory kf = KeyFactory.getInstance(KEYFACTORY_RSA);
return kf.generatePrivate(spec);
}

Expand Down Expand Up @@ -107,40 +109,49 @@ public PublicKey getPublicKey(Resource resource, KeyFormat format) {
keyBytes = decodePem(keyBytes, PUBLIC_KEY_HEADER, PUBLIC_KEY_FOOTER);
}
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
KeyFactory kf = KeyFactory.getInstance(KEYFACTORY_RSA);
return kf.generatePublic(spec);
}

/**
* <p>encrypt.</p>
*
* @param msg an array of {@link byte} objects
* @param msg an array of byte objects
* @param key a {@link java.security.PublicKey} object
* @return an array of {@link byte} objects
* @return an array of byte objects
*/
@SneakyThrows
public byte[] encrypt(byte[] msg, PublicKey key) {
final Cipher cipher = Cipher.getInstance("RSA");
final Cipher cipher = Cipher.getInstance(CIPHER_RSA);
cipher.init(Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(msg);
}

/**
* <p>decrypt.</p>
*
* @param msg an array of {@link byte} objects
* @param msg an array of byte objects
* @param key a {@link java.security.PrivateKey} object
* @return an array of {@link byte} objects
* @return an array of byte objects
*/
@SneakyThrows
public byte[] decrypt(byte[] msg, PrivateKey key) {
final Cipher cipher = Cipher.getInstance("RSA");
final Cipher cipher = Cipher.getInstance(CIPHER_RSA);
cipher.init(Cipher.DECRYPT_MODE, key);
return cipher.doFinal(msg);
}

/**
* Key format.
*/
public enum KeyFormat {
/**
* DER format.
*/
DER,
/**
* PEM format.
*/
PEM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ static public <T> IterableDecorator<T, T> filter(Iterable<T> source, Predicate<T
return new IterableDecorator<>(source, Function.identity(), filter);
}

/**
* IterableDecorator.
*
* @param <U> u.
* @param <T> t.
*/
public static class IterableDecorator<U, T> implements Iterable<T> {
private final Function<U, T> transform;
private final Predicate<U> filter;
Expand All @@ -76,6 +82,13 @@ public static class IteratorDecorator<U, T> implements Iterator<T> {
private final Predicate<U> filter;
private T next = null;

/**
* IteratorDecorator.
*
* @param source source
* @param transform transform
* @param filter filter
*/
public IteratorDecorator(Iterator<U> source, Function<U, T> transform, Predicate<U> filter) {
this.source = source;
this.transform = transform;
Expand All @@ -97,12 +110,10 @@ public T next() {
}

private void maybeFetchNext() {
if (next == null) {
if (source.hasNext()) {
U val = source.next();
if (filter.test(val)) {
next = transform.apply(val);
}
if (next == null && source.hasNext()) {
U val = source.next();
if (filter.test(val)) {
next = transform.apply(val);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* has been initialized or not, but after initialization the instance supplier is changed to avoid extra logic
* execution.
*
* @param <R> supplier.
*
* @author Sergio.U.Bocchio
* @version $Id: $Id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/**
* <p>EncryptableEnumerablePropertySourceWrapper class.</p>
*
* @param <T> encryptableDelegate.
*
* @author Ulises Bocchio
* @version $Id: $Id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* property is encrypted or not using the Jasypt convention of surrounding encrypted values with "ENC()".</p>
* <p>When an encrypted property is detected, it is decrypted using the provided {@link org.jasypt.encryption.StringEncryptor}</p>
*
* @param <T> encryptableDelegate.
*
* @author Ulises Bocchio
* @version $Id: $Id
*/
Expand Down
Loading