33
33
import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
34
34
import org .springframework .security .config .http .SessionCreationPolicy ;
35
35
36
+ import com .ericsson .ei .exception .AbortExecutionException ;
36
37
import com .ericsson .ei .utils .TextFormatter ;
37
38
38
39
@ Configuration
@@ -91,21 +92,16 @@ private String decodeBase64(String password) {
91
92
}
92
93
93
94
private void addLDAPServersFromList (JSONArray serverList , AuthenticationManagerBuilder auth ) throws Exception {
94
- TextFormatter textFormatter = new TextFormatter ();
95
- StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor ();
96
-
97
- encryptor .setPassword (jasyptEncryptorPassword );
98
95
99
96
for (int i = 0 ; i < serverList .length (); i ++) {
100
97
JSONObject server = (JSONObject ) serverList .get (i );
101
98
String password = server .getString ("password" );
102
99
103
100
if (checkIfPasswordEncrypted (password )) {
104
- password = textFormatter .removeEncryptionParentheses (password );
105
- password = encryptor .decrypt (password );
101
+ password = decryptPassword (password );
106
102
}
107
103
else {
108
- password = decodeBase64 (server . getString ( " password" ) );
104
+ password = decodeBase64 (password );
109
105
}
110
106
111
107
auth
@@ -123,4 +119,20 @@ private void addLDAPServersFromList(JSONArray serverList, AuthenticationManagerB
123
119
private boolean checkIfPasswordEncrypted (final String password ) {
124
120
return (password .startsWith ("ENC(" ) && password .endsWith (")" ));
125
121
}
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
+ }
126
138
}
0 commit comments