added empty http code view
parent
8ae1b376fe
commit
b462d6dd96
|
@ -0,0 +1,34 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.mitre.openid.connect.view;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.servlet.view.AbstractView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An empty view that simply returns an HTTP code set in the model
|
||||||
|
* @author jricher
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Component("httpCodeView")
|
||||||
|
public class HttpCodeView extends AbstractView {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
HttpStatus code = (HttpStatus) model.get("code");
|
||||||
|
if (code == null) {
|
||||||
|
code = HttpStatus.OK; // default to 200
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setStatus(code.value());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import org.mitre.oauth2.model.ClientDetailsEntity;
|
||||||
import org.mitre.openid.connect.model.WhitelistedSite;
|
import org.mitre.openid.connect.model.WhitelistedSite;
|
||||||
import org.mitre.openid.connect.service.WhitelistedSiteService;
|
import org.mitre.openid.connect.service.WhitelistedSiteService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
|
@ -90,15 +91,16 @@ public class WhitelistApi {
|
||||||
WhitelistedSite oldWhitelist = whitelistService.getById(id);
|
WhitelistedSite oldWhitelist = whitelistService.getById(id);
|
||||||
|
|
||||||
if (oldWhitelist == null) {
|
if (oldWhitelist == null) {
|
||||||
// TODO: throw new "entity not found"
|
m.put("code", HttpStatus.NOT_FOUND);
|
||||||
|
return "httpCodeView";
|
||||||
|
} else {
|
||||||
|
|
||||||
|
WhitelistedSite newWhitelist = whitelistService.update(oldWhitelist, whitelist);
|
||||||
|
|
||||||
|
m.put("entity", newWhitelist);
|
||||||
|
|
||||||
|
return "jsonEntityView";
|
||||||
}
|
}
|
||||||
|
|
||||||
WhitelistedSite newWhitelist = whitelistService.update(oldWhitelist, whitelist);
|
|
||||||
|
|
||||||
m.put("entity", newWhitelist);
|
|
||||||
|
|
||||||
return "jsonEntityView";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,13 +112,12 @@ public class WhitelistApi {
|
||||||
WhitelistedSite whitelist = whitelistService.getById(id);
|
WhitelistedSite whitelist = whitelistService.getById(id);
|
||||||
|
|
||||||
if (whitelist == null) {
|
if (whitelist == null) {
|
||||||
// TODO: throw new "entity not found"
|
m.put("code", HttpStatus.NOT_FOUND);
|
||||||
|
} else {
|
||||||
|
whitelistService.remove(whitelist);
|
||||||
}
|
}
|
||||||
|
|
||||||
whitelistService.remove(whitelist);
|
return "httpCodeView";
|
||||||
|
|
||||||
// TODO: not really an entity view, more of an empty view w/code
|
|
||||||
return "jsonEntityView";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,12 +127,14 @@ public class WhitelistApi {
|
||||||
public String getWhitelistedSite(@PathVariable("id") Long id, ModelMap m) {
|
public String getWhitelistedSite(@PathVariable("id") Long id, ModelMap m) {
|
||||||
WhitelistedSite whitelist = whitelistService.getById(id);
|
WhitelistedSite whitelist = whitelistService.getById(id);
|
||||||
if (whitelist == null) {
|
if (whitelist == null) {
|
||||||
// TODO: throw new "entity not found"
|
m.put("code", HttpStatus.NOT_FOUND);
|
||||||
|
return "httpCodeView";
|
||||||
|
} else {
|
||||||
|
|
||||||
|
m.put("entity", whitelist);
|
||||||
|
|
||||||
|
return "jsonEntityView";
|
||||||
}
|
}
|
||||||
|
|
||||||
m.put("entity", whitelist);
|
|
||||||
|
|
||||||
return "jsonEntityView";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue