Client updates.

pull/105/merge
Michael Jett 2012-05-15 17:03:17 -04:00
parent 0f9b828066
commit 0c7ea88323
6 changed files with 49 additions and 29 deletions

View File

@ -55,21 +55,21 @@ public class ClientDetailsEntity implements ClientDetails {
public enum AuthType { public enum AuthType {
client_secret_post, client_secret_basic, client_secret_jwt, private_key_jwt client_secret_post, client_secret_basic, client_secret_jwt, private_key_jwt
}; }
private String clientId; private String clientId = "";
private String clientSecret; private String clientSecret = "";
private Set<String> scope; private Set<String> scope= Collections.emptySet();
private Set<String> authorizedGrantTypes; private Set<String> authorizedGrantTypes= Collections.emptySet();
private Set<GrantedAuthority> authorities = Collections.emptySet(); private Set<GrantedAuthority> authorities = Collections.emptySet();
private String clientName; private String clientName= "";
private String clientDescription; private String clientDescription = "";
private boolean allowRefresh = false; // do we allow refresh tokens for this client? private boolean allowRefresh = false; // do we allow refresh tokens for this client?
private Integer accessTokenTimeout; // in seconds private Integer accessTokenTimeout = 0; // in seconds
private Integer refreshTokenTimeout; // in seconds private Integer refreshTokenTimeout = 0; // in seconds
private String owner; // userid of who registered it private String owner = ""; // userid of who registered it
private Set<String> registeredRedirectUri; private Set<String> registeredRedirectUri = Collections.emptySet();
private Set<String> resourceIds; private Set<String> resourceIds = Collections.emptySet();
//Additional properties added by OpenID Connect Dynamic Client Registration spec //Additional properties added by OpenID Connect Dynamic Client Registration spec
//http://openid.net/specs/openid-connect-registration-1_0.html //http://openid.net/specs/openid-connect-registration-1_0.html

View File

@ -28,7 +28,9 @@ public interface ClientDetailsEntityService extends ClientDetailsService {
public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception; public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception;
public ClientDetailsEntity createClient(String clientId, String clientSecret, Set<String> scope, Set<String> grantTypes, String redirectUri, Set<GrantedAuthority> authorities, Set<String> resourceIds, String name, String description, boolean allowRefresh, Integer accessTokenTimeout, Integer refreshTokenTimeout, String owner); public ClientDetailsEntity createClient(String clientId, String clientSecret, Set<String> scope, Set<String> grantTypes, String redirectUri, Set<GrantedAuthority> authorities, Set<String> resourceIds, String name, String description, boolean allowRefresh, Integer accessTokenTimeout, Integer refreshTokenTimeout, String owner);
public ClientDetailsEntity createClient(ClientDetailsEntity client);
public void deleteClient(ClientDetailsEntity client); public void deleteClient(ClientDetailsEntity client);
public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient); public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient);

View File

@ -108,6 +108,15 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
return client; return client;
} }
@Override
public ClientDetailsEntity createClient(ClientDetailsEntity client) {
clientRepository.saveClient(client);
return client;
}
/** /**
* Delete a client and all its associated tokens * Delete a client and all its associated tokens

View File

@ -15,6 +15,7 @@
******************************************************************************/ ******************************************************************************/
package org.mitre.openid.connect.web; package org.mitre.openid.connect.web;
import com.google.gson.Gson;
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;
@ -22,6 +23,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
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.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
@ -56,13 +58,19 @@ public class ClientAPI {
return modelAndView; return modelAndView;
} }
@RequestMapping(method = RequestMethod.POST, headers="Accept=application/json") @RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json")
@ResponseBody public String apiAddClient(@RequestBody String json, Model m) {
public ClientDetailsEntity apiAddClient(@RequestBody ClientDetailsEntity c) {
return null; ClientDetailsEntity client = new Gson().fromJson(json, ClientDetailsEntity.class);
m.addAttribute("entity", client);
clientService.createClient(client);
return "jsonClientView";
} }
@RequestMapping(value="/{id}", method=RequestMethod.GET, headers="Accept=application/json") @RequestMapping(value="/{id}", method=RequestMethod.GET, headers="Accept=application/json")
@ResponseBody @ResponseBody
public Object apiShowClient(@PathVariable("id") Long id, ModelAndView modelAndView) { public Object apiShowClient(@PathVariable("id") Long id, ModelAndView modelAndView) {

View File

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

View File

@ -87,14 +87,14 @@
<div class="row-fluid"> <div class="row-fluid">
<div class="span6"> <div class="span6">
<label>Client name</label> <label>Client name</label>
<input id="name" type="text" class="" placeholder="Type something"> <span class="help-inline">Associated help text!</span> <input id="clientName" type="text" class="" placeholder="Type something"> <span class="help-inline">Associated help text!</span>
<label>Redirect URL</label> <label>Redirect URL</label>
<input id="redirectURL" type="text" class="" placeholder="http://"><span class="help-inline">Associated help text!</span> <input id="registeredRedirectUri" type="text" class="" placeholder="http://"><span class="help-inline">Associated help text!</span>
</div> </div>
<div class="span6"> <div class="span6">
<label>Description</label> <label>Description</label>
<textarea id="description" class="input-xlarge" placeholder="Type a description" <textarea id="clientDescription" class="input-xlarge" placeholder="Type a description"
rows="3"></textarea> <span class="help-inline">Associated help text!</span> rows="3"></textarea> <span class="help-inline">Associated help text!</span>
</div> </div>
</div> </div>