From 0c7ea88323e81572a64f4fd6c94b6acff713ba94 Mon Sep 17 00:00:00 2001 From: Michael Jett Date: Tue, 15 May 2012 17:03:17 -0400 Subject: [PATCH] Client updates. --- .../oauth2/model/ClientDetailsEntity.java | 24 +++++++++---------- .../service/ClientDetailsEntityService.java | 4 +++- ...faultOAuth2ClientDetailsEntityService.java | 9 +++++++ .../mitre/openid/connect/web/ClientAPI.java | 16 +++++++++---- .../src/main/webapp/resources/js/app.js | 19 ++++++++------- .../webapp/resources/template/client.html | 6 ++--- 6 files changed, 49 insertions(+), 29 deletions(-) diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientDetailsEntity.java b/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientDetailsEntity.java index 422f81129..cfa3165e7 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientDetailsEntity.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientDetailsEntity.java @@ -55,21 +55,21 @@ public class ClientDetailsEntity implements ClientDetails { public enum AuthType { client_secret_post, client_secret_basic, client_secret_jwt, private_key_jwt - }; + } - private String clientId; - private String clientSecret; - private Set scope; - private Set authorizedGrantTypes; + private String clientId = ""; + private String clientSecret = ""; + private Set scope= Collections.emptySet(); + private Set authorizedGrantTypes= Collections.emptySet(); private Set authorities = Collections.emptySet(); - private String clientName; - private String clientDescription; + private String clientName= ""; + private String clientDescription = ""; private boolean allowRefresh = false; // do we allow refresh tokens for this client? - private Integer accessTokenTimeout; // in seconds - private Integer refreshTokenTimeout; // in seconds - private String owner; // userid of who registered it - private Set registeredRedirectUri; - private Set resourceIds; + private Integer accessTokenTimeout = 0; // in seconds + private Integer refreshTokenTimeout = 0; // in seconds + private String owner = ""; // userid of who registered it + private Set registeredRedirectUri = Collections.emptySet(); + private Set resourceIds = Collections.emptySet(); //Additional properties added by OpenID Connect Dynamic Client Registration spec //http://openid.net/specs/openid-connect-registration-1_0.html diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/service/ClientDetailsEntityService.java b/openid-connect-common/src/main/java/org/mitre/oauth2/service/ClientDetailsEntityService.java index ba62e309c..7f94fe264 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/service/ClientDetailsEntityService.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/service/ClientDetailsEntityService.java @@ -28,7 +28,9 @@ public interface ClientDetailsEntityService extends ClientDetailsService { public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception; public ClientDetailsEntity createClient(String clientId, String clientSecret, Set scope, Set grantTypes, String redirectUri, Set authorities, Set resourceIds, String name, String description, boolean allowRefresh, Integer accessTokenTimeout, Integer refreshTokenTimeout, String owner); - + + public ClientDetailsEntity createClient(ClientDetailsEntity client); + public void deleteClient(ClientDetailsEntity client); public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient); diff --git a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ClientDetailsEntityService.java b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ClientDetailsEntityService.java index 3a607353d..bec6726c1 100644 --- a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ClientDetailsEntityService.java +++ b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ClientDetailsEntityService.java @@ -108,6 +108,15 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt return client; } + + @Override + public ClientDetailsEntity createClient(ClientDetailsEntity client) { + + clientRepository.saveClient(client); + + return client; + + } /** * Delete a client and all its associated tokens diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientAPI.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientAPI.java index 1f29bce10..d92f9ae93 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientAPI.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ClientAPI.java @@ -15,6 +15,7 @@ ******************************************************************************/ package org.mitre.openid.connect.web; +import com.google.gson.Gson; import org.mitre.oauth2.model.ClientDetailsEntity; import org.mitre.oauth2.service.ClientDetailsEntityService; import org.springframework.beans.factory.annotation.Autowired; @@ -22,6 +23,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; @@ -56,13 +58,19 @@ public class ClientAPI { return modelAndView; } - @RequestMapping(method = RequestMethod.POST, headers="Accept=application/json") - @ResponseBody - public ClientDetailsEntity apiAddClient(@RequestBody ClientDetailsEntity c) { + @RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json") + public String apiAddClient(@RequestBody String json, Model m) { - 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") @ResponseBody public Object apiShowClient(@PathVariable("id") Long id, ModelAndView modelAndView) { diff --git a/openid-connect-server/src/main/webapp/resources/js/app.js b/openid-connect-server/src/main/webapp/resources/js/app.js index 283dc20db..51c9434f5 100644 --- a/openid-connect-server/src/main/webapp/resources/js/app.js +++ b/openid-connect-server/src/main/webapp/resources/js/app.js @@ -4,13 +4,14 @@ // We can pass it default values. defaults:{ - name:null, - redirectURL:"http://myURL.domain", - grantType:["my grant type 1", "my grant type 2"], + clientName:"my name", + //registeredRedirectUri:["http://myURL.domain"], + /*grantType:["my grant type 1", "my grant type 2"], scope:["scope 1", "scope 2"], - authority:"my authority", - description:"my description", - refreshTokens:false + authority:"my authority",*/ + clientDescription:"my description", + clientId:"123" + //refreshTokens:false }, urlRoot:"/api/clients" @@ -108,9 +109,9 @@ saveClient:function () { this.model.set({ - name:$('#name').val(), - redirectURL:$('#redirectURL').val(), - description:$('#description').val() + clientName:$('#clientName').val(), + //registeredRedirectUri:[$('#registeredRedirectUri').val()], + clientDescription:$('#clientDescription').val() }); if (this.model.isNew()) { var self = this; diff --git a/openid-connect-server/src/main/webapp/resources/template/client.html b/openid-connect-server/src/main/webapp/resources/template/client.html index 73b261d23..425949a8c 100644 --- a/openid-connect-server/src/main/webapp/resources/template/client.html +++ b/openid-connect-server/src/main/webapp/resources/template/client.html @@ -87,14 +87,14 @@
- Associated help text! + Associated help text! - Associated help text! + Associated help text!
- Associated help text!