|
16 | 16 | import org.springframework.http.MediaType; |
17 | 17 | import org.springframework.http.ResponseEntity; |
18 | 18 | import org.springframework.transaction.annotation.Transactional; |
| 19 | +import org.springframework.util.CollectionUtils; |
| 20 | +import org.springframework.util.StringUtils; |
19 | 21 | import org.springframework.validation.annotation.Validated; |
20 | 22 | import org.springframework.web.bind.annotation.PutMapping; |
21 | 23 | import org.springframework.web.bind.annotation.RequestBody; |
@@ -60,15 +62,15 @@ public IdentityProviderController(UserRepository userRepository, |
60 | 62 | public ResponseEntity<Map<String, Object>> connect(User user, @RequestBody @Validated ConnectionRequest connectionRequest) { |
61 | 63 | LOG.debug("/connect SP to IdP connection for " + user.getEmail()); |
62 | 64 |
|
| 65 | + String idpManageIdentifier = connectionRequest.getIdpManageIdentifier(); |
| 66 | + Organization organization = organizationRepository.findByManageIdentifier(idpManageIdentifier) |
| 67 | + .orElseThrow(() -> new NotFoundException("Organization with manageIdentifier not found: " + idpManageIdentifier)); |
| 68 | + |
63 | 69 | Map<String, Object> serviceProvider = manage.providerById(connectionRequest.getEntityType(), |
64 | 70 | connectionRequest.getApplicationManageIdentifier(), Environment.PROD); |
65 | 71 |
|
66 | | - String idpManageIdentifier = connectionRequest.getIdpManageIdentifier(); |
67 | 72 | Map<String, Object> identityProvider = manage.providerById(EntityType.saml20_idp, idpManageIdentifier, Environment.PROD); |
68 | 73 |
|
69 | | - Organization organization = organizationRepository.findByManageIdentifier(idpManageIdentifier) |
70 | | - .orElseThrow(() -> new NotFoundException("Organization with manageIdentifier not found: " + idpManageIdentifier)); |
71 | | - |
72 | 74 | User userFromDB = reinitializeUser(user, userRepository); |
73 | 75 | //See https://github.com/OpenConext/OpenConext-access/wiki/Service-Connect-Flow |
74 | 76 | boolean memberRequest = !userFromDB.isSuperUser(); |
@@ -105,14 +107,17 @@ public ResponseEntity<Map<String, Object>> connect(User user, @RequestBody @Vali |
105 | 107 | .equals(idpInstitutionGUID); |
106 | 108 | boolean connectWithoutInteraction = idpAndSpShareInstitution || !connectOption.equals(DashBoardConnectionOption.connectWithInteraction); |
107 | 109 | if (connectWithoutInteraction) { |
108 | | - manage.connectWithoutInteraction(identityProvider, serviceProvider, userFromDB); |
| 110 | + manage.connectWithoutInteraction(identityProvider, serviceProvider, userFromDB); |
109 | 111 | if (connectOption.equals(DashBoardConnectionOption.connectWithoutInteractionWithEmail)) { |
110 | | - mailBox.sendNewConnectionCreated( |
111 | | - userFromDB, |
112 | | - contactPersons(serviceProvider), |
113 | | - getProviderName(identityProvider), |
114 | | - getProviderName(serviceProvider), |
115 | | - (String) getData(serviceProvider).get("entityid")); |
| 112 | + List<String> recipients = contactPersons(serviceProvider); |
| 113 | + if (!CollectionUtils.isEmpty(recipients)) { |
| 114 | + mailBox.sendNewConnectionCreated( |
| 115 | + userFromDB, |
| 116 | + recipients, |
| 117 | + getProviderName(identityProvider), |
| 118 | + getProviderName(serviceProvider), |
| 119 | + (String) getData(serviceProvider).get("entityid")); |
| 120 | + } |
116 | 121 | } |
117 | 122 | return Results.createResult(); |
118 | 123 | } |
|
0 commit comments