-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Endpoint for Profile to fetch roles for user
- Loading branch information
Showing
18 changed files
with
237 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package access.profile; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ApplicationInfo { | ||
|
||
private String landingPage; | ||
private String nameEn; | ||
private String nameNl; | ||
private String organisationEn; | ||
private String organisationNl; | ||
private String logo; | ||
} |
79 changes: 79 additions & 0 deletions
79
server/src/main/java/access/profile/ProfileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package access.profile; | ||
|
||
import access.manage.Manage; | ||
import access.model.Authority; | ||
import access.model.Role; | ||
import access.model.User; | ||
import access.model.UserRole; | ||
import access.repository.UserRepository; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import static access.SwaggerOpenIdConfig.BASIC_AUTHENTICATION_SCHEME_NAME; | ||
|
||
@RestController | ||
@RequestMapping(value = {"/api/profile", "/api/external/v1/profile"}, produces = MediaType.APPLICATION_JSON_VALUE) | ||
@SecurityRequirement(name = BASIC_AUTHENTICATION_SCHEME_NAME) | ||
public class ProfileController { | ||
|
||
private static final Log LOG = LogFactory.getLog(ProfileController.class); | ||
|
||
private final UserRepository userRepository; | ||
private final Manage manage; | ||
|
||
public ProfileController(UserRepository userRepository, | ||
Manage manage) { | ||
this.userRepository = userRepository; | ||
this.manage = manage; | ||
} | ||
|
||
@GetMapping(value = "") | ||
@PreAuthorize("hasRole('PROFILE')") | ||
public ResponseEntity<List<UserRoleProfile>> roles(@RequestParam("collabPersonId") String collabPersonId) { | ||
LOG.debug("Fetch profile roles for:" + collabPersonId); | ||
|
||
Optional<User> optionalUser = userRepository.findBySubIgnoreCase(collabPersonId); | ||
Set<UserRole> userRoles = optionalUser.map(User::getUserRoles).orElse(Collections.emptySet()); | ||
List<Role> roles = userRoles.stream() | ||
.filter(userRole -> userRole.getAuthority().equals(Authority.GUEST)) | ||
.map(UserRole::getRole).toList(); | ||
return ResponseEntity.ok( | ||
manage.addManageMetaData(roles).stream(). | ||
map(this::userRoleProfile) | ||
.toList() | ||
); | ||
} | ||
|
||
private UserRoleProfile userRoleProfile(Role role) { | ||
return new UserRoleProfile( | ||
role.getName(), | ||
role.getDescription(), | ||
applicationInfoList(role)); | ||
} | ||
|
||
private List<ApplicationInfo> applicationInfoList(Role role) { | ||
return role.getApplicationMaps().stream().map(applicationMap -> new ApplicationInfo( | ||
(String) applicationMap.get("landingPage"), | ||
(String) applicationMap.get("name:en"), | ||
(String) applicationMap.get("name:nl"), | ||
(String) applicationMap.get("OrganizationName:en"), | ||
(String) applicationMap.get("OrganizationName:nl"), | ||
(String) applicationMap.get("logo") | ||
)).toList(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package access.profile; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class UserRoleProfile { | ||
|
||
private String name; | ||
private String description; | ||
private List<ApplicationInfo> applications; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,10 @@ lifecycle: | |
user: lifecycle | ||
password: secret | ||
|
||
profile: | ||
user: profile | ||
password: secret | ||
|
||
email: | ||
from: "[email protected]" | ||
contactEmail: "[email protected]" | ||
|
Oops, something went wrong.