Client API now renders JSON for all Clients

pull/67/merge
Michael Jett 2012-05-08 11:16:45 -04:00
parent ba56c00318
commit eda7505b7b
4 changed files with 98 additions and 20 deletions

View File

@ -0,0 +1,61 @@
package org.mitre.openid.connect.view;
/**
* @author Michael Jett <mjett@mitre.org>
*/
import java.io.Writer;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.web.servlet.view.AbstractView;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class JSONOAuthClientView extends AbstractView{
/* (non-Javadoc)
* @see org.springframework.web.servlet.view.AbstractView#renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void renderMergedOutputModel(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Gson gson = new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
public boolean shouldSkipField(FieldAttributes f) {
return false;
}
public boolean shouldSkipClass(Class<?> clazz) {
// skip the JPA binding wrapper
if (clazz.equals(BeanPropertyBindingResult.class)) {
return true;
}
return false;
}
}).create();
response.setContentType("application/json");
Writer out = response.getWriter();
Object obj = model.get("entity");
if (obj == null) {
obj = model;
}
gson.toJson(obj, out);
}
}

View File

@ -15,20 +15,28 @@
******************************************************************************/ ******************************************************************************/
package org.mitre.openid.connect.web; package org.mitre.openid.connect.web;
import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.oauth2.service.ClientDetailsEntityService;
import org.springframework.beans.factory.annotation.Autowired;
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.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.Collection;
/** /**
* @author Michael Jett <mjett@mitre.org> * @author Michael Jett <mjett@mitre.org>
*/ */
@Controller @Controller
@RequestMapping("/manager/clients/api") @RequestMapping("/api/clients")
public class ClientAPI { public class ClientAPI {
@Autowired
private ClientDetailsEntityService clientService;
/** /**
* constructor * constructor
*/ */
@ -36,6 +44,19 @@ public class ClientAPI {
} }
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping("")
public ModelAndView apiGetAllClients(ModelAndView modelAndView) {
Collection<ClientDetailsEntity> clients = clientService.getAllClients();
modelAndView.addObject("entity", clients);
modelAndView.setViewName("jsonClientView");
return modelAndView;
}
/*
*/
/** /**
* *
* @param modelAndView * @param modelAndView
@ -52,7 +73,8 @@ public class ClientAPI {
* @param refreshTokenTimeout * @param refreshTokenTimeout
* @param owner * @param owner
* @return * @return
*/ *//*
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping("/add") @RequestMapping("/add")
public ModelAndView apiAddClient(ModelAndView modelAndView, public ModelAndView apiAddClient(ModelAndView modelAndView,
@ -71,31 +93,25 @@ public class ClientAPI {
return null; return null;
} }
*/
/** /**
* *
* @param modelAndView * @param modelAndView
* @param clientId * @param clientId
* @return * @return
*/ *//*
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping("/delete") @RequestMapping("/delete")
public ModelAndView apiDeleteClient(ModelAndView modelAndView, public ModelAndView apiDeleteClient(ModelAndView modelAndView,
@RequestParam String clientId) { @RequestParam String clientId) {
return null; return null;
} }
/**
*
* @param modelAndView
* @return
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping("/getAll")
public ModelAndView apiGetAllClients(ModelAndView modelAndView) {
return null;
}
/**
/* *//**
* *
* @param modelAndView * @param modelAndView
* @param clientId * @param clientId
@ -111,7 +127,7 @@ public class ClientAPI {
* @param refreshTokenTimeout * @param refreshTokenTimeout
* @param owner * @param owner
* @return * @return
*/ *//*
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping("/update") @RequestMapping("/update")
public ModelAndView apiUpdateClient(ModelAndView modelAndView, public ModelAndView apiUpdateClient(ModelAndView modelAndView,
@ -128,5 +144,5 @@ public class ClientAPI {
@RequestParam(required = false) String owner @RequestParam(required = false) String owner
) { ) {
return null; return null;
} }*/
} }

View File

@ -188,6 +188,7 @@
<bean id="jsonUserInfoView" class="org.mitre.openid.connect.view.JSONUserInfoView"/> <bean id="jsonUserInfoView" class="org.mitre.openid.connect.view.JSONUserInfoView"/>
<bean id="jsonIdTokenView" class="org.mitre.openid.connect.view.JSONIdTokenView"/> <bean id="jsonIdTokenView" class="org.mitre.openid.connect.view.JSONIdTokenView"/>
<bean id="jsonClientView" class="org.mitre.openid.connect.view.JSONOAuthClientView" />
<!-- End view configuration --> <!-- End view configuration -->

View File

@ -15,7 +15,7 @@
<meta name="author" content=""> <meta name="author" content="">
<!-- Le styles --> <!-- Le styles -->
<link href="resources/bootstrap2/css/bootstrap.css" rel="stylesheet"> <link href="resources/bootstrap2/css/bootstrap.min.css" rel="stylesheet">
<link href="resources/bootstrap2/css/bootstrap-responsive.css" rel="stylesheet"> <link href="resources/bootstrap2/css/bootstrap-responsive.css" rel="stylesheet">
<style type="text/css"> <style type="text/css">