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

View File

@ -187,7 +187,8 @@
<bean id="jwkKeyList" class="org.mitre.openid.connect.view.JwkKeyListView" />
<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 -->

View File

@ -15,7 +15,7 @@
<meta name="author" content="">
<!-- 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">
<style type="text/css">