Author: ilgrosso
Date: Tue May 28 07:36:19 2013
New Revision: 1486793

URL: http://svn.apache.org/r1486793
Log:
[SYNCOPE-373] Return fake UserTO for admin when self-reading

Modified:
    
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java
    
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java
    
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeUserDetailsService.java
    syncope/branches/1_1_X/core/src/main/resources/restContext.xml
    syncope/branches/1_1_X/core/src/main/resources/securityContext.xml
    syncope/branches/1_1_X/core/src/main/resources/syncopeContext.xml
    syncope/branches/1_1_X/core/src/main/resources/workflowContext.xml
    
syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
    
syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java

Modified: 
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java
URL: 
http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java?rev=1486793&r1=1486792&r2=1486793&view=diff
==============================================================================
--- 
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java
 (original)
+++ 
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java
 Tue May 28 07:36:19 2013
@@ -21,6 +21,7 @@ package org.apache.syncope.core.rest.dat
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
+import javax.annotation.Resource;
 import org.apache.commons.lang.StringUtils;
 import org.apache.syncope.common.mod.MembershipMod;
 import org.apache.syncope.common.mod.UserMod;
@@ -71,6 +72,9 @@ public class UserDataBinder extends Abst
     @Autowired
     private ConnObjectUtil connObjectUtil;
 
+    @Resource(name = "adminUser")
+    private String adminUser;
+
     @Transactional(readOnly = true)
     public SyncopeUser getUserFromId(final Long userId) {
         if (userId == null) {
@@ -96,8 +100,19 @@ public class UserDataBinder extends Abst
 
     @Transactional(readOnly = true)
     public UserTO getAuthenticatedUserTO() {
-        SyncopeUser authUser = 
userDAO.find(SecurityContextHolder.getContext().getAuthentication().getName());
-        return getUserTO(authUser);
+        final UserTO authUserTO;
+
+        final String authUsername = 
SecurityContextHolder.getContext().getAuthentication().getName();
+        if (adminUser.equals(authUsername)) {
+            authUserTO = new UserTO();
+            authUserTO.setId(-1);
+            authUserTO.setUsername(adminUser);
+        } else {
+            SyncopeUser authUser = userDAO.find(authUsername);
+            authUserTO = getUserTO(authUser);
+        }
+
+        return authUserTO;
     }
 
     @Transactional(readOnly = true)

Modified: 
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java
URL: 
http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java?rev=1486793&r1=1486792&r2=1486793&view=diff
==============================================================================
--- 
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java
 (original)
+++ 
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java
 Tue May 28 07:36:19 2013
@@ -19,6 +19,7 @@
 package org.apache.syncope.core.security;
 
 import java.util.Date;
+import javax.annotation.Resource;
 import org.apache.syncope.common.types.AuditElements.AuthenticationSubCategory;
 import org.apache.syncope.common.types.AuditElements.Category;
 import org.apache.syncope.common.types.AuditElements.Result;
@@ -53,36 +54,14 @@ public class SyncopeAuthenticationProvid
     @Autowired
     private UserDAO userDAO;
 
-    private SyncopeUserDetailsService userDetailsService;
-
+    @Resource(name = "adminUser")
     private String adminUser;
 
     private String adminPassword;
 
     private String adminPasswordAlgorithm;
 
-    public SyncopeUserDetailsService getSyncopeUserDetailsService() {
-        return userDetailsService;
-    }
-
-    public void setSyncopeUserDetailsService(final SyncopeUserDetailsService 
syncopeUserDetailsService) {
-        this.userDetailsService = syncopeUserDetailsService;
-    }
-
-    public String getAdminUser() {
-        return adminUser;
-    }
-
-    public void setAdminUser(final String adminUser) {
-        this.adminUser = adminUser;
-    }
-
-    /**
-     * @return the adminPassword
-     */
-    public String getAdminPassword() {
-        return adminPassword;
-    }
+    private SyncopeUserDetailsService userDetailsService;
 
     /**
      * @param adminPassword the adminPassword to set
@@ -92,19 +71,16 @@ public class SyncopeAuthenticationProvid
     }
 
     /**
-     * @return the adminPasswordAlgorithm
-     */
-    public String getAdminPasswordAlgorithm() {
-        return adminPasswordAlgorithm;
-    }
-
-    /**
      * @param adminPasswordAlgorithm the adminPasswordAlgorithm to set
      */
     public void setAdminPasswordAlgorithm(final String adminPasswordAlgorithm) 
{
         this.adminPasswordAlgorithm = adminPasswordAlgorithm;
     }
 
+    public void setSyncopeUserDetailsService(final SyncopeUserDetailsService 
syncopeUserDetailsService) {
+        this.userDetailsService = syncopeUserDetailsService;
+    }
+
     @Override
     @Transactional(noRollbackFor = {BadCredentialsException.class, 
DisabledException.class})
     public Authentication authenticate(final Authentication authentication)

Modified: 
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeUserDetailsService.java
URL: 
http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeUserDetailsService.java?rev=1486793&r1=1486792&r2=1486793&view=diff
==============================================================================
--- 
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeUserDetailsService.java
 (original)
+++ 
syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/security/SyncopeUserDetailsService.java
 Tue May 28 07:36:19 2013
@@ -21,6 +21,7 @@ package org.apache.syncope.core.security
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import javax.annotation.Resource;
 import org.apache.syncope.core.persistence.beans.Entitlement;
 import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
 import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
@@ -49,16 +50,9 @@ public class SyncopeUserDetailsService i
     @Autowired
     private EntitlementDAO entitlementDAO;
 
+    @Resource(name = "adminUser")
     private String adminUser;
 
-    public String getAdminUser() {
-        return adminUser;
-    }
-
-    public void setAdminUser(String adminUser) {
-        this.adminUser = adminUser;
-    }
-
     @Override
     public UserDetails loadUserByUsername(final String username) throws 
UsernameNotFoundException, DataAccessException {
         final Set<SimpleGrantedAuthority> authorities = new 
HashSet<SimpleGrantedAuthority>();

Modified: syncope/branches/1_1_X/core/src/main/resources/restContext.xml
URL: 
http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/resources/restContext.xml?rev=1486793&r1=1486792&r2=1486793&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/main/resources/restContext.xml (original)
+++ syncope/branches/1_1_X/core/src/main/resources/restContext.xml Tue May 28 
07:36:19 2013
@@ -36,10 +36,6 @@ under the License.
 
   <context:component-scan 
base-package="org.apache.syncope.core.rest.controller"/>
 
-  <bean id="adminUser" class="java.lang.String">
-    <constructor-arg value="${adminUser}"/>
-  </bean>
-  
   <!-- CXF Configuration - BEGIN -->
   <context:component-scan base-package="org.apache.syncope.core.services"/>
 

Modified: syncope/branches/1_1_X/core/src/main/resources/securityContext.xml
URL: 
http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/resources/securityContext.xml?rev=1486793&r1=1486792&r2=1486793&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/main/resources/securityContext.xml 
(original)
+++ syncope/branches/1_1_X/core/src/main/resources/securityContext.xml Tue May 
28 07:36:19 2013
@@ -46,13 +46,10 @@ under the License.
   </security:http>
 
   <bean id="syncopeUserDetailsService"
-        class="org.apache.syncope.core.security.SyncopeUserDetailsService">
-    <property name="adminUser" value="${adminUser}"/>
-  </bean>
+        class="org.apache.syncope.core.security.SyncopeUserDetailsService"/>
 
   <bean id="syncopeAuthenticationProvider"
         class="org.apache.syncope.core.security.SyncopeAuthenticationProvider">
-    <property name="adminUser" value="${adminUser}"/>
     <property name="adminPassword" value="${adminPassword}"/>
     <property name="adminPasswordAlgorithm" value="${adminPasswordAlgorithm}"/>
     <property name="syncopeUserDetailsService" 
ref="syncopeUserDetailsService"/>

Modified: syncope/branches/1_1_X/core/src/main/resources/syncopeContext.xml
URL: 
http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/resources/syncopeContext.xml?rev=1486793&r1=1486792&r2=1486793&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/main/resources/syncopeContext.xml (original)
+++ syncope/branches/1_1_X/core/src/main/resources/syncopeContext.xml Tue May 
28 07:36:19 2013
@@ -40,6 +40,10 @@ under the License.
     <property name="ignoreUnresolvablePlaceholders" value="true"/>
   </bean>
 
+  <bean id="adminUser" class="java.lang.String">
+    <constructor-arg value="${adminUser}"/>
+  </bean>
+
   <bean class="org.apache.syncope.core.util.ApplicationContextProvider"/>
 
   <context:component-scan base-package="org.apache.syncope.core.init"/>

Modified: syncope/branches/1_1_X/core/src/main/resources/workflowContext.xml
URL: 
http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/resources/workflowContext.xml?rev=1486793&r1=1486792&r2=1486793&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/main/resources/workflowContext.xml 
(original)
+++ syncope/branches/1_1_X/core/src/main/resources/workflowContext.xml Tue May 
28 07:36:19 2013
@@ -22,10 +22,6 @@ under the License.
        xsi:schemaLocation="http://www.springframework.org/schema/beans   
                            
http://www.springframework.org/schema/beans/spring-beans.xsd";>
 
-  <bean id="adminUser" class="java.lang.String">
-    <constructor-arg value="${adminUser}"/>
-  </bean>
-
   <bean id="uwfAdapter" class="${uwfAdapter}"/>
   <bean id="rwfAdapter" class="${rwfAdapter}"/>
 

Modified: 
syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
URL: 
http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java?rev=1486793&r1=1486792&r2=1486793&view=diff
==============================================================================
--- 
syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
 (original)
+++ 
syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
 Tue May 28 07:36:19 2013
@@ -107,7 +107,7 @@ public abstract class AbstractTest {
 
     protected static final String BASE_URL = 
"http://localhost:9080/syncope/rest/";;
 
-    protected static final String ADMIN_UID = "admin";
+    protected static final String ADMIN_UNAME = "admin";
 
     protected static final String ADMIN_PWD = "password";
 
@@ -199,7 +199,7 @@ public abstract class AbstractTest {
     }
 
     protected void resetRestTemplate() {
-        setupRestTemplate(ADMIN_UID, ADMIN_PWD);
+        setupRestTemplate(ADMIN_UNAME, ADMIN_PWD);
         userService = new UserServiceProxy(BASE_URL, restTemplate);
         userWorkflowService = new UserWorkflowServiceProxy(BASE_URL, 
restTemplate);
         roleService = new RoleServiceProxy(BASE_URL, restTemplate);
@@ -238,7 +238,7 @@ public abstract class AbstractTest {
     }
 
     protected <T> T createServiceInstance(final Class<T> serviceClass) {
-        return createServiceInstance(serviceClass, ADMIN_UID);
+        return createServiceInstance(serviceClass, ADMIN_UNAME);
     }
 
     protected <T> T createServiceInstance(final Class<T> serviceClass, final 
String username) {

Modified: 
syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
URL: 
http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1486793&r1=1486792&r2=1486793&view=diff
==============================================================================
--- 
syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
 (original)
+++ 
syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
 Tue May 28 07:36:19 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.core.rest;
 
+import static org.apache.syncope.core.rest.AbstractTest.ADMIN_PWD;
 import static org.apache.syncope.core.rest.AbstractTest.getUUIDString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -2218,6 +2219,12 @@ public class UserTestITCase extends Abst
             
assertNotNull(scce.getException(SyncopeClientExceptionType.NotFound));
         }
     }
+    
+        @Test
+    public void issueSYNCOPE373() {
+        UserTO userTO = userService.readSelf();
+        assertEquals(ADMIN_UNAME, userTO.getUsername());
+    }
 
     private boolean getBooleanAttribute(ConnObjectTO connObjectTO, String 
attrName) {
         return Boolean.parseBoolean(getStringAttribute(connObjectTO, 
attrName));


Reply via email to