You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2012/11/29 15:34:47 UTC

svn commit: r1415183 - in /syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core: rest/controller/RoleController.java sync/SyncJob.java sync/SyncopeSyncResultHandler.java util/EntitlementUtil.java

Author: ilgrosso
Date: Thu Nov 29 14:34:46 2012
New Revision: 1415183

URL: http://svn.apache.org/viewvc?rev=1415183&view=rev
Log:
Fixing some minor issues after some tests

Modified:
    syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
    syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncJob.java
    syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncopeSyncResultHandler.java
    syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/util/EntitlementUtil.java

Modified: syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
URL: http://svn.apache.org/viewvc/syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java?rev=1415183&r1=1415182&r2=1415183&view=diff
==============================================================================
--- syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java (original)
+++ syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java Thu Nov 29 14:34:46 2012
@@ -53,10 +53,6 @@ import org.apache.syncope.types.AuditEle
 import org.apache.syncope.types.AuditElements.RoleSubCategory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Controller;
 import org.springframework.transaction.annotation.Transactional;
@@ -301,13 +297,7 @@ public class RoleController extends Abst
 
         WorkflowResult<Long> created = rwfAdapter.create(roleTO);
 
-        // Extend the current authentication context to include the role just created
-        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
-        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(auth.getAuthorities());
-        authorities.add(new SimpleGrantedAuthority(EntitlementUtil.getEntitlementNameFromRoleId(created.getResult())));
-        Authentication newAuth = new UsernamePasswordAuthenticationToken(
-                auth.getPrincipal(), auth.getCredentials(), authorities);
-        SecurityContextHolder.getContext().setAuthentication(newAuth);
+        EntitlementUtil.extendAuthContext(created.getResult());
 
         List<PropagationTask> tasks = propagationManager.getRoleCreateTaskIds(created, roleTO.getVirtualAttributes());
 

Modified: syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncJob.java
URL: http://svn.apache.org/viewvc/syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncJob.java?rev=1415183&r1=1415182&r2=1415183&view=diff
==============================================================================
--- syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncJob.java (original)
+++ syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncJob.java Thu Nov 29 14:34:46 2012
@@ -162,7 +162,6 @@ public class SyncJob extends AbstractTas
 
         // Failures
         if (syncTraceLevel == TraceLevel.FAILURES || syncTraceLevel == TraceLevel.ALL) {
-
             if (!createdFailed.isEmpty()) {
                 report.append("\n\nFailed to create: ");
                 report.append(SyncResult.reportSetOfSynchronizationResult(createdFailed, syncTraceLevel));

Modified: syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncopeSyncResultHandler.java
URL: http://svn.apache.org/viewvc/syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncopeSyncResultHandler.java?rev=1415183&r1=1415182&r2=1415183&view=diff
==============================================================================
--- syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncopeSyncResultHandler.java (original)
+++ syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/sync/SyncopeSyncResultHandler.java Thu Nov 29 14:34:46 2012
@@ -427,6 +427,8 @@ public class SyncopeSyncResultHandler im
                 if (AttributableType.ROLE == attrUtil.getType()) {
                     WorkflowResult<Long> created = rwfAdapter.create((RoleTO) subjectTO);
 
+                    EntitlementUtil.extendAuthContext(created.getResult());
+
                     List<PropagationTask> tasks = propagationManager.getRoleCreateTaskIds(created,
                             subjectTO.getVirtualAttributes(), Collections.singleton(syncTask.getResource().getName()));
 

Modified: syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/util/EntitlementUtil.java
URL: http://svn.apache.org/viewvc/syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/util/EntitlementUtil.java?rev=1415183&r1=1415182&r2=1415183&view=diff
==============================================================================
--- syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/util/EntitlementUtil.java (original)
+++ syncope/branches/DEV_ROLE_PROVISIONING/core/src/main/java/org/apache/syncope/core/util/EntitlementUtil.java Thu Nov 29 14:34:46 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.core.util;
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -25,7 +26,10 @@ import java.util.regex.Pattern;
 import org.apache.syncope.core.persistence.beans.Entitlement;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.context.SecurityContext;
 import org.springframework.security.core.context.SecurityContextHolder;
 
@@ -102,6 +106,20 @@ public final class EntitlementUtil {
     }
 
     /**
+     * Extend the current authentication context to include the given role.
+     * 
+     * @param roleId role id
+     */
+    public static void extendAuthContext(final Long roleId) {
+        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(auth.getAuthorities());
+        authorities.add(new SimpleGrantedAuthority(EntitlementUtil.getEntitlementNameFromRoleId(roleId)));
+        Authentication newAuth = new UsernamePasswordAuthenticationToken(
+                auth.getPrincipal(), auth.getCredentials(), authorities);
+        SecurityContextHolder.getContext().setAuthentication(newAuth);
+    }
+
+    /**
      * Private default constructor, for static-only classes.
      */
     private EntitlementUtil() {