Skip to content

Commit 5e45b23

Browse files
authored
Fixed the jasypt empty password error when Ldap is enabled. (#373)
1 parent e23085c commit 5e45b23

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.github.ericsson</groupId>
88
<artifactId>eiffel-intelligence</artifactId>
9-
<version>2.0.1</version>
9+
<version>2.0.2</version>
1010
<packaging>war</packaging>
1111

1212
<parent>

src/main/java/com/ericsson/ei/EndpointSecurity.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
3434
import org.springframework.security.config.http.SessionCreationPolicy;
3535

36+
import com.ericsson.ei.exception.AbortExecutionException;
3637
import com.ericsson.ei.utils.TextFormatter;
3738

3839
@Configuration
@@ -91,21 +92,16 @@ private String decodeBase64(String password) {
9192
}
9293

9394
private void addLDAPServersFromList(JSONArray serverList, AuthenticationManagerBuilder auth) throws Exception {
94-
TextFormatter textFormatter = new TextFormatter();
95-
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
96-
97-
encryptor.setPassword(jasyptEncryptorPassword);
9895

9996
for (int i = 0; i < serverList.length(); i++) {
10097
JSONObject server = (JSONObject) serverList.get(i);
10198
String password = server.getString("password");
10299

103100
if (checkIfPasswordEncrypted(password)) {
104-
password = textFormatter.removeEncryptionParentheses(password);
105-
password = encryptor.decrypt(password);
101+
password = decryptPassword(password);
106102
}
107103
else {
108-
password = decodeBase64(server.getString("password"));
104+
password = decodeBase64(password);
109105
}
110106

111107
auth
@@ -123,4 +119,20 @@ private void addLDAPServersFromList(JSONArray serverList, AuthenticationManagerB
123119
private boolean checkIfPasswordEncrypted(final String password) {
124120
return (password.startsWith("ENC(") && password.endsWith(")"));
125121
}
122+
123+
private String decryptPassword(final String inputEncryptedPassword) throws Exception {
124+
TextFormatter textFormatter = new TextFormatter();
125+
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
126+
127+
if (jasyptEncryptorPassword.isEmpty()) {
128+
LOGGER.error("Property -jasypt.encryptor.password need to be set for decrypting LDAP password.");
129+
throw new AbortExecutionException("Failed to initiate LDAP when password is encrypted. " +
130+
"Property -jasypt.encryptor.password need to be set for decrypting LDAP password.");
131+
}
132+
133+
encryptor.setPassword(jasyptEncryptorPassword);
134+
135+
String encryptedPassword = textFormatter.removeEncryptionParentheses(inputEncryptedPassword);
136+
return encryptor.decrypt(encryptedPassword);
137+
}
126138
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2019 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
package com.ericsson.ei.exception;
18+
19+
public class AbortExecutionException extends Exception {
20+
21+
private static final long serialVersionUID = 2L;
22+
23+
public AbortExecutionException() {
24+
super();
25+
}
26+
27+
public AbortExecutionException(String message) {
28+
super(message);
29+
}
30+
31+
public AbortExecutionException(String message, Throwable e) {
32+
super(message, e);
33+
}
34+
35+
}

0 commit comments

Comments
 (0)