Skip to content

Commit

Permalink
Upgrade Hiss to version 0.12.0 (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkay1375 authored Jan 3, 2025
1 parent e13e91c commit 0115d0b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
An small library which uses Spring Boot autoconfiguration capability that integrates Hiss with Spring Boot and Spring Data Mongo.

By integrating Hiss with Spring Boot project we mean registration of:
- Hiss bean using `HissPropertiesFromEnvProvider`
- Hiss bean [using environment variables](https://github.com/Tap30/hiss?tab=readme-ov-file#creating-properties-from-environment-variables)
- Mongo interceptor which automatically encrypts objects before saving to DB and decrypts them after loading.

## Quick Start
Expand All @@ -15,18 +15,18 @@ Apache Maven:
<dependency>
<groupId>io.github.tap30</groupId>
<artifactId>hiss-spring-boot-mongo-starter</artifactId>
<version>0.9.8</version>
<version>0.10.0</version>
</dependency>
```

Gradle (Groovy):
```groovy
implementation 'io.github.tap30:hiss-spring-boot-mongo-starter:0.9.8'
implementation 'io.github.tap30:hiss-spring-boot-mongo-starter:0.10.0'
```

Gradle (Kotlin):
```kotlin
implementation("io.github.tap30:hiss-spring-boot-mongo-starter:0.9.8")
implementation("io.github.tap30:hiss-spring-boot-mongo-starter:0.10.0")
```

### 2. Set environment variables
Expand All @@ -42,7 +42,7 @@ HISS_DEFAULT_HASHING_ALGORITHM=hmac-sha256
```

For more information about envs see
[this](https://github.com/Tap30/hiss?tab=readme-ov-file#hisspropertiesfromenvprovider).
[this](https://github.com/Tap30/hiss?tab=readme-ov-file#creating-properties-from-environment-variables).

### 3. Annotate your class with `@Encrypted`

Expand All @@ -63,11 +63,18 @@ Note: Getters and setters must exist as Hiss use them to get/set values.
## Using custom `HissPropertiesProvider`

By implementing `HissPropertiesProvider` and annotating it with `@Component`
this library will pick your implementation rather than default `HissPropertiesFromEnvProvider`.
this library will pick your implementation rather than default one.

## Using custom encryption and hashing algorithms

Just like custom `HissPropertiesProvider` by implementing `Encryptor` and `Hasher` interfaces
and annotating them with `@Component`, this library will pick them up.

For more information about `Encryptor`s and `Hasher`s see [Hiss readme](https://github.com/Tap30/hiss?tab=readme-ov-file#supported-algorithms).

## Querying Data

Currently there is not easy way to support querying encrypted fields.
Currently there is not an easy way to support querying encrypted fields.

To query data, inject Hiss bean (`@Autowired Hiss hiss`)
and use `Hiss$hash(String)` method to generate hash of content;
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.tap30</groupId>
<artifactId>hiss-spring-boot-mongo-starter</artifactId>
<version>0.9.8</version>
<version>0.10.0</version>
<name>Hiss Spring Boot Mongo Starter</name>
<description>Integrates Hiss library with Spring data mongo</description>
<developers>
Expand Down Expand Up @@ -35,7 +35,7 @@
<mockito-junit-jupiter.version>5.11.0</mockito-junit-jupiter.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<jetbrains-annotations.version>24.1.0</jetbrains-annotations.version>
<hiss.version>0.11.1</hiss.version>
<hiss.version>0.12.0</hiss.version>
<spring-boot.version>2.7.18</spring-boot.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@

import io.github.tap30.hiss.Hiss;
import io.github.tap30.hiss.HissFactory;
import io.github.tap30.hiss.HissPropertiesFromEnvProvider;
import io.github.tap30.hiss.HissPropertiesProvider;
import io.github.tap30.hiss.encryptor.Encryptor;
import io.github.tap30.hiss.hasher.Hasher;
import io.github.tap30.hiss.properties.HissProperties;
import io.github.tap30.hiss.properties.HissPropertiesProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;

import java.util.Optional;
import java.util.Set;

@AutoConfiguration
@ConditionalOnClass(Hiss.class)
public class HissSpringBootMongoAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public Hiss hiss(Optional<HissPropertiesProvider> optionalHissPropertiesProvider) {
var hissPropertiesProvider = optionalHissPropertiesProvider
.orElse(new HissPropertiesFromEnvProvider());
return HissFactory.createHiss(hissPropertiesProvider);
public Hiss hiss(Optional<HissPropertiesProvider> optionalHissPropertiesProvider,
Set<Encryptor> encryptors,
Set<Hasher> hashers) {
var hissProperties = optionalHissPropertiesProvider
.map(HissProperties::withProvider)
.orElse(HissProperties.fromEnv());
return HissFactory.createHiss(hissProperties, encryptors, hashers);
}

@Bean
Expand Down

0 comments on commit 0115d0b

Please sign in to comment.