Skip to content

Commit ed5ebe5

Browse files
Added AutoComment feature (#187)
1 parent 976689c commit ed5ebe5

5 files changed

Lines changed: 43 additions & 26 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ You can use this SDK in your application by adding the following dependency:
1818
<dependency>
1919
<groupId>com.delinea.secrets</groupId>
2020
<artifactId>tss-sdk-java</artifactId>
21-
<version>2.1.0</version>
21+
<version>2.1.1</version>
2222
</dependency>
2323
```
2424

@@ -49,7 +49,7 @@ Set authentication_mode to 0 for fetch secret using Secret Server credentials, S
4949
```ini
5050
authentication_mode =0
5151
server_url =Secret_Server_url
52-
api_version=v1
52+
autoComment =AutoComment is feature that adds a comment when a secret is accessed in Delinea Secret Server, which is recorded in the secrets Audit log for tracking
5353

5454
server.username =application_user
5555
server.password =application_user_password
@@ -69,7 +69,7 @@ Set authentication_mode to 1 for fetch secret using SDK client, Set the followin
6969
```ini
7070
authentication_mode =1
7171
server_url =Secret_Server_url
72-
api_version=v1
72+
autoComment =AutoComment is feature that adds a comment when a secret is accessed in Delinea Secret Server, which is recorded in the secrets Audit log for tracking
7373

7474
rule_name =create_rule_name
7575
onboarding_key =onboarding_key
@@ -85,7 +85,7 @@ Set authentication_mode to 0 for fetch secret using Delinea Platform credentials
8585
```ini
8686
authentication_mode =0
8787
server_url =Delinea_Platform_url
88-
api_version=v1
88+
autoComment =AutoComment is feature that adds a comment when a secret is accessed in Delinea Secret Server, which is recorded in the secrets Audit log for tracking
8989

9090
server.username =service_user
9191
server.password =service_user_password
@@ -105,8 +105,8 @@ Set the following properties in application.properties:
105105

106106
```ini
107107
authentication_mode =1
108-
server_url =Secret_Server_url
109-
api_version=v1
108+
server_url =Delinea_Platform_url
109+
autoComment =AutoComment is feature that adds a comment when a secret is accessed in Delinea Secret Server, which is recorded in the secrets Audit log for tracking
110110

111111
rule_name =create_rule_name
112112
onboarding_key =onboarding_key

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<groupId>com.delinea.secrets</groupId>
1616
<artifactId>tss-sdk-java</artifactId>
17-
<version>2.1.0</version>
17+
<version>2.1.1</version>
1818
<name>tss-sdk-java</name>
1919
<description>The Delinea Secret Server Java SDK</description>
2020

src/main/java/com/delinea/server/spring/SecretServer.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,63 @@
44
import java.util.Map;
55

66
import org.springframework.web.client.RestTemplate;
7+
import org.springframework.web.util.UriComponentsBuilder;
78

89
/**
910
* A <a href="https://spring.io/projects/spring-framework">Spring Framework</a>
10-
* <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html">RestTemplate</a>
11+
* <a href=
12+
* "https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html">RestTemplate</a>
1113
* with convenience methods specific to the Delinea Secret Server REST API.
1214
*
13-
* <p>Use the {@link SecretServerFactoryBean} to create and initialize it.
15+
* <p>
16+
* Use the {@link SecretServerFactoryBean} to create and initialize it.
1417
*/
1518
public class SecretServer extends RestTemplate {
1619
private static final String SECRET_ID_URI = "/secrets/{id}";
1720
private static final String SECRET_FILE_ATTACHMENT_URI = SECRET_ID_URI + "/fields/{slug}";
21+
private String autoComment;
22+
23+
public void setAutoComment(String autoComment) {
24+
this.autoComment = autoComment;
25+
}
1826

1927
/**
2028
* Fetch and return a {@link Secret} from Delinea Secret Server.
2129
*
22-
* @param id - the integer ID of the secret to be fetched
30+
* @param id - the integer ID of the secret to be fetched
2331
* @param fetchFileAttachments - whether to fetch {@code fileAttachments} so
24-
* {@link Secret.Field#getValue()} returns the contents instead of the default placeholder
32+
* {@link Secret.Field#getValue()} returns the
33+
* contents instead of the default placeholder
2534
* @return the {@link Secret} object
2635
*/
2736
public Secret getSecret(final int id, final boolean fetchFileAttachments) {
28-
final Map<String, String> params = new HashMap<>();
29-
params.put("id", String.valueOf(id));
3037

31-
final Secret secret = getForObject(SECRET_ID_URI, Secret.class, params);
38+
final Map<String, String> uriParams = new HashMap<>();
39+
uriParams.put("id", String.valueOf(id));
40+
41+
UriComponentsBuilder builder = UriComponentsBuilder.fromPath(SECRET_ID_URI);
42+
43+
if (!autoComment.isBlank()) {
44+
builder.queryParam("autoComment", autoComment);
45+
}
46+
47+
final String uri = builder.build().toUriString();
48+
final Secret secret = getForObject(uri, Secret.class, uriParams);
3249
if (fetchFileAttachments) {
3350
secret.getFields().forEach(field -> {
3451
if (field.getFileAttachmentId() > 0) {
35-
params.put("slug", field.getSlug());
36-
field.setValue(getForEntity(SECRET_FILE_ATTACHMENT_URI, String.class, params).getBody());
52+
uriParams.put("slug", field.getSlug());
53+
field.setValue(getForEntity(SECRET_FILE_ATTACHMENT_URI, String.class, uriParams).getBody());
3754
}
3855
});
3956
}
4057
return secret;
4158
}
4259

4360
/**
44-
* Fetch and return a {@link Secret} from Delinea Secret Server, including {@code fileAttachments}
61+
* Fetch and return a {@link Secret} from Delinea Secret Server, including
62+
* {@code fileAttachments}
63+
*
4564
* @see #getSecret(int, boolean)
4665
*
4766
* @param id - the integer ID of the secret to be fetched

src/main/java/com/delinea/server/spring/SecretServerFactoryBean.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ public String getTokenType() {
8181
private static final String AUTHORIZATION_HEADER_NAME = "Authorization";
8282
private static final String AUTHORIZATION_TOKEN_TYPE = "Bearer";
8383

84-
private String API_VERSION;
8584
private String ruleName;
86-
8785
private String onboardingKey;
8886
private int authenticationMode;
8987
private String clientId;
@@ -96,6 +94,7 @@ public String getTokenType() {
9694
private String proxyPort;
9795
private String proxyUsername;
9896
private String proxyPassword;
97+
private String autoComment;
9998

10099
@Autowired(required = false)
101100
private ClientHttpRequestFactory requestFactory;
@@ -120,8 +119,6 @@ public void afterPropertiesSet() throws Exception {
120119
} else {
121120
authenticationMode = DEFAULT_AUTH_MODE;
122121
}
123-
String apiVersionProp = environment.getProperty("api.version");
124-
this.API_VERSION = (apiVersionProp != null && !apiVersionProp.isEmpty()) ? apiVersionProp : "v1";
125122

126123
if (authenticationMode == DEFAULT_AUTH_MODE) {
127124
this.serverUsername = environment.getProperty("server.username");
@@ -142,6 +139,7 @@ public void afterPropertiesSet() throws Exception {
142139
this.proxyPort = environment.getProperty("proxy.port");
143140
this.proxyUsername = environment.getProperty("proxy.username");
144141
this.proxyPassword = environment.getProperty("proxy.password");
142+
this.autoComment = environment.getProperty("autoComment", "");
145143

146144
if (requestFactory == null) {
147145
requestFactory = createRequestFactoryWithProxy();
@@ -175,7 +173,7 @@ private ClientHttpRequestFactory createRequestFactoryWithProxy() {
175173
HttpHost proxy = new HttpHost(proxyHost, port);
176174

177175
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
178-
if (StringUtils.hasText(proxyUsername)) {
176+
if (StringUtils.hasText(proxyUsername) && proxyPassword != null) {
179177
credsProvider.setCredentials(
180178
new AuthScope(proxyHost, port),
181179
new UsernamePasswordCredentials(proxyUsername, proxyPassword.toCharArray()));
@@ -274,8 +272,7 @@ private void setSDKClientCred() throws UnknownHostException {
274272

275273
// Use requestFactory-backed RestTemplate so proxy is used
276274
RestTemplate rt = new RestTemplate(requestFactory);
277-
ResponseEntity<Map<String, Object>> response = rt.exchange(serverUrl + "/api/" + API_VERSION
278-
+ "/sdk-client-accounts", HttpMethod.POST, entity, new ParameterizedTypeReference<Map<String, Object>>() {
275+
ResponseEntity<Map<String, Object>> response = rt.exchange(serverUrl + "/api/v1/sdk-client-accounts", HttpMethod.POST, entity, new ParameterizedTypeReference<Map<String, Object>>() {
279276
});
280277

281278
if (response.getStatusCode() == HttpStatus.OK) {
@@ -291,7 +288,8 @@ private void setSDKClientCred() throws UnknownHostException {
291288
public SecretServer getObject() throws Exception {
292289
AccessGrant accessGrant = getAccessGrant();
293290
final SecretServer secretServer = new SecretServer();
294-
secretServer.setUriTemplateHandler(new DefaultUriBuilderFactory(secreterverUrl + "/api/" + API_VERSION));
291+
secretServer.setAutoComment(autoComment);
292+
secretServer.setUriTemplateHandler(new DefaultUriBuilderFactory(secreterverUrl + "/api/v1"));
295293

296294
secretServer.setRequestFactory(new InterceptingClientHttpRequestFactory(requestFactory,
297295
Arrays.asList((request, body, execution) -> {

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Common properties
66
authentication_mode =
77
server.url =
8-
api.version=
8+
autoComment =
99

1010
# 1. Using Server credentials:
1111
# If authentication_mode is set to 0, provide the following properties:

0 commit comments

Comments
 (0)