Client Entity now initialized with non-null values so JPA won't flip. Added unified method for saving. Sync'd class member names to allow proper binding.

pull/105/merge
Michael Jett 2012-05-16 13:27:53 -04:00
parent 0c7ea88323
commit af6e043239
5 changed files with 41 additions and 20 deletions

View File

@ -35,5 +35,7 @@ public interface ClientDetailsEntityService extends ClientDetailsService {
public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient); public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient);
public ClientDetailsEntity saveClient(ClientDetailsEntity client);
public Collection<ClientDetailsEntity> getAllClients(); public Collection<ClientDetailsEntity> getAllClients();
} }

View File

@ -18,6 +18,7 @@ package org.mitre.oauth2.service.impl;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.mitre.oauth2.model.ClientDetailsEntity; import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.oauth2.model.ClientDetailsEntityFactory; import org.mitre.oauth2.model.ClientDetailsEntityFactory;
@ -148,6 +149,25 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
throw new IllegalArgumentException("Neither old client or new client can be null!"); throw new IllegalArgumentException("Neither old client or new client can be null!");
} }
/**
*
* @param client object to be saved
* @return ClientDetailsEntity the saved object
*/
@Override
public ClientDetailsEntity saveClient(ClientDetailsEntity client) {
// this must be a new client if we don't have a clientID
// assign it a new ID
if (client.getClientId() == null || this.loadClientByClientId(client.getClientId()) == null) {
client.setClientId(UUID.randomUUID().toString());
return this.createClient(client);
} else {
return clientRepository.updateClient(client.getClientId(), client);
}
}
/** /**
* Get all clients in the system * Get all clients in the system
*/ */

View File

@ -16,6 +16,7 @@
package org.mitre.openid.connect.web; package org.mitre.openid.connect.web;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.mitre.oauth2.exception.ClientNotFoundException;
import org.mitre.oauth2.model.ClientDetailsEntity; import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.oauth2.service.ClientDetailsEntityService; import org.mitre.oauth2.service.ClientDetailsEntityService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
/** /**
* @author Michael Jett <mjett@mitre.org> * @author Michael Jett <mjett@mitre.org>
@ -62,10 +64,7 @@ public class ClientAPI {
public String apiAddClient(@RequestBody String json, Model m) { public String apiAddClient(@RequestBody String json, Model m) {
ClientDetailsEntity client = new Gson().fromJson(json, ClientDetailsEntity.class); ClientDetailsEntity client = new Gson().fromJson(json, ClientDetailsEntity.class);
m.addAttribute("entity", clientService.saveClient(client));
m.addAttribute("entity", client);
clientService.createClient(client);
return "jsonClientView"; return "jsonClientView";
} }

View File

@ -4,14 +4,14 @@
// We can pass it default values. // We can pass it default values.
defaults:{ defaults:{
clientName:"my name", clientName:"",
//registeredRedirectUri:["http://myURL.domain"], registeredRedirectUri:[],
/*grantType:["my grant type 1", "my grant type 2"], authorizedGrantTypes:[],
scope:["scope 1", "scope 2"], scope:[],
authority:"my authority",*/ authorities:[],
clientDescription:"my description", clientDescription:"",
clientId:"123" clientId:null,
//refreshTokens:false allowRefresh:false
}, },
urlRoot:"/api/clients" urlRoot:"/api/clients"
@ -110,7 +110,7 @@
saveClient:function () { saveClient:function () {
this.model.set({ this.model.set({
clientName:$('#clientName').val(), clientName:$('#clientName').val(),
//registeredRedirectUri:[$('#registeredRedirectUri').val()], registeredRedirectUri:[$('#registeredRedirectUri').val()],
clientDescription:$('#clientDescription').val() clientDescription:$('#clientDescription').val()
}); });
if (this.model.isNew()) { if (this.model.isNew()) {

View File

@ -1,16 +1,16 @@
<script type="text/html" id="tmpl-client"> <script type="text/html" id="tmpl-client">
<td> <td>
<%=name%> <%=clientName%>
</td> </td>
<td> <td>
<%=redirectURL%> <%=registeredRedirectUri[0]%>
</td> </td>
<td> <td>
<ul> <ul>
<% for (var i in grantType) { %> <% for (var i in authorizedGrantTypes) { %>
<li> <li>
<%=grantType[i]%> <%=authorizedGrantTypes[i]%>
</li> </li>
<% } %> <% } %>
</ul> </ul>
@ -25,13 +25,13 @@
</ul> </ul>
</td> </td>
<td> <td>
<%=authority%> <%=authorities[0]%>
</td> </td>
<td> <td>
<%=description%> <%=clientDescription%>
</td> </td>
<td><input type="checkbox" <td><input type="checkbox"
<%=(refreshTokens == 1 ? 'checked' : '')%> <%=(allowRefresh == 1 ? 'checked' : '')%>
value="" id="" name="" disabled> value="" id="" name="" disabled>
</td> </td>
<td> <td>