-
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.
Merged in feature/shibui-2059 (pull request #527)
Feature/shibui 2059
- Loading branch information
Showing
17 changed files
with
559 additions
and
45 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...ain/java/edu/internet2/tier/shibboleth/admin/ui/controller/AttributeBundleController.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,60 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.controller; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.domain.AttributeBundle; | ||
import edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException; | ||
import edu.internet2.tier.shibboleth.admin.ui.exception.ObjectIdExistsException; | ||
import edu.internet2.tier.shibboleth.admin.ui.security.exception.GroupDeleteException; | ||
import edu.internet2.tier.shibboleth.admin.ui.security.exception.GroupExistsConflictException; | ||
import edu.internet2.tier.shibboleth.admin.ui.security.model.Group; | ||
import edu.internet2.tier.shibboleth.admin.ui.service.AttributeBundleService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.annotation.Secured; | ||
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.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/custom/entity/bundles") | ||
@Slf4j | ||
public class AttributeBundleController { | ||
@Autowired AttributeBundleService attributeBundleService; | ||
|
||
@Secured("ROLE_ADMIN") | ||
@PostMapping | ||
@Transactional | ||
public ResponseEntity<?> create(@RequestBody AttributeBundle bundle) throws ObjectIdExistsException { | ||
AttributeBundle result = attributeBundleService.create(bundle); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(result); | ||
} | ||
|
||
@Secured("ROLE_ADMIN") | ||
@DeleteMapping("/{resourceId}") | ||
@Transactional | ||
public ResponseEntity<?> delete(@PathVariable String resourceId) throws EntityNotFoundException { | ||
attributeBundleService.deleteDefinition(resourceId); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@GetMapping | ||
@Transactional(readOnly = true) | ||
public ResponseEntity<?> getAll() { | ||
return ResponseEntity.ok(attributeBundleService.findAll()); | ||
} | ||
|
||
@Secured("ROLE_ADMIN") | ||
@PutMapping | ||
@Transactional | ||
public ResponseEntity<?> update(@RequestBody AttributeBundle bundle) throws EntityNotFoundException { | ||
AttributeBundle result = attributeBundleService.updateBundle(bundle); | ||
return ResponseEntity.ok(result); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...va/edu/internet2/tier/shibboleth/admin/ui/controller/AttributeBundleExceptionHandler.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,29 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.controller; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException; | ||
import edu.internet2.tier.shibboleth.admin.ui.exception.ObjectIdExistsException; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.context.request.WebRequest; | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; | ||
|
||
@ControllerAdvice(assignableTypes = {AttributeBundleController.class}) | ||
public class AttributeBundleExceptionHandler extends ResponseEntityExceptionHandler { | ||
@ExceptionHandler({ EntityNotFoundException.class }) | ||
public ResponseEntity<?> handleEntityNotFoundException(EntityNotFoundException e, WebRequest request) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponse(HttpStatus.NOT_FOUND, e.getMessage())); | ||
} | ||
|
||
@ExceptionHandler({ ObjectIdExistsException.class }) | ||
public ResponseEntity<?> handleObjectIdExistsException(ObjectIdExistsException e, WebRequest request) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setLocation(EntityDescriptorController.getResourceUriFor(e.getMessage())); | ||
return ResponseEntity.status(HttpStatus.CONFLICT).headers(headers).body(new ErrorResponse( | ||
String.valueOf(HttpStatus.CONFLICT.value()), | ||
String.format("The attribute bundle with resource id [%s] already exists.", e.getMessage()))); | ||
|
||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/domain/AttributeBundle.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,31 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.domain; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
import lombok.Data; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.ElementCollection; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
@Entity(name = "attribute_bundle_definition") | ||
@Data | ||
public class AttributeBundle { | ||
@Column(nullable = false) | ||
@ElementCollection | ||
Set<BundleableAttributeType> attributes = new HashSet<>(); | ||
|
||
@Column(name = "name", nullable = true) | ||
String name; | ||
|
||
@Id | ||
@Column(name = "resource_id", nullable = false) | ||
String resourceId = UUID.randomUUID().toString(); | ||
} |
40 changes: 40 additions & 0 deletions
40
.../src/main/java/edu/internet2/tier/shibboleth/admin/ui/domain/BundleableAttributeType.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,40 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import edu.internet2.tier.shibboleth.admin.util.BundleableAttributeTypeValueSerializer; | ||
|
||
@JsonSerialize(using = BundleableAttributeTypeValueSerializer.class) | ||
public enum BundleableAttributeType { | ||
EDUPERSONPRINCIPALNAME("eduPersonPrincipalName"), | ||
UID("uid"), | ||
MAIL("mail"), | ||
SURNAME("surname"), | ||
GIVENNAME("givenName"), | ||
EDUPERSONAFFILIATE("eduPersonAffiliation"), | ||
EDUPERSONSCOPEDAFFILIATION("eduPersonScopedAffiliation"), | ||
EDUPERSONPRIMARYAFFILIATION("eduPersonPrimaryAffiliation"), | ||
EDUPERSONENTITLEMENT("eduPersonEntitlement"), | ||
EDUPERSONASSURANCE("eduPersonAssurance"), | ||
EDUPERSONUNIQUEID("eduPersonUniqueId"), | ||
EMPLOYEENUMBER("employeeNumber"); | ||
|
||
String label; | ||
|
||
BundleableAttributeType(String val) { | ||
label = val; | ||
} | ||
|
||
public String label() {return label;} | ||
|
||
@JsonCreator | ||
public static BundleableAttributeType valueOfLabel(String label) { | ||
for (BundleableAttributeType e : values()) { | ||
if (e.label.equals(label)) { | ||
return e; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
8 changes: 0 additions & 8 deletions
8
...c/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/EntityIdExistsException.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...c/main/java/edu/internet2/tier/shibboleth/admin/ui/exception/ObjectIdExistsException.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,8 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.exception; | ||
|
||
public class ObjectIdExistsException extends Exception { | ||
public ObjectIdExistsException(String entityId) { | ||
super(entityId); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...ain/java/edu/internet2/tier/shibboleth/admin/ui/repository/AttributeBundleRepository.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,18 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.repository; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.domain.AttributeBundle; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Repository to manage {@link edu.internet2.tier.shibboleth.admin.ui.domain.AttributeBundle} instances. | ||
*/ | ||
public interface AttributeBundleRepository extends JpaRepository<AttributeBundle, String> { | ||
List<AttributeBundle> findAll(); | ||
|
||
Optional<AttributeBundle> findByResourceId(String resourceId); | ||
|
||
AttributeBundle save(AttributeBundle target); | ||
} |
46 changes: 46 additions & 0 deletions
46
.../src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/AttributeBundleService.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,46 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.domain.AttributeBundle; | ||
import edu.internet2.tier.shibboleth.admin.ui.exception.EntityNotFoundException; | ||
import edu.internet2.tier.shibboleth.admin.ui.exception.ObjectIdExistsException; | ||
import edu.internet2.tier.shibboleth.admin.ui.repository.AttributeBundleRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class AttributeBundleService { | ||
@Autowired | ||
AttributeBundleRepository attributeBundleRepository; | ||
|
||
public AttributeBundle create(AttributeBundle bundle) throws ObjectIdExistsException { | ||
if (attributeBundleRepository.findByResourceId(bundle.getResourceId()).isPresent()) { | ||
throw new ObjectIdExistsException(bundle.getResourceId()); | ||
} | ||
return attributeBundleRepository.save(bundle); | ||
} | ||
|
||
public List<AttributeBundle> findAll() { | ||
return attributeBundleRepository.findAll(); | ||
} | ||
|
||
public void deleteDefinition(String resourceId) throws EntityNotFoundException { | ||
if (attributeBundleRepository.findByResourceId(resourceId).isEmpty()) { | ||
throw new EntityNotFoundException(String.format("Unable to find attribute bundle with resource id: [%s] for deletion", resourceId)); | ||
} | ||
attributeBundleRepository.deleteById(resourceId); | ||
} | ||
|
||
public AttributeBundle updateBundle(AttributeBundle bundle) throws EntityNotFoundException { | ||
Optional<AttributeBundle> dbBundle = attributeBundleRepository.findByResourceId(bundle.getResourceId()); | ||
if (dbBundle.isEmpty()) { | ||
throw new EntityNotFoundException(String.format("Unable to find attribute bundle with resource id: [%s] for update", bundle.getResourceId())); | ||
} | ||
AttributeBundle bundleToUpdate = dbBundle.get(); | ||
bundleToUpdate.setName(bundle.getName()); | ||
bundleToUpdate.setAttributes(bundle.getAttributes()); | ||
return attributeBundleRepository.save(bundleToUpdate); | ||
} | ||
} |
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.