Blame SOURCES/pki-core-updated-account-info.patch

dd68f4
From ebe79a4db05662091bd15efc860ef6923beff2aa Mon Sep 17 00:00:00 2001
dd68f4
From: "Endi S. Dewata" <edewata@redhat.com>
dd68f4
Date: Thu, 20 Oct 2016 00:54:47 +0200
dd68f4
Subject: [PATCH] Updated AccountInfo.
dd68f4
dd68f4
The AccountInfo has been changed to extend the ResourceMessage
dd68f4
such that it can be used to pass the list of accessible
dd68f4
components as an attribute.
dd68f4
dd68f4
https://fedorahosted.org/pki/ticket/2523
dd68f4
(cherry picked from commit 6d5d15edebeb1ba113e4f3d5b2bb1ba93a92ce1d)
dd68f4
(cherry picked from commit 388e443b99999dd2aa0832aaed0cdf43ee260b81)
dd68f4
---
dd68f4
 .../com/netscape/certsrv/account/AccountInfo.java  |  8 ++--
dd68f4
 .../com/netscape/certsrv/base/ResourceMessage.java | 11 +++++-
dd68f4
 .../org/dogtagpki/server/rest/AccountService.java  | 46 ++++++++--------------
dd68f4
 3 files changed, 31 insertions(+), 34 deletions(-)
dd68f4
dd68f4
diff --git a/base/common/src/com/netscape/certsrv/account/AccountInfo.java b/base/common/src/com/netscape/certsrv/account/AccountInfo.java
dd68f4
index 7943d22..3310bf0 100644
dd68f4
--- a/base/common/src/com/netscape/certsrv/account/AccountInfo.java
dd68f4
+++ b/base/common/src/com/netscape/certsrv/account/AccountInfo.java
dd68f4
@@ -33,11 +33,13 @@ import javax.xml.bind.annotation.XmlRootElement;
dd68f4
 import javax.xml.bind.annotation.adapters.XmlAdapter;
dd68f4
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
dd68f4
 
dd68f4
+import com.netscape.certsrv.base.ResourceMessage;
dd68f4
+
dd68f4
 /**
dd68f4
  * @author Endi S. Dewata
dd68f4
  */
dd68f4
 @XmlRootElement(name="Account")
dd68f4
-public class AccountInfo {
dd68f4
+public class AccountInfo extends ResourceMessage {
dd68f4
 
dd68f4
     public static Marshaller marshaller;
dd68f4
     public static Unmarshaller unmarshaller;
dd68f4
@@ -98,7 +100,7 @@ public class AccountInfo {
dd68f4
     @Override
dd68f4
     public int hashCode() {
dd68f4
         final int prime = 31;
dd68f4
-        int result = 1;
dd68f4
+        int result = super.hashCode();
dd68f4
         result = prime * result + ((email == null) ? 0 : email.hashCode());
dd68f4
         result = prime * result + ((fullName == null) ? 0 : fullName.hashCode());
dd68f4
         result = prime * result + ((id == null) ? 0 : id.hashCode());
dd68f4
@@ -110,7 +112,7 @@ public class AccountInfo {
dd68f4
     public boolean equals(Object obj) {
dd68f4
         if (this == obj)
dd68f4
             return true;
dd68f4
-        if (obj == null)
dd68f4
+        if (!super.equals(obj))
dd68f4
             return false;
dd68f4
         if (getClass() != obj.getClass())
dd68f4
             return false;
dd68f4
diff --git a/base/common/src/com/netscape/certsrv/base/ResourceMessage.java b/base/common/src/com/netscape/certsrv/base/ResourceMessage.java
dd68f4
index 1214b45..85d0d07 100644
dd68f4
--- a/base/common/src/com/netscape/certsrv/base/ResourceMessage.java
dd68f4
+++ b/base/common/src/com/netscape/certsrv/base/ResourceMessage.java
dd68f4
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlValue;
dd68f4
 import javax.xml.bind.annotation.adapters.XmlAdapter;
dd68f4
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
dd68f4
 
dd68f4
+import com.netscape.certsrv.account.AccountInfo;
dd68f4
 import com.netscape.certsrv.key.AsymKeyGenerationRequest;
dd68f4
 import com.netscape.certsrv.key.KeyArchivalRequest;
dd68f4
 import com.netscape.certsrv.key.KeyRecoveryRequest;
dd68f4
@@ -35,8 +36,14 @@ import com.netscape.certsrv.key.SymKeyGenerationRequest;
dd68f4
  * @author Ade Lee
dd68f4
  */
dd68f4
 @XmlRootElement(name = "ResourceMessage")
dd68f4
-@XmlSeeAlso({ KeyArchivalRequest.class, KeyRecoveryRequest.class, SymKeyGenerationRequest.class,
dd68f4
-        PKIException.Data.class, AsymKeyGenerationRequest.class })
dd68f4
+@XmlSeeAlso({
dd68f4
+    AccountInfo.class,
dd68f4
+    KeyArchivalRequest.class,
dd68f4
+    KeyRecoveryRequest.class,
dd68f4
+    SymKeyGenerationRequest.class,
dd68f4
+    PKIException.Data.class,
dd68f4
+    AsymKeyGenerationRequest.class
dd68f4
+})
dd68f4
 @XmlAccessorType(XmlAccessType.NONE)
dd68f4
 public class ResourceMessage {
dd68f4
 
dd68f4
diff --git a/base/server/cms/src/org/dogtagpki/server/rest/AccountService.java b/base/server/cms/src/org/dogtagpki/server/rest/AccountService.java
dd68f4
index 827e99e..673db45 100644
dd68f4
--- a/base/server/cms/src/org/dogtagpki/server/rest/AccountService.java
dd68f4
+++ b/base/server/cms/src/org/dogtagpki/server/rest/AccountService.java
dd68f4
@@ -21,13 +21,8 @@ package org.dogtagpki.server.rest;
dd68f4
 import java.security.Principal;
dd68f4
 import java.util.Arrays;
dd68f4
 
dd68f4
-import javax.servlet.http.HttpServletRequest;
dd68f4
 import javax.servlet.http.HttpSession;
dd68f4
-import javax.ws.rs.core.Context;
dd68f4
-import javax.ws.rs.core.HttpHeaders;
dd68f4
-import javax.ws.rs.core.Request;
dd68f4
 import javax.ws.rs.core.Response;
dd68f4
-import javax.ws.rs.core.UriInfo;
dd68f4
 
dd68f4
 import org.apache.catalina.realm.GenericPrincipal;
dd68f4
 import org.apache.commons.lang.StringUtils;
dd68f4
@@ -43,47 +38,40 @@ import com.netscape.cms.servlet.base.PKIService;
dd68f4
  */
dd68f4
 public class AccountService extends PKIService implements AccountResource {
dd68f4
 
dd68f4
-    @Context
dd68f4
-    private UriInfo uriInfo;
dd68f4
-
dd68f4
-    @Context
dd68f4
-    private HttpHeaders headers;
dd68f4
-
dd68f4
-    @Context
dd68f4
-    private Request request;
dd68f4
-
dd68f4
-    @Context
dd68f4
-    private HttpServletRequest servletRequest;
dd68f4
-
dd68f4
-    @Override
dd68f4
-    public Response login() {
dd68f4
-        HttpSession session = servletRequest.getSession();
dd68f4
-        System.out.println("Creating session "+session.getId());
dd68f4
-
dd68f4
+    protected AccountInfo createAccountInfo() {
dd68f4
         Principal principal = servletRequest.getUserPrincipal();
dd68f4
-        System.out.println("Principal: "+principal);
dd68f4
+        System.out.println("Principal: " + principal);
dd68f4
 
dd68f4
-        AccountInfo response = new AccountInfo();
dd68f4
+        AccountInfo accountInfo = new AccountInfo();
dd68f4
         String name = principal.getName();
dd68f4
-        response.setID(name);
dd68f4
+        accountInfo.setID(name);
dd68f4
 
dd68f4
         if (principal instanceof PKIPrincipal) {
dd68f4
             PKIPrincipal pkiPrincipal = (PKIPrincipal)principal;
dd68f4
             IUser user = pkiPrincipal.getUser();
dd68f4
 
dd68f4
             String fullName = user.getFullName();
dd68f4
-            if (!StringUtils.isEmpty(fullName)) response.setFullName(fullName);
dd68f4
+            if (!StringUtils.isEmpty(fullName)) accountInfo.setFullName(fullName);
dd68f4
 
dd68f4
             String email = user.getEmail();
dd68f4
-            if (!StringUtils.isEmpty(email)) response.setEmail(email);
dd68f4
+            if (!StringUtils.isEmpty(email)) accountInfo.setEmail(email);
dd68f4
         }
dd68f4
 
dd68f4
         if (principal instanceof GenericPrincipal) {
dd68f4
             String[] roles = ((GenericPrincipal) principal).getRoles();
dd68f4
-            response.setRoles(Arrays.asList(roles));
dd68f4
+            accountInfo.setRoles(Arrays.asList(roles));
dd68f4
         }
dd68f4
 
dd68f4
-        return createOKResponse(response);
dd68f4
+        return accountInfo;
dd68f4
+    }
dd68f4
+
dd68f4
+    @Override
dd68f4
+    public Response login() {
dd68f4
+        HttpSession session = servletRequest.getSession();
dd68f4
+        System.out.println("Creating session " + session.getId());
dd68f4
+
dd68f4
+        AccountInfo accountInfo = createAccountInfo();
dd68f4
+        return createOKResponse(accountInfo);
dd68f4
     }
dd68f4
 
dd68f4
     @Override
dd68f4
-- 
dd68f4
1.8.3.1
dd68f4