Author: [email protected]
Date: Mon Jul 18 16:35:28 2011
New Revision: 1217

Log:
[AMDATUAUTH-68] Finalized REST API and UI

Added:
   
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/AMDATUhit.jpg   
(contents, props changed)
   trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/cr.css
   trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.html
   trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/static/js/
Modified:
   
trunk/amdatu-auth/oauth-api/src/main/java/org/amdatu/authentication/oauth/api/OAuthServiceConsumer.java
   
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
   
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumersBean.java
   trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.jsp
   trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/static/css/cr.css
   
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthServiceConsumerRegistryTest.java

Modified: 
trunk/amdatu-auth/oauth-api/src/main/java/org/amdatu/authentication/oauth/api/OAuthServiceConsumer.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-api/src/main/java/org/amdatu/authentication/oauth/api/OAuthServiceConsumer.java
     (original)
+++ 
trunk/amdatu-auth/oauth-api/src/main/java/org/amdatu/authentication/oauth/api/OAuthServiceConsumer.java
     Mon Jul 18 16:35:28 2011
@@ -74,7 +74,9 @@
      * 
      * @return The URL to which a user will be redirected after a request 
token has been authorized.
      */
-    String getCallbackUrl();
+    String getCallbackUrl();
+    
+    void setCallbackUrl(String callbackUrl);
 
     /**
      * Map of arbitrary additional properties stored in the service consumer. 
This could for example be used

Modified: 
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
   (original)
+++ 
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
   Mon Jul 18 16:35:28 2011
@@ -67,23 +67,23 @@
 @Path("oauth/consumers")
 public class OAuthServiceConsumerRegistryRESTImpl implements 
OAuthServiceConsumerRegistryREST {
     private final static String ALIAS = "/rest/oauth/consumers";
-    
+
     // FIXME: Temporary fix for AMDATUAUTH-49. Until a generic approach has 
been defined 
     // to handle authorization of REST services, we verify that the current 
user is in the
     // role "Administrator"
     private static final String DEFAULT_ADMIN_GROUP = "Administrators";
-    
+
     // Tenant unaware service dependencies   
     private volatile LogService m_logService;
     private volatile Tenant m_tenant;
     private volatile Component m_component;
     private volatile DependencyManager m_dependencyManager;
-    
+
     // Tenant aware service dependencies
     private volatile TokenProvider m_tokenProvider;
     private volatile OAuthServiceConsumerRegistry m_registry;
     private volatile UserAdmin m_userAdmin;
-    
+
     // HTTP caching policy for this REST interface
     private static CacheControl NO_CACHE_CONTROL;
     static {
@@ -97,23 +97,23 @@
             .setService(TokenProvider.class, 
getTenantFilter(TokenProvider.class))
             .setRequired(true)
             .setInstanceBound(true));
-        
+
         m_component.add(m_dependencyManager.createServiceDependency()
             .setService(OAuthServiceConsumerRegistry.class, 
getTenantFilter(OAuthServiceConsumerRegistry.class))
             .setRequired(true)
             .setInstanceBound(true));
-        
+
         m_component.add(m_dependencyManager.createServiceDependency()
             .setService(UserAdmin.class, getTenantFilter(UserAdmin.class))
             .setRequired(true)
             .setInstanceBound(true));
     }
-    
+
     private String getTenantFilter(Class<?> clazz) {
         return "(&(" + Tenant.TENANT_ID_SERVICEPROPERTY + "=" + 
m_tenant.getId() + ")(" + Constants.OBJECTCLASS
-            + "=" + clazz.getName() + "))";
+        + "=" + clazz.getName() + "))";
     }
-    
+
     public void start() {
         m_logService.log(LogService.LOG_DEBUG, "OAuth Service Consumer 
registry REST service started.");
     }
@@ -129,7 +129,7 @@
     public String status() {
         return "OAuth Service Consumer registry online";
     }
-    
+
     /**
      * REST interface: GET /rest/oauth/consumers/{consumerKey}
      * Returns the requested consumer in application/xml or application/json 
format.
@@ -178,7 +178,7 @@
             OAuthServiceConsumer consumer = 
m_registry.getConsumer(consumerKey);
             if (consumer != null) {
                 return 
Response.ok(OAuthServiceConsumerBean.copy(consumer)).cacheControl(NO_CACHE_CONTROL)
-                    .build();
+                .build();
             }
             else {
                 return 
Response.status(HttpStatus.SC_NOT_FOUND).cacheControl(NO_CACHE_CONTROL).build();
@@ -215,7 +215,7 @@
             throw new WebApplicationException(e, 
Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
-    
+
     /**
      * REST interface: POST /rest/oauth/consumers
      * Adds a new consumer with a generated consumer key and secret and the 
properties of the posted 
@@ -233,7 +233,7 @@
             if (!isAuthorized(request)) {
                 return 
Response.status(HttpStatus.SC_UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
             }
-            
+
             // Now verify if a consumer with the specified name does not 
already exist
             OAuthServiceConsumer existingConsumer = 
m_registry.getConsumerByName(name);
             if (existingConsumer != null) {
@@ -243,30 +243,30 @@
                     + existingConsumer.getName() + "' is already in use. 
Register your application with a different name.");
                 return 
Response.status(HttpStatus.SC_BAD_REQUEST).cacheControl(NO_CACHE_CONTROL).entity(bean).build();
             }
-            
+
             // Verify that the callback URL starts with http, https or equals 
'oob'
             if (!callbackUrl.startsWith("http://";) && 
!callbackUrl.startsWith("https://";) && !"oob".equals(callbackUrl)) {
                 OAuthResultBean bean = new OAuthResultBean();
                 bean.setMessage("The callback URL is invalid. The callback URL 
must start with 'http://', 'https://' or equal 'oob'.");
                 return 
Response.status(HttpStatus.SC_BAD_REQUEST).cacheControl(NO_CACHE_CONTROL).entity(bean).build();
             }
-            
+
             // Generate a new consumer key and secret for this consumer
             OAuthServiceConsumerBean consumer = new OAuthServiceConsumerBean();
             consumer.setConsumerKey(generateNonce());
             consumer.setConsumerSecret(generateNonce());
             consumer.setName(name);
             consumer.setCallbackUrl(callbackUrl);
-            
+
             // Add the edit link
             consumer.setEditLink(ALIAS + "/" + consumer.getConsumerKey());
             consumer.addProperty(OAuthServiceConsumer.OWNERID, 
getCurrentUser(request).getName());
             m_registry.addConsumer(consumer);
-            
+
             // Remove properties, as these are of type Map<String, Object> 
which cannot be marhsalled 
             // from and to XML/JSON directly
             consumer.setProperties(null);
-            
+
             return 
Response.ok().cacheControl(NO_CACHE_CONTROL).entity(consumer).build();
         }
         catch (Exception e) {
@@ -284,11 +284,13 @@
      * @return The HTTP response object
      */
     @PUT
-    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+    @Consumes("application/x-www-form-urlencoded")
     @Path("{consumerKey}")
     public Response updateConsumer(@PathParam("consumerKey") final String 
consumerKey,
-        final OAuthServiceConsumerBean consumer) {
+        @FormParam("callbackurl") final String callbackUrl) {
         try {
+            OAuthServiceConsumer consumer = 
m_registry.getConsumer(consumerKey);
+            consumer.setCallbackUrl(callbackUrl);
             m_registry.updateConsumer(consumer);
             return Response.ok().cacheControl(NO_CACHE_CONTROL).build();
         }
@@ -298,6 +300,23 @@
         catch (ConsumerRegistryStorageException e) {
             throw new WebApplicationException(e, 
Response.Status.INTERNAL_SERVER_ERROR);
         }
+    }
+    
+    @PUT
+    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+    @Path("{consumerKey}")
+    public Response updateConsumerWithBean(@PathParam("consumerKey") final 
String consumerKey,
+        final OAuthServiceConsumerBean consumer) {
+        try {
+            m_registry.updateConsumer(consumer);
+            return Response.ok().cacheControl(NO_CACHE_CONTROL).build();
+        }
+        catch (ConsumerNotFoundException e) {
+            throw new WebApplicationException(Response.Status.NOT_FOUND);
+        }
+        catch (ConsumerRegistryStorageException e) {
+            throw new WebApplicationException(e, 
Response.Status.INTERNAL_SERVER_ERROR);
+        }
     }
 
     /**
@@ -320,14 +339,14 @@
             throw new WebApplicationException(e, 
Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
-    
+
     private String generateNonce() {
         Random random = new Random();
         byte[] randomBytes = new byte[32];
         random.nextBytes(randomBytes);
         return new BigInteger(1, randomBytes).toString(36);
     }
-    
+
     private boolean isAuthorized(final HttpServletRequest request) {
         try {
             User user = getCurrentUser(request);
@@ -341,7 +360,7 @@
         }
         return false;
     }
-    
+
     private User getCurrentUser(final HttpServletRequest request) throws 
TokenProviderException, InvalidTokenException {
         String token = m_tokenProvider.getTokenFromRequest(request);
         if (token != null) {

Modified: 
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumersBean.java
==============================================================================
--- 
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumersBean.java
      (original)
+++ 
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumersBean.java
      Mon Jul 18 16:35:28 2011
@@ -7,7 +7,7 @@
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlRootElement;
 
-@XmlRootElement(name = "consumers")
+@XmlRootElement(name = "result")
 @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
 public class OAuthServiceConsumersBean {
     private List<OAuthServiceConsumerBean> m_consumers;

Added: 
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/AMDATUhit.jpg
==============================================================================
Binary file. No diff available.

Added: trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/cr.css
==============================================================================
--- (empty file)
+++ trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/cr.css      
Mon Jul 18 16:35:28 2011
@@ -0,0 +1,58 @@
+body {
+  margin: 0px;
+  padding: 0;
+  background: #000000;
+  font-family: bookman old style;
+  font-size: 14px;
+  color: #999999;
+}
+
+table {
+  padding: 10px;
+}
+
+div.leftbox {
+  width:22%;
+  height:600px;
+  float:left;
+  margin-left:10px;
+  background: #282828;
+
+  border: #555555 1px;
+  -moz-border-radius: 15px;
+  border-radius: 15px;
+  border-style: solid;
+
+  box-shadow: 7px 7px 8px #555555;
+  -webkit-box-shadow: 7px 7px 8px #555555;
+  -moz-box-shadow: 7px 7px 8px #555555;
+  filter: progid:DXImageTransform.Microsoft.dropShadow(color=#555555, offX=7, 
offY=7, positive=true);
+}
+
+div.leftbox p {
+ margin-top:20px;
+ margin-left:10px;
+}
+
+div.rightbox {
+  width: 75%;
+  height:600px;
+  float:left;
+  margin-left:15px;
+  background: #282828;
+
+  border: #555555 1px;
+  -moz-border-radius: 15px;
+  border-radius: 15px;
+  border-style: solid;
+
+  box-shadow: 7px 7px 8px #555555;
+  -webkit-box-shadow: 7px 7px 8px #555555;
+  -moz-box-shadow: 7px 7px 8px #555555;
+  filter: progid:DXImageTransform.Microsoft.dropShadow(color=#555555, offX=7, 
offY=7, positive=true);
+}
+
+div.error {
+  font-color: #FF0000;
+  background: #282828;
+}
\ No newline at end of file

Added: 
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.html
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.html   
    Mon Jul 18 16:35:28 2011
@@ -0,0 +1,95 @@
+<html>
+  <head>
+    <title>Amdatu OAuth Server - Register new Aplication</title>
+    <link rel="stylesheet" href="cr.css">
+  </head>
+<body>
+<table>
+  <tr>
+    <td align="left"><img src="AMDATUhit.jpg" width="30%" align="left"/></td>
+    <td align="right" nowrap="nowrap"><h2>Register new application</h2></td>
+  </tr>
+</table>
+<hr/>
+
+<div class="leftbox">
+  <p>Use this form to register a new Application in the consumer registry of 
the OAuth server.
+  Registered applications will receive a consumer key and secret which can be 
used to communicate
+  using the OAuth protocol.</p>
+  <a href="#" onclick="javascript:editConsumer('blabla');">edit</a>
+</div>
+
+<div class="rightbox">
+  <div id="newapp">
+    <p>
+    <table>
+      <tr>
+        <td>Application name</td>
+        <td><input type="text" style="width: 200px;"></td>
+      </tr>
+      <tr>
+        <td>Callback URL</td>
+        <td><input type="text" style="width: 500px;"></td>
+      </tr>
+      <tr>
+        <td><input type="submit" value="Register"></td>
+        <td></td>
+      </tr>
+    </table>
+    </p>
+  </div>
+
+  <div id="editapp">
+    <table>
+          <tr>
+            <td>Application name</td>
+            <td><input type="text" style="width: 200px;"></td>
+          </tr>
+          <tr>
+            <td>Callback URL</td>
+            <td><input type="text" style="width: 500px;"></td>
+          </tr>
+          <tr>
+            <td><input type="submit" value="update"></td>
+            <td></td>
+          </tr>
+    </table>
+  </div>
+</div>
+
+</body>
+</html>
+
+<script type="text/javascript">
+showNewApp();
+  function editConsumer(url) {
+    showEditApp();
+  }
+
+ function showNewApp() {
+    document.getElementById("newapp").style.visibility = "";
+    document.getElementById("newapp").style.display = "";
+    document.getElementById("editapp").style.visibility = "hidden";
+    document.getElementById("editapp").style.display = "none";
+  }
+
+  function showEditApp() {
+    document.getElementById("newapp").style.visibility = "hidden";
+    document.getElementById("newapp").style.display = "none";
+    document.getElementById("editapp").style.visibility = "";
+    document.getElementById("editapp").style.display = "";
+  }
+
+  function getConsumer(url) {
+      jQuery.ajax({
+        url: url,
+        type: "GET",
+        dataType: "json",
+        async:true,
+        success: function(data, textStatus, jqXHR) {
+          var consumer = jQuery.parseJSON(jqXHR.responseText).consumer;
+          alert(consumer.name);
+        }
+      });
+    }
+</script>
\ No newline at end of file

Modified: 
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.jsp
==============================================================================
--- 
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.jsp    
    (original)
+++ 
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.jsp    
    Mon Jul 18 16:35:28 2011
@@ -7,13 +7,13 @@
 <c:set var="baseUrl" 
value="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${contextPath}"/>
 <c:set var="statusUrl" value="${baseUrl}/rest/authorization/status"/>
 <c:set var="loginUrl" value="${baseUrl}/rest/authorization/login"/>
-<c:set var="registerAppUrl" value="${baseUrl}/rest/oauth/consumers/"/>
+<c:set var="appUrl" value="${baseUrl}/rest/oauth/consumers/"/>
 
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd";>
 <html>
   <head>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-      <title>Amdatu OAuth Server - Register Application</title>
+      <title>Amdatu OAuth Server - Manage Applications</title>
       <link rel="stylesheet" href="${staticPath}/css/cr.css">
       <script type="text/javascript" 
src="${contextPath}/dashboard/static/js/lib/jquery-1.4.2.min.js"></script>
   </head>
@@ -22,14 +22,15 @@
     <table>
       <tr>
         <td align="left"><img src="${staticPath}/img/amdatu.jpg" width="30%" 
align="left"/></td>
-        <td align="right" nowrap="nowrap"><h2>Register new 
application</h2></td>
+        <td align="right" nowrap="nowrap"><h2>Manage your 
applications</h2></td>
       </tr>
     </table>
     <hr/>
 
     <div class="leftbox">
+      <h3>Register a new application</h3>
       <p>
-        Use this form to register a new Application in the consumer registry 
of the OAuth server.
+        Click <a href="#" onclick="javascript:showDiv('newApp');">here</a> to 
register a new Application in the consumer registry of the OAuth server.
         Registered applications will receive a consumer key and secret which 
can be used to
         communicate using the OAuth protocol.
       </p>
@@ -45,15 +46,14 @@
 
     <div class="rightbox">
       <p>
-
-        <div id="login" style="display:none;visibility:hidden">
+        <div id="login" name="hidablediv" 
style="display:none;visibility:hidden">
           To register a new Application you must log in with an existing 
Amdatu account.
           <table width="95%">
             <tr>
-              <td>Username</td><td><input type="edit" id="username" value="" 
onKeyPress="return submitenter(this, event)"/></td>
+              <td>Username</td><td><input type="edit" id="editusername" 
value="" onKeyPress="return submitenter(this, event)"/></td>
             </tr>
             <tr>
-              <td>Password</td><td><input type="password" id="password" 
value="" onKeyPress="return submitenter(this, event)"/></td>
+              <td>Password</td><td><input type="password" id="editpassword" 
value="" onKeyPress="return submitenter(this, event)"/></td>
             </tr>
             <tr>
               <td><input type="submit" value="Login" 
onclick="javascript:login()" /></td><td/>
@@ -62,7 +62,14 @@
           </table>
         </div>
 
-        <div id="register" style="display:none;visibility:hidden">
+        <div id="account" name="hidablediv" 
style="display:none;visibility:hidden">
+          <p>
+            You are currently logged in as '<label id="username"></label>'. 
Click on one of the links on the
+            left to register a new application or to edit an existing 
application.
+          </p>
+        </div>
+
+        <div id="newApp" name="hidablediv" 
style="display:none;visibility:hidden">
           <table>
             <tr>
               <td>Application name</td>
@@ -73,17 +80,43 @@
               <td><input id="callbackurl" type="text" style="width: 
500px;"></td>
             </tr>
             <tr>
-              <td><input type="button" value="Register" 
onclick="javascript:registerApplication();"></td>
+              <td><input type="button" value="Register" 
onclick="javascript:newApplication();"></td>
               <td></td>
             </tr>
           </table>
         </div>
 
-        <div id="registeredApp" style="display:none;visibility:hidden">
-        </div>
+        <div id="editApp" name="hidablediv" 
style="display:none;visibility:hidden">
+          <table>
+            <tr>
+              <td>Application name</td>
+              <td><input id="editname" type="text" disabled="disabled" 
style="width: 200px;"></td>
+            </tr>
+            <tr>
+              <td>Consumer key</td>
+              <td><input id="editconsumerkey" type="text" disabled="disabled" 
style="width: 500px;"></td>
+            </tr>
+            <tr>
+              <td>Consumer secret</td>
+              <td><input id="editconsumersecret" type="text" 
disabled="disabled" style="width: 500px;"></td>
+            </tr>
+            <tr>
+              <td>Callback URL</td>
+              <td><input id="editcallbackurl" type="text" style="width: 
500px;"></td>
+            </tr>
+          </table>
 
-        <div id="error" class="error" style="display:none;visibility:hidden">
+          <table>
+            <tr>
+              <td><input type="button" value="Update application" 
onclick="javascript:updateApplication();"></td>
+              <td><input type="button" value="Delete application" 
onclick="javascript:deleteApplication();"></td>
+            </tr>
+          </table>
         </div>
+
+        <div id="info" class="info" 
style="display:none;visibility:hidden"></div>
+
+        <div id="error" class="error" 
style="display:none;visibility:hidden"></div>
       </p>
   </div>
 
@@ -92,7 +125,7 @@
 
 <script type="text/javascript">
   detectLoginStatus();
-  getConsumers();
+  loadApplications();
 
   function detectLoginStatus() {
     var url = "${statusUrl}";
@@ -103,9 +136,11 @@
       async:true,
       success: function(response) {
           if (response.username != null) {
-            showRegister(response.username);
+            showDiv("account");
+            document.getElementById("username").innerHTML = response.username;
+            loadApplications();
           } else {
-            showLogin();
+            showDiv("login");
           }
         }
       }
@@ -114,8 +149,8 @@
 
   function login() {
     var postdata = {
-      username : document.getElementById('username').value,
-      password : document.getElementById('password').value
+      username : document.getElementById('editusername').value,
+      password : document.getElementById('editpassword').value
     };
 
     var url = "${loginUrl}";
@@ -141,53 +176,116 @@
     );
   }
 
-  function getConsumers() {
-      var url = "${registerAppUrl}";
-      jQuery.ajax({
-        url: url,
-        type: "GET",
-        dataType: "json",
-        async:true,
-        success: function(data, textStatus, jqXHR) {
-          var consumers = 
jQuery.parseJSON(jqXHR.responseText).consumers.consumers;
+  function loadApplications() {
+    var url = "${appUrl}";
+    jQuery.ajax({
+      url: url,
+      type: "GET",
+      dataType: "json",
+      async:true,
+      success: function(data, textStatus, jqXHR) {
+        var consumers = jQuery.parseJSON(jqXHR.responseText).result.consumers;
+        if (typeof consumers != 'undefined') {
           var html = "<ul>";
-          for (i=0; i<consumers.length; i++) {
-            html += "<li><a href=\"" + consumers[i].editLink.href + "\">" + 
consumers[i].name + "</a></li>";
+          if (typeof consumers.length == 'undefined') {
+            html += "<li><a href=\"#\" onclick=\"javascript:editApplication('" 
+ consumers.editLink.href + "');\">" + consumers.name + "</a></li>";
+          }
+          else {
+            for (i=0; i<consumers.length; i++) {
+              html += "<li><a href=\"#\" 
onclick=\"javascript:editApplication('" + consumers[i].editLink.href + "');\">" 
+ consumers[i].name + "</a></li>";
+            }
           };
           html += "</ul>";
           var myAppsDiv = document.getElementById("myapps");
           myAppsDiv.innerHTML = html;
         }
-      });
+        else {
+          var myAppsDiv = document.getElementById("myapps");
+          myAppsDiv.innerHTML = "<p><i>You do not have any registered 
applications</i></p>";
+        }
+      }
+    });
+  }
+
+  function editApplication(url) {
+    showDiv("editApp");
+    jQuery.ajax({
+        url: url,
+        type: "GET",
+        dataType: "json",
+        async:true,
+        success: function(data, textStatus, jqXHR) {
+          var consumer = jQuery.parseJSON(jqXHR.responseText).consumer;
+          document.getElementById("editname").value = consumer.name;
+          document.getElementById("editconsumerkey").value = 
consumer.consumerKey;
+          document.getElementById("editconsumersecret").value = 
consumer.consumerSecret;
+          document.getElementById("editcallbackurl").value = 
consumer.callbackUrl;
+        }
+    });
+  }
+
+  function updateApplication(app) {
+    var postdata = {
+      callbackurl : document.getElementById('editcallbackurl').value,
+    };
+
+    var url = "${appUrl}" + document.getElementById('editconsumerkey').value;
+    jQuery.ajax({
+      url: url,
+      type: "PUT",
+      data: postdata,
+      dataType: "json",
+      async:true,
+      success: function(data, textStatus, jqXHR) {
+        showInfo("Application updated successfully");
+        loadApplications();
+      },
+      error: function(jqXHR, textStatus, errorThrown) {
+        var obj = jQuery.parseJSON(jqXHR.responseText);
+        showError(obj.result.message);
+      }
+    });
+  }
+
+  function deleteApplication(app) {
+    var url = "${appUrl}" + document.getElementById('editconsumerkey').value;
+    jQuery.ajax({
+      url: url,
+      type: "DELETE",
+      dataType: "json",
+      async:true,
+      success: function(data, textStatus, jqXHR) {
+        showInfo("Application deleted successfully");
+        hide("editApp");
+        loadApplications();
+      },
+      error: function(jqXHR, textStatus, errorThrown) {
+        var obj = jQuery.parseJSON(jqXHR.responseText);
+        showError(obj.result.message);
+      }
+    });
+  }
+
+  function showDiv(id) {
+    hide("info");
+    hide("error");
+    var divs = document.getElementsByName("hidablediv");
+    for (i=0; i<divs.length; i++) {
+      divs[i].style.visibility = "hidden";
+      divs[i].style.display = "none";
     }
+    document.getElementById(id).style.visibility = "";
+    document.getElementById(id).style.display = "";
+  }
 
+  function show(id) {
+    document.getElementById(id).style.visibility = "";
+    document.getElementById(id).style.display = "";
+  }
 
-  function showLogin() {
-    document.getElementById("login").style.visibility = "";
-    document.getElementById("login").style.display = "";
-    document.getElementById("register").style.visibility = "hidden";
-    document.getElementById("register").style.display = "none";
-  }
-
-  function showRegister(username) {
-    document.getElementById("login").style.visibility = "hidden";
-    document.getElementById("login").style.display = "none";
-    document.getElementById("register").style.visibility = "";
-    document.getElementById("register").style.display = "";
-  }
-
-  function showError() {
-    document.getElementById("registeredApp").style.visibility = "hidden";
-    document.getElementById("registeredApp").style.display = "none";
-    document.getElementById("error").style.visibility = "";
-    document.getElementById("error").style.display = "";
-  }
-
-    function showRegisteredApp() {
-      document.getElementById("error").style.visibility = "hidden";
-      document.getElementById("error").style.display = "none";
-      document.getElementById("registeredApp").style.visibility = "";
-      document.getElementById("registeredApp").style.display = "";
+  function hide(id) {
+    document.getElementById(id).style.visibility = "hidden";
+    document.getElementById(id).style.display = "none";
   }
 
   function submitenter(field, e) {
@@ -208,14 +306,13 @@
     }
   }
 
-  function registerApplication() {
-
+  function newApplication() {
     var postdata = {
       name : document.getElementById('name').value,
       callbackurl : document.getElementById('callbackurl').value,
     };
 
-    var url = "${registerAppUrl}";
+    var url = "${appUrl}";
     jQuery.ajax({
       url: url,
       type: "POST",
@@ -224,7 +321,7 @@
       async:true,
       success: function(data, textStatus, jqXHR) {
         var consumer = jQuery.parseJSON(jqXHR.responseText).consumer;
-        var resultDiv = document.getElementById("registeredApp");
+        var resultDiv = document.getElementById("info");
         var html = "The following Application has been registered:";
         html += "<table>";
         html += "<tr><td>Application name:</td><td>" + consumer.name + 
"</td></tr>";
@@ -232,17 +329,30 @@
         html += "<tr><td>Consumer secret:</td><td>" + consumer.consumerSecret 
+ "</td></tr>";
         html += "<tr><td>Callback URL:</td><td>" + consumer.callbackUrl + 
"</td></tr>";
         html += "</tr></table>";
-        showRegisteredApp();
+        hide("error");
+        show("info");
         resultDiv.innerHTML = html;
+        loadApplications();
       },
       error: function(jqXHR, textStatus, errorThrown) {
         var obj = jQuery.parseJSON(jqXHR.responseText);
-        var errorMessage = obj.result.message;
-        var errorDiv = document.getElementById("error");
-        showError();
-        errorDiv.innerHTML = errorMessage;
+        showError(obj.result.message);
       }
     });
   }
 
+  function showInfo(msg) {
+    hide("error");
+    var infoDiv = document.getElementById("info");
+    infoDiv.innerHTML = msg;
+    show("info");
+  }
+
+  function showError(msg) {
+    hide("info");
+    var errorDiv = document.getElementById("error");
+    errorDiv.innerHTML = msg;
+    show("error");
+  }
+
 </script>

Modified: 
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/static/css/cr.css
==============================================================================
--- 
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/static/css/cr.css   
    (original)
+++ 
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/static/css/cr.css   
    Mon Jul 18 16:35:28 2011
@@ -15,6 +15,10 @@
   color: #FFFFFF;
 }
 
+label {
+  color: #CCCCCC;
+}
+
 div.leftbox {
   width:22%;
   height:600px;
@@ -33,6 +37,10 @@
   filter: progid:DXImageTransform.Microsoft.dropShadow(color=#555555, offX=7, 
offY=7, positive=true);
 }
 
+p {
+margin-left:5px;
+}
+
 h3 {
   margin-left:5px;
 }
@@ -64,7 +72,13 @@
 }
 
 div.error {
-  margin-left:10px;
+  margin-left:15px;
   color: #EB3125;
   background: #282828;
+}
+
+div.info {
+  margin-left:15px;
+  color: #DDDDDD;
+  background: #282828;
 }
\ No newline at end of file

Modified: 
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthServiceConsumerRegistryTest.java
==============================================================================
--- 
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthServiceConsumerRegistryTest.java
 (original)
+++ 
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthServiceConsumerRegistryTest.java
 Mon Jul 18 16:35:28 2011
@@ -130,7 +130,7 @@
             body = consumer.toXML();
         } else if ("application/json".equals(mimeType)) {
             body = consumer.toJson().toString();
-        }
+        } 
         m_logService.log(LogService.LOG_DEBUG, "Adding consumer for " + 
mimeType + ", url=" + (update ? url + "/"
             + consumer.getConsumerKey() : url) + ", input=" + body);
         RequestEntity requestEntity = new StringRequestEntity(body, mimeType, 
"UTF-8");
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to