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.
parent
0c7ea88323
commit
af6e043239
|
@ -35,5 +35,7 @@ public interface ClientDetailsEntityService extends ClientDetailsService {
|
|||
|
||||
public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient);
|
||||
|
||||
public ClientDetailsEntity saveClient(ClientDetailsEntity client);
|
||||
|
||||
public Collection<ClientDetailsEntity> getAllClients();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.mitre.oauth2.service.impl;
|
|||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.mitre.oauth2.model.ClientDetailsEntity;
|
||||
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!");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package org.mitre.openid.connect.web;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.mitre.oauth2.exception.ClientNotFoundException;
|
||||
import org.mitre.oauth2.model.ClientDetailsEntity;
|
||||
import org.mitre.oauth2.service.ClientDetailsEntityService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Michael Jett <mjett@mitre.org>
|
||||
|
@ -62,10 +64,7 @@ public class ClientAPI {
|
|||
public String apiAddClient(@RequestBody String json, Model m) {
|
||||
|
||||
ClientDetailsEntity client = new Gson().fromJson(json, ClientDetailsEntity.class);
|
||||
|
||||
m.addAttribute("entity", client);
|
||||
|
||||
clientService.createClient(client);
|
||||
m.addAttribute("entity", clientService.saveClient(client));
|
||||
|
||||
return "jsonClientView";
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
// We can pass it default values.
|
||||
defaults:{
|
||||
clientName:"my name",
|
||||
//registeredRedirectUri:["http://myURL.domain"],
|
||||
/*grantType:["my grant type 1", "my grant type 2"],
|
||||
scope:["scope 1", "scope 2"],
|
||||
authority:"my authority",*/
|
||||
clientDescription:"my description",
|
||||
clientId:"123"
|
||||
//refreshTokens:false
|
||||
clientName:"",
|
||||
registeredRedirectUri:[],
|
||||
authorizedGrantTypes:[],
|
||||
scope:[],
|
||||
authorities:[],
|
||||
clientDescription:"",
|
||||
clientId:null,
|
||||
allowRefresh:false
|
||||
},
|
||||
|
||||
urlRoot:"/api/clients"
|
||||
|
@ -110,7 +110,7 @@
|
|||
saveClient:function () {
|
||||
this.model.set({
|
||||
clientName:$('#clientName').val(),
|
||||
//registeredRedirectUri:[$('#registeredRedirectUri').val()],
|
||||
registeredRedirectUri:[$('#registeredRedirectUri').val()],
|
||||
clientDescription:$('#clientDescription').val()
|
||||
});
|
||||
if (this.model.isNew()) {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<script type="text/html" id="tmpl-client">
|
||||
|
||||
<td>
|
||||
<%=name%>
|
||||
<%=clientName%>
|
||||
</td>
|
||||
<td>
|
||||
<%=redirectURL%>
|
||||
<%=registeredRedirectUri[0]%>
|
||||
</td>
|
||||
<td>
|
||||
<ul>
|
||||
<% for (var i in grantType) { %>
|
||||
<% for (var i in authorizedGrantTypes) { %>
|
||||
<li>
|
||||
<%=grantType[i]%>
|
||||
<%=authorizedGrantTypes[i]%>
|
||||
</li>
|
||||
<% } %>
|
||||
</ul>
|
||||
|
@ -25,13 +25,13 @@
|
|||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<%=authority%>
|
||||
<%=authorities[0]%>
|
||||
</td>
|
||||
<td>
|
||||
<%=description%>
|
||||
<%=clientDescription%>
|
||||
</td>
|
||||
<td><input type="checkbox"
|
||||
<%=(refreshTokens == 1 ? 'checked' : '')%>
|
||||
<%=(allowRefresh == 1 ? 'checked' : '')%>
|
||||
value="" id="" name="" disabled>
|
||||
</td>
|
||||
<td>
|
||||
|
|
Loading…
Reference in New Issue