Skip to content

Commit 3a174b3

Browse files
fix: suppress SpotBugs warnings in AuthenticationService and PlatformLogin (#184)
- Added @SuppressFBWarnings("EI_EXPOSE_REP2") to setRestTemplate methods to avoid exposing internal mutable RestTemplate objects. - Removed redundant null check in SecretServerFactoryBean - Keeps SpotBugs check passing without changing functionality. - updated document
1 parent 0f7a486 commit 3a174b3

6 files changed

Lines changed: 58 additions & 30 deletions

File tree

README.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# The Delinea Secret Server Java SDK
1+
# The Delinea Secret Server and Platform Java SDK
22

33
![Deploy](https://github.com/DelineaXPM/tss-sdk-java/workflows/Deploy/badge.svg)
44

5-
The [Delinea](https://delinea.com/) Secret Server Java SDK contains classes that
6-
interact with [Secret Server](https://delinea.com/products/secret-server/) via the REST API.
5+
The [Delinea](https://delinea.com/) Secret Server and Platform Java SDK contains classes that
6+
interact with [Secret Server](https://delinea.com/products/secret-server/) and Delinea Platform via the REST API.
77

88
The SDK contains an API based the [Spring Framework](https://spring.io/projects/spring-framework)
99
[RestTemplate](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html),
@@ -12,21 +12,21 @@ that calls the API.
1212

1313
## Install into your application
1414

15-
You can use this SDk in your application by adding the following dependency:
15+
You can use this SDK in your application by adding the following dependency:
1616

1717
```xml
1818
<dependency>
1919
<groupId>com.delinea.secrets</groupId>
2020
<artifactId>tss-sdk-java</artifactId>
21-
<version>2.0</version>
21+
<version>2.1.0</version>
2222
</dependency>
2323
```
2424

2525
## Build locally
2626

2727
### Prerequisites
2828

29-
The SDK builds and runs on Java 8 or later.
29+
The SDK builds and runs on Java 17 or later.
3030

3131
Apache [Maven](https://maven.apache.org/) is also required to build the SDK.
3232

@@ -36,15 +36,15 @@ will succeed.
3636

3737
### Settings
3838

39-
The API authenticates to Secret Server using either an _Application User_ or a Delinea Platform _Service User_ .
40-
The SDK application gets a secret from Secret Server by it's _id_ .
39+
The API authenticates to Secret Server using _Application User_ and with Delinea Platform using _Service User_ .
40+
The SDK application gets a secret from Secret Server by its _id_ .
4141

4242
### Secret Server Integration
4343
##### 1. Using Secret Server credentials
4444

4545
`authentication_mode` and `server_url` must be set.
4646

47-
Set authentication_mode to 0 for fetch secret using Secret Server credentials, provide the following properties:
47+
Set authentication_mode to 0 for fetch secret using Secret Server credentials, Set the following properties in application.properties:
4848

4949
```ini
5050
authentication_mode =0
@@ -55,16 +55,16 @@ server.username =application_user
5555
server.password =application_user_password
5656
```
5757

58-
##### 2. Using the SDK client
59-
To fetch secret using the SDK client, you need to create a new onboarding rule and use an onboarding key for authentication.
58+
##### 2. Using the Client Onboarding Key
59+
To fetch secret using the Client Onboarding, you need to create a new onboarding rule and use an onboarding key for authentication.
6060
1. Go to Secret Server > Settings > All settings and click on SDK Client.
6161
2. Click the Client Onboarding tab, then the Create rule.
6262
3. Enter a name for the new rule(this will be your rule_name).
6363
4. Check the Require onboarding key box.
6464
5. Click Save to auto-generate an onboarding key.
6565
6. You can see the key,select the Show key option (this will be your onboarding_key).
6666

67-
Set authentication_mode to 1 for fetch secret using SDK client, provide the following properties:
67+
Set authentication_mode to 1 for fetch secret using SDK client, Set the following properties in application.properties:
6868

6969
```ini
7070
authentication_mode =1
@@ -75,12 +75,12 @@ rule_name =create_rule_name
7575
onboarding_key =onboarding_key
7676
```
7777

78-
### Delinea Platfrom Integration
78+
### Delinea Platform Integration
7979
##### 1. Using Delinea PLatform credentials
8080

8181
`authentication_mode` and `server_url` must be set.
8282

83-
Set authentication_mode to 0 for fetch secret using Delinea Platform credentials, provide the following properties:
83+
Set authentication_mode to 0 for fetch secret using Delinea Platform credentials, Set the following properties in application.properties:
8484

8585
```ini
8686
authentication_mode =0
@@ -90,8 +90,8 @@ api_version=v1
9090
server.username =service_user
9191
server.password =service_user_password
9292
```
93-
##### 2. Using the SDK client
94-
To fetch secret using the SDK client, you need to create a new onboarding rule and use an onboarding key for authentication.
93+
##### 2. Using the Client Onboarding Key
94+
To fetch secret using the Client Onboarding, you need to create a new onboarding rule and use an onboarding key for authentication.
9595
1. Go to Delinea Platform > Settings > Secret Server > Administration > Tools and integrations > click on SDK Client.
9696
2. Click the Client Onboarding tab, then the Create rule.
9797
3. Enter a name for the new rule(this will be your rule_name).
@@ -101,7 +101,7 @@ To fetch secret using the SDK client, you need to create a new onboarding rule a
101101

102102
Set authentication_mode=1 to fetch secrets using the SDK client.
103103
Set server_url to the Secret Server URL. To find the Secret Server URL in Delinea Platform, go to Settings > Secret Server > Secret Server connection and copy the Secret Server URL.
104-
Provide the following properties:
104+
Set the following properties in application.properties:
105105

106106
```ini
107107
authentication_mode =1
@@ -111,6 +111,17 @@ api_version=v1
111111
rule_name =create_rule_name
112112
onboarding_key =onboarding_key
113113
```
114+
115+
## (Optional) Proxy Configuration
116+
```ini
117+
proxy.host = Proxy server hostname or IP address
118+
proxy.port = Proxy server port number
119+
proxy.username = Proxy server username (if authentication is required)
120+
proxy.password = Proxy server password (if authentication is required)
121+
```
122+
123+
Note: Leave proxy.username and proxy.password blank if your proxy does not require authentication.
124+
114125
## Run the jar
115126

116127
After the SDK application settings are configured the jar can be built:
@@ -175,6 +186,7 @@ applicationContext.getEnvironment().getPropertySources()
175186

176187
// Register the factoryBean
177188
applicationContext.registerBean(SecretServerFactoryBean.class);
189+
applicationContext.registerBean(AuthenticationService.class);
178190
applicationContext.refresh();
179191

180192
// Fetch the secret

pom.xml

Lines changed: 6 additions & 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</version>
17+
<version>2.1.0</version>
1818
<name>tss-sdk-java</name>
1919
<description>The Delinea Secret Server Java SDK</description>
2020

@@ -139,6 +139,11 @@
139139
<artifactId>snakeyaml</artifactId>
140140
<version>2.4</version>
141141
</dependency>
142+
<dependency>
143+
<groupId>com.github.spotbugs</groupId>
144+
<artifactId>spotbugs-annotations</artifactId>
145+
<version>4.9.3</version>
146+
</dependency>
142147
</dependencies>
143148

144149
<profiles>

src/main/java/com/delinea/platform/service/AuthenticationService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import com.delinea.server.spring.AuthenticationModel;
1212
import com.fasterxml.jackson.databind.ObjectMapper;
1313

14+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15+
1416
/**
1517
* Handles authentication logic for both Secret Server and Platform.
1618
* <p>
@@ -21,6 +23,15 @@ public class AuthenticationService implements IAuthenticationService {
2123
private RestTemplate restTemplate ;
2224
private PlatformLogin platformLogin = new PlatformLogin();
2325

26+
/**
27+
* Sets the RestTemplate to be used for HTTP calls.
28+
* The RestTemplate is injected and managed by Spring,
29+
* so no defensive copy is required.
30+
*/
31+
@SuppressFBWarnings(
32+
value = "EI_EXPOSE_REP2",
33+
justification = "RestTemplate is a Spring-managed immutable bean and safe to assign directly."
34+
)
2435
public void setRestTemplate(RestTemplate restTemplate) {
2536
this.restTemplate = restTemplate;
2637
this.platformLogin.setRestTemplate(restTemplate);

src/main/java/com/delinea/platform/service/PlatformLogin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020
import com.delinea.server.spring.AuthenticationModel;
2121
import com.fasterxml.jackson.databind.ObjectMapper;
2222

23+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24+
2325
/** Handles authentication against Delinea Platform and vault retrieval. */
2426
@Component
2527
public class PlatformLogin {
2628
private RestTemplate restTemplate;
29+
30+
/**
31+
* Injects RestTemplate. Safe assignment since Spring manages RestTemplate lifecycle.
32+
*/
33+
@SuppressFBWarnings(
34+
value = "EI_EXPOSE_REP2",
35+
justification = "RestTemplate is a Spring-managed immutable bean and safe to assign directly."
36+
)
2737
public void setRestTemplate(RestTemplate restTemplate) {
2838
this.restTemplate = restTemplate;
2939
}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,14 @@ private ClientHttpRequestFactory createRequestFactoryWithProxy() {
189189
.setDefaultCredentialsProvider(credsProvider)
190190
.setDefaultRequestConfig(config)
191191
.setConnectionManager(new PoolingHttpClientConnectionManager())
192-
.addRequestInterceptorLast((request, entity, context) -> {
193-
try {
194-
// System.out.println("[DEBUG] Outgoing request through proxy → " + request.getRequestUri());
195-
} catch (Exception e) {
196-
// System.out.println("[DEBUG] Outgoing request through proxy (URI unavailable).");
197-
}
198-
})
192+
.addRequestInterceptorLast((request, entity, context) -> {})
199193
.build();
200194
return new HttpComponentsClientHttpRequestFactory(httpClient);
201195
}
202196

203197
private AccessGrant getAccessGrant() throws UnknownHostException, UnsupportedEncodingException, Exception {
204198
if (authenticationMode == DEFAULT_AUTH_MODE) {
205199
AuthenticationModel authenticationModel = isPlatfromOrSS();
206-
if (authenticationModel != null) {
207200
if (authenticationModel.isPlatformLogin()) {
208201
AccessGrant accessGrant = new AccessGrant();
209202
accessGrant.accessToken = authenticationModel.getToken();
@@ -212,9 +205,6 @@ private AccessGrant getAccessGrant() throws UnknownHostException, UnsupportedEnc
212205
} else {
213206
return getTokenUsingSScred();
214207
}
215-
} else {
216-
throw new NullPointerException("Invalid Server URL ");
217-
}
218208
} else {
219209
this.secreterverUrl = serverUrl;
220210
setSDKClientCred();

src/main/java/com/delinea/server/spring/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
* @author Adam Migus
1111
* @see SecretServerFactoryBean
1212
*/
13-
package com.delinea.secrets.server.spring;
13+
package com.delinea.server.spring;

0 commit comments

Comments
 (0)