From 3402a3e46337182866fe9d2af6765d854021ed1c Mon Sep 17 00:00:00 2001 From: Michael Jett <mjett@mitre.org> Date: Wed, 16 May 2012 14:32:40 -0400 Subject: [PATCH] ClientAPI now fully supports RESTful DELETE --- .../oauth2/model/ClientDetailsEntity.java | 44 ++++++++----------- .../mitre/openid/connect/web/ClientAPI.java | 6 +-- .../src/main/webapp/resources/js/app.js | 16 ++++++- 3 files changed, 36 insertions(+), 30 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 cfa3165e7..96d9f8b1a 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 @@ -19,18 +19,10 @@ package org.mitre.oauth2.model; import java.util.Collections; +import java.util.HashSet; import java.util.Set; -import javax.persistence.Basic; -import javax.persistence.CollectionTable; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; +import javax.persistence.*; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.oauth2.provider.ClientDetails; @@ -56,22 +48,22 @@ 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<String> scope= Collections.emptySet(); - private Set<String> authorizedGrantTypes= Collections.emptySet(); - private Set<GrantedAuthority> authorities = Collections.emptySet(); - private String clientName= ""; - private String clientDescription = ""; - private boolean allowRefresh = false; // do we allow refresh tokens for this client? - private Integer accessTokenTimeout = 0; // in seconds - private Integer refreshTokenTimeout = 0; // in seconds - private String owner = ""; // userid of who registered it - private Set<String> registeredRedirectUri = Collections.emptySet(); - private Set<String> resourceIds = Collections.emptySet(); - //Additional properties added by OpenID Connect Dynamic Client Registration spec + private String clientId = ""; + private String clientSecret = ""; + private Set<String> scope = new HashSet<String>(); + private Set<String> authorizedGrantTypes = new HashSet<String>(); + private Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); + private String clientName = ""; + private String clientDescription = ""; + private boolean allowRefresh = false; // do we allow refresh tokens for this client? + private Integer accessTokenTimeout = 0; // in seconds + private Integer refreshTokenTimeout = 0; // in seconds + private String owner = ""; // userid of who registered it + private Set<String> registeredRedirectUri = new HashSet<String>(); + private Set<String> resourceIds = new HashSet<String>(); + + //Additional properties added by OpenID Connect Dynamic Client Registration spec //http://openid.net/specs/openid-connect-registration-1_0.html /** @@ -122,7 +114,7 @@ public class ClientDetailsEntity implements ClientDetails { /** * @return the clientId */ - @Id + @Id @GeneratedValue public String getClientId() { return clientId; } 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 f517eb5ad..9bf46eeac 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 @@ -69,10 +69,10 @@ public class ClientAPI { return "jsonClientView"; } - @RequestMapping(method = RequestMethod.DELETE, headers = "Accept=application/json") - public String apiDeleteClient(@RequestBody String json, Model m) { + @RequestMapping(value="/{id}", method=RequestMethod.DELETE, headers="Accept=application/json") + public String apiDeleteClient(@PathVariable("id") String id, ModelAndView modelAndView) { - ClientDetailsEntity client = new Gson().fromJson(json, ClientDetailsEntity.class); + ClientDetailsEntity client = clientService.loadClientByClientId(id); clientService.deleteClient(client); return "jsonClientView"; 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 7b82fb6a6..368dacc86 100644 --- a/openid-connect-server/src/main/webapp/resources/js/app.js +++ b/openid-connect-server/src/main/webapp/resources/js/app.js @@ -2,6 +2,8 @@ var ClientModel = Backbone.Model.extend({ + idAttribute: "clientId", + // We can pass it default values. defaults:{ clientName:"", @@ -53,7 +55,19 @@ }, deleteClient:function () { - alert('delete'); + + var self = this; + + this.model.destroy({ + success:function () { + self.$el.fadeTo("slow", 0.00, function(){ //fade + $(this).slideUp("slow", function() { //slide up + $(this).remove(); //then remove from the DOM + }); + }); + } + }); + return false; }, close:function () {