-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/shibui-1848' of bitbucket.org:unicon/shib-idp-u…
…i into feature/shibui-1853
- Loading branch information
Showing
23 changed files
with
710 additions
and
59 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
114 changes: 114 additions & 0 deletions
114
...main/java/edu/internet2/tier/shibboleth/admin/ui/security/controller/GroupController.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,114 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.security.controller; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.controller.ErrorResponse; | ||
| import edu.internet2.tier.shibboleth.admin.ui.security.model.Group; | ||
| import edu.internet2.tier.shibboleth.admin.ui.security.service.IGroupService; | ||
|
|
||
| @Controller | ||
| @RequestMapping(value = "/api/admin/groups") | ||
| public class GroupController { | ||
| @Autowired | ||
| private IGroupService groupService; | ||
|
|
||
| @PostMapping | ||
| @Transactional | ||
| public ResponseEntity<?> create(@RequestBody Group group) { | ||
| // If already defined, we can't create a new one, nor will this call update the definition | ||
| Group foundGroup = groupService.find(group.getResourceId()); | ||
|
|
||
| if (foundGroup != null) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setLocation(ServletUriComponentsBuilder.fromCurrentServletMapping().path("/api/admin/groups").build().toUri()); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).headers(headers) | ||
| .body(new ErrorResponse(String.valueOf(HttpStatus.METHOD_NOT_ALLOWED.value()), | ||
| String.format("The group with resource id: [%s] and name: [%s] already exists.", | ||
| group.getResourceId(), group.getName()))); | ||
| } | ||
|
|
||
| Group result = groupService.createOrUpdateGroup(group); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body(result); | ||
| } | ||
|
|
||
| @PutMapping | ||
| @Transactional | ||
| public ResponseEntity<?> update(@RequestBody Group group) { | ||
| Group g = groupService.find(group.getResourceId()); | ||
|
|
||
| if (g == null) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setLocation(ServletUriComponentsBuilder.fromCurrentServletMapping().path("/api/admin/groups").build().toUri()); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).headers(headers) | ||
| .body(new ErrorResponse(String.valueOf(HttpStatus.NOT_FOUND.value()), | ||
| String.format("Unable to find group with resource id: [%s] and name: [%s]", | ||
| group.getResourceId(), group.getName()))); | ||
| } | ||
|
|
||
| Group result = groupService.createOrUpdateGroup(group); | ||
| return ResponseEntity.ok(result); | ||
| } | ||
|
|
||
| @GetMapping | ||
| @Transactional(readOnly = true) | ||
| public ResponseEntity<?> getAll() { | ||
| return ResponseEntity.ok(groupService.findAll()); | ||
| } | ||
|
|
||
| @GetMapping("/{resourceId}") | ||
| @Transactional(readOnly = true) | ||
| public ResponseEntity<?> getOne(@PathVariable String resourceId) { | ||
| Group g = groupService.find(resourceId); | ||
|
|
||
| if (g == null) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setLocation(ServletUriComponentsBuilder.fromCurrentServletMapping().path("/api/admin/groups").build().toUri()); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).headers(headers) | ||
| .body(new ErrorResponse(String.valueOf(HttpStatus.NOT_FOUND.value()), | ||
| String.format("Unable to find group with resource id: [%s]", resourceId))); | ||
| } | ||
| return ResponseEntity.ok(g); | ||
| } | ||
|
|
||
| @DeleteMapping("/{resourceId}") | ||
| @Transactional | ||
| public ResponseEntity<?> delete(@PathVariable String resourceId) { | ||
| Group g = groupService.find(resourceId); | ||
|
|
||
| if (g == null) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setLocation(ServletUriComponentsBuilder.fromCurrentServletMapping().path("/api/admin/groups").build().toUri()); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).headers(headers) | ||
| .body(new ErrorResponse(String.valueOf(HttpStatus.NOT_FOUND.value()), | ||
| String.format("Unable to find group with resource id: [%s]", resourceId))); | ||
| } | ||
| if (!g.getUsers().isEmpty()) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setLocation(ServletUriComponentsBuilder.fromCurrentServletMapping().path("/api/admin/groups").build().toUri()); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.CONFLICT).headers(headers) | ||
| .body(new ErrorResponse(String.valueOf(HttpStatus.CONFLICT.value()), String.format( | ||
| "Unable to delete group with resource id: [%s] - remove all users from group first", | ||
| resourceId))); | ||
| } | ||
| groupService.deleteDefinition(g); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/model/Group.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,35 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.security.model; | ||
|
|
||
| import java.util.Set; | ||
| import java.util.UUID; | ||
|
|
||
| import javax.persistence.CascadeType; | ||
| import javax.persistence.Column; | ||
| import javax.persistence.Entity; | ||
| import javax.persistence.FetchType; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.OneToMany; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
|
||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
|
|
||
| @Entity(name = "user_groups") | ||
| @Data | ||
| public class Group { | ||
| @Column(name = "group_description", nullable = true) | ||
| String description; | ||
|
|
||
| @Column(nullable = false) | ||
| String name; | ||
|
|
||
| @Id | ||
| @Column(name = "resource_id") | ||
| String resourceId = UUID.randomUUID().toString(); | ||
|
|
||
| @OneToMany(mappedBy = "group", cascade = CascadeType.ALL, fetch = FetchType.EAGER) | ||
| @JsonIgnore | ||
| @EqualsAndHashCode.Exclude | ||
| Set<User> users; | ||
| } |
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
16 changes: 16 additions & 0 deletions
16
...ain/java/edu/internet2/tier/shibboleth/admin/ui/security/repository/GroupsRepository.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,16 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.security.repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.security.model.Group; | ||
|
|
||
| public interface GroupsRepository extends JpaRepository<Group, String> { | ||
| List<Group> findAll(); | ||
|
|
||
| Group findByResourceId(String id); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| Group save(Group group); | ||
| } |
36 changes: 36 additions & 0 deletions
36
...c/main/java/edu/internet2/tier/shibboleth/admin/ui/security/service/GroupServiceImpl.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,36 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.security.service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.security.model.Group; | ||
| import edu.internet2.tier.shibboleth.admin.ui.security.repository.GroupsRepository; | ||
|
|
||
| @Service | ||
| public class GroupServiceImpl implements IGroupService { | ||
| @Autowired | ||
| private GroupsRepository repo; | ||
|
|
||
| @Override | ||
| public Group createOrUpdateGroup(Group group) { | ||
| return repo.save(group); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteDefinition(Group group) { | ||
| repo.delete(group); | ||
| } | ||
|
|
||
| @Override | ||
| public Group find(String resourceId) { | ||
| return repo.findByResourceId(resourceId); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Group> findAll() { | ||
| return repo.findAll(); | ||
| } | ||
|
|
||
| } |
17 changes: 17 additions & 0 deletions
17
.../src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/service/IGroupService.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,17 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.security.service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.security.model.Group; | ||
|
|
||
| public interface IGroupService { | ||
|
|
||
| Group createOrUpdateGroup(Group g); | ||
|
|
||
| void deleteDefinition(Group g); | ||
|
|
||
| Group find(String resourceId); | ||
|
|
||
| List<Group> findAll(); | ||
|
|
||
| } |
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
Oops, something went wrong.