From 3c3846be35db892ac36bfc617060284482b7c892 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 14 Feb 2014 12:56:14 -0500
Subject: [PATCH] Updated REST interface for account.

The REST interface for account has been modified to return Response
objects to allow better handling of server responses.

Ticket #554
---
 .../src/com/netscape/certsrv/account/AccountClient.java    | 14 +++++++++-----
 .../src/com/netscape/certsrv/account/AccountResource.java  |  9 +++++++--
 .../com/netscape/cms/servlet/account/AccountService.java   | 11 ++++++++---
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/account/AccountClient.java b/base/common/src/com/netscape/certsrv/account/AccountClient.java
index dcf8975b513076f216b786214ce136d0036b1af9..cec8bd8470a40be3a3d2580681a83c7551c394c8 100644
--- a/base/common/src/com/netscape/certsrv/account/AccountClient.java
+++ b/base/common/src/com/netscape/certsrv/account/AccountClient.java
@@ -19,6 +19,8 @@ package com.netscape.certsrv.account;
 
 import java.net.URISyntaxException;
 
+import javax.ws.rs.core.Response;
+
 import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.PKIClient;
 
@@ -40,14 +42,16 @@ public class AccountClient extends Client {
     }
 
     public void login() {
-        resource.login();
+        Response response = resource.login();
+        client.getEntity(response, Void.class);
         loggedIn = true;
     }
 
     public void logout() {
-        if (loggedIn) {
-            resource.logout();
-            loggedIn = false;
-        }
+        if (!loggedIn) return;
+
+        Response response = resource.logout();
+        client.getEntity(response, Void.class);
+        loggedIn = false;
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/account/AccountResource.java b/base/common/src/com/netscape/certsrv/account/AccountResource.java
index c18e26de825dd4fba39d1532b2616160eee29674..be6437515a80f07a973aa9b853e0f389ca9ae203 100644
--- a/base/common/src/com/netscape/certsrv/account/AccountResource.java
+++ b/base/common/src/com/netscape/certsrv/account/AccountResource.java
@@ -20,6 +20,9 @@ package com.netscape.certsrv.account;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.annotations.ClientResponseType;
 
 import com.netscape.certsrv.acls.ACLMapping;
 import com.netscape.certsrv.authentication.AuthMethodMapping;
@@ -33,11 +36,13 @@ public interface AccountResource {
 
     @GET
     @Path("login")
+    @ClientResponseType(entityType=Void.class)
     @ACLMapping("account.login")
-    public void login();
+    public Response login();
 
     @GET
     @Path("logout")
+    @ClientResponseType(entityType=Void.class)
     @ACLMapping("account.logout")
-    public void logout();
+    public Response logout();
 }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/account/AccountService.java b/base/server/cms/src/com/netscape/cms/servlet/account/AccountService.java
index 611c865aedae275ac7c492d60451ba9f0a52050a..1a07a3a2383dc59a381d3564a4f447fce594aa5e 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/account/AccountService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/account/AccountService.java
@@ -25,6 +25,7 @@ import javax.servlet.http.HttpSession;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
 import com.netscape.certsrv.account.AccountResource;
@@ -48,20 +49,24 @@ public class AccountService extends PKIService implements AccountResource {
     private HttpServletRequest servletRequest;
 
     @Override
-    public void login() {
+    public Response login() {
         HttpSession session = servletRequest.getSession();
         System.out.println("Creating session "+session.getId());
 
         Principal principal = servletRequest.getUserPrincipal();
         System.out.println("Principal: "+principal);
+
+        return createNoContentResponse();
     }
 
     @Override
-    public void logout() {
+    public Response logout() {
         HttpSession session = servletRequest.getSession(false);
-        if (session == null) return;
+        if (session == null) return createNoContentResponse();
 
         System.out.println("Destroying session "+session.getId());
         session.invalidate();
+
+        return createNoContentResponse();
     }
 }
-- 
1.8.4.2

