Skip to content

Commit

Permalink
SHIBUI-2393/2474
Browse files Browse the repository at this point in the history
Added checking for required fields
  • Loading branch information
chasegawa committed Nov 28, 2022
1 parent 63cd583 commit 2d5cbfa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException;
import edu.internet2.tier.shibboleth.admin.ui.exception.InvalidPatternMatchException;
import edu.internet2.tier.shibboleth.admin.ui.exception.MissingRequiredFieldsException;
import edu.internet2.tier.shibboleth.admin.ui.exception.ObjectIdExistsException;
import edu.internet2.tier.shibboleth.admin.ui.exception.PersistentEntityNotFound;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -46,4 +47,9 @@ public ResponseEntity<?> handleObjectIdExistsException(ObjectIdExistsException e
String.format("The persistent entity with id [%s] already exists.", e.getMessage())));

}

@ExceptionHandler({ MissingRequiredFieldsException.class })
public ResponseEntity<?> handleMissingRequiredFieldsException(MissingRequiredFieldsException e, WebRequest request) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(HttpStatus.BAD_REQUEST, e.getMessage()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.exception;

public class MissingRequiredFieldsException extends Exception {
public MissingRequiredFieldsException(String entityId) {
super(entityId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.DynamicRegistrationRepresentation;
import edu.internet2.tier.shibboleth.admin.ui.domain.oidc.DynamicRegistrationInfo;
import edu.internet2.tier.shibboleth.admin.ui.exception.ForbiddenException;
import edu.internet2.tier.shibboleth.admin.ui.exception.MissingRequiredFieldsException;
import edu.internet2.tier.shibboleth.admin.ui.exception.ObjectIdExistsException;
import edu.internet2.tier.shibboleth.admin.ui.exception.PersistentEntityNotFound;
import edu.internet2.tier.shibboleth.admin.ui.exception.UnsupportedShibUiOperationException;
Expand Down Expand Up @@ -83,11 +84,15 @@ private DynamicRegistrationRepresentation changeApproveStatusOfDynamicRepresenta
}

@Override
public DynamicRegistrationRepresentation createNew(DynamicRegistrationRepresentation dynRegRepresentation) throws ObjectIdExistsException {
public DynamicRegistrationRepresentation createNew(DynamicRegistrationRepresentation dynRegRepresentation) throws ObjectIdExistsException, MissingRequiredFieldsException {
if (entityExists(dynRegRepresentation.getResourceId())) {
throw new ObjectIdExistsException(dynRegRepresentation.getResourceId());
}

if (StringUtils.isEmpty(dynRegRepresentation.getName()) || StringUtils.isEmpty(dynRegRepresentation.getRedirectUris())) {
throw new MissingRequiredFieldsException("Name and Redirect URIs are both required to create new Dynamic Registration");
}

DynamicRegistrationInfo dri = dynRegRepresentation.buildDynamicRegistrationInfo();
dri.setEnabled(false); // cannot create as enabled

Expand Down

0 comments on commit 2d5cbfa

Please sign in to comment.