first commit
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
package com.baeldung.springvault;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.vault.repository.mapping.Secret;
|
||||
|
||||
@Secret(backend = "credentials", value = "myapp")
|
||||
public class Credentials {
|
||||
|
||||
@Id
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.springvault;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CredentialsRepository extends CrudRepository<Credentials, String> {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.baeldung.springvault;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -18,6 +19,9 @@ public class CredentialsService {
|
||||
|
||||
@Autowired
|
||||
private VaultTemplate vaultTemplate;
|
||||
|
||||
@Autowired
|
||||
private CredentialsRepository credentialsRepository;
|
||||
|
||||
/**
|
||||
* To Secure Credentials
|
||||
@@ -40,5 +44,15 @@ public class CredentialsService {
|
||||
VaultResponseSupport<Credentials> response = vaultTemplate.read("credentials/myapp", Credentials.class);
|
||||
return response.getData();
|
||||
}
|
||||
|
||||
public Credentials saveCredentials(Credentials credentials) {
|
||||
|
||||
return credentialsRepository.save(credentials);
|
||||
}
|
||||
|
||||
public Optional<Credentials> findById(String username) {
|
||||
|
||||
return credentialsRepository.findById(username);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user