Skip to content

Commit

Permalink
SHIBUI-2633
Browse files Browse the repository at this point in the history
Fixing the MDQ "/entities"
  • Loading branch information
chasegawa committed Nov 2, 2023
1 parent 7090cec commit f90f4ce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests()
.requestMatchers(new AntPathRequestMatcher("/unsecured/**/*"),
new AntPathRequestMatcher("/entities*"),
new AntPathRequestMatcher("/entities/**/*"),
new AntPathRequestMatcher("/actuator/**"),
new AntPathRequestMatcher("/api/beacon/send")).permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.List;

/**
* EntitiesController is here to meet the requirements for this project being an MDQ. Despite similar logic to the
* EntitiesDescriptorController, the required endpoints that make this project an MDQ server are served by this controller.
*/
@RestController
@RequestMapping(value = { "/entities", // per protocol - https://spaces.at.internet2.edu/display/MDQ/Metadata+Query+Protocol
"/api/entities" }, // existing - included to break no existing code
@RequestMapping(value = { "/" }, // per protocol - https://spaces.at.internet2.edu/display/MDQ/Metadata+Query+Protocol
method = RequestMethod.GET)
@Slf4j
@Tags(value = {@Tag(name = "MDQ")})
Expand All @@ -49,7 +49,30 @@ public class EntitiesController {
@Autowired
private EntityDescriptorRepository entityDescriptorRepository;

@RequestMapping(value = "/{entityId:.*}")
@RequestMapping(value = "/entities", produces = "application/xml")
@Operation(description = "Endpoint based on the MDQ spec to return all entity's information. see: https://spaces.at.internet2.edu/display/MDQ/Metadata+Query+Protocol",
summary = "Return all the entities from the entity's id", method = "GET")
@Transactional(readOnly = true)
public ResponseEntity<?> getAllXml() throws MarshallingException, ResolverException, UnsupportedEncodingException {
List<edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor> entityDescriptors = entityDescriptorRepository.findAll();
if (entityDescriptors == null || entityDescriptors.isEmpty()) {
return ResponseEntity.notFound().build();
}
StringBuilder result = new StringBuilder();
entityDescriptors.forEach(entityDescriptor -> {
try {
final String xml = this.openSamlObjects.marshalToXmlString(entityDescriptor);
result.append(xml);
}
catch (MarshallingException e) {
throw new RuntimeException(e);
}
});
String xmlDeclarationClean = result.toString().replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>","");
return new ResponseEntity<>("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + xmlDeclarationClean, new HttpHeaders(), HttpStatus.OK);
}

@RequestMapping(value = "/entities/{entityId:.*}")
@Operation(description = "Endpoint based on the MDQ spec to return a single entity's information. see: https://spaces.at.internet2.edu/display/MDQ/Metadata+Query+Protocol",
summary = "Return a single entity from the entity's id", method = "GET")
@Transactional(readOnly = true)
Expand All @@ -70,7 +93,7 @@ private String formatModifiedDate(EntityDescriptorRepresentation entityDescripto
return DateUtils.formatDate(date, DateUtils.PATTERN_RFC1123);
}

@RequestMapping(value = "/{entityId:.*}", produces = "application/xml")
@RequestMapping(value = "/entities/{entityId:.*}", produces = "application/xml")
@Operation(description = "Endpoint based on the MDQ spec to return a single entity's information. see: https://spaces.at.internet2.edu/display/MDQ/Metadata+Query+Protocol",
summary = "Return a single entity from the entity's id", method = "GET")
@Transactional(readOnly = true)
Expand Down

0 comments on commit f90f4ce

Please sign in to comment.