|
43 | 43 | public class ConnectionController implements UserAccessRights { |
44 | 44 |
|
45 | 45 | private static final Log LOG = LogFactory.getLog(ConnectionController.class); |
| 46 | + private static final int SECRET_LENGTH = 36; |
46 | 47 |
|
47 | 48 | private final ConnectionRepository connectionRepository; |
48 | 49 | private final ApplicationRepository applicationRepository; |
@@ -135,7 +136,7 @@ public Map<String, String> secret(User user, @PathVariable("connectionId") Long |
135 | 136 | user = this.reinitializeUser(user, userRepository); |
136 | 137 | confirmApplicationMembership(user, organization, application, Authority.MEMBER); |
137 | 138 |
|
138 | | - String secret = passwordGenerator.generatePassword(36, rules); |
| 139 | + String secret = passwordGenerator.generatePassword(SECRET_LENGTH, rules); |
139 | 140 | connection.getMetaData().put("secret", secret); |
140 | 141 | saveConnection(connection); |
141 | 142 |
|
@@ -217,16 +218,27 @@ public ResponseEntity<Map<String, Integer>> delete(User user, @PathVariable("con |
217 | 218 | private Connection saveConnection(Connection connection) { |
218 | 219 | //Put / Post to Manage only if the status is not OPEN |
219 | 220 | if (!connection.getStatus().equals(ConnectionStatus.OPEN)) { |
220 | | - if (connection.getProtocol().equals(EntityType.oidc10_rp) && |
221 | | - !StringUtils.hasText((String) connection.getMetaData().get("secret")) && |
222 | | - connection.getMetaData().getOrDefault("pkce", false) == Boolean.FALSE) { |
| 221 | + boolean isPublicRelyingParty = connection.getProtocol().equals(EntityType.oidc10_rp) && |
| 222 | + connection.getMetaData().getOrDefault("pkce", false) == Boolean.FALSE; |
| 223 | + boolean hasSecret = StringUtils.hasText((String) connection.getMetaData().get("secret")) ; |
| 224 | + if (isPublicRelyingParty && !hasSecret) { |
223 | 225 | //generate secret but store the raw-text variant, because Manage encodes it |
224 | | - String secret = passwordGenerator.generatePassword(36, rules); |
| 226 | + String secret = passwordGenerator.generatePassword(SECRET_LENGTH, rules); |
225 | 227 | connection.getMetaData().put("secret", secret); |
| 228 | + connection.setSecretSet(true); |
226 | 229 | } |
227 | 230 |
|
228 | 231 | Map<String, Object> provider = manage.saveProvider(connection); |
229 | 232 | connection.updateRemoteManageData(provider); |
| 233 | + if (isPublicRelyingParty) { |
| 234 | + //We must store the encrypted secret, otherwise manage will keep encrypting it again and again |
| 235 | + Map<String, Object> data = (Map<String, Object>) provider.get("data"); |
| 236 | + Map<String, Object> metaDataFields = (Map<String, Object>) data.get("metaDataFields"); |
| 237 | + String secretFromManage = (String) metaDataFields.get("secret"); |
| 238 | + if (StringUtils.hasText(secretFromManage) && secretFromManage.length() != SECRET_LENGTH) { |
| 239 | + connection.getMetaData().put("secret", secretFromManage); |
| 240 | + } |
| 241 | + } |
230 | 242 |
|
231 | 243 | List<Map<String, Object>> contactPersons = (List<Map<String, Object>>) connection.getMetaData().get("contactPersons"); |
232 | 244 | if (!CollectionUtils.isEmpty(contactPersons)) { |
|
0 commit comments