1 23 package org.infoglue.cms.util.workflow; 24 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.infoglue.cms.security.InfoGlueGroup; 31 import org.infoglue.cms.security.InfoGluePrincipal; 32 import org.infoglue.cms.security.InfoGlueRole; 33 34 37 class PrincipalOwner implements Owner 38 { 39 42 private final InfoGluePrincipal principal; 43 44 49 PrincipalOwner(final InfoGluePrincipal principal) 50 { 51 this.principal = principal; 52 } 53 54 59 public String getIdentifier() 60 { 61 return principal.getName(); 62 } 63 } 64 65 71 class RoleOwner implements Owner 72 { 73 76 private static final String PREFIX = "\\"; 77 78 81 private final InfoGlueRole role; 82 83 86 private final InfoGlueGroup group; 87 88 93 RoleOwner(final InfoGlueRole role) 94 { 95 this(role, null); 96 } 97 98 104 RoleOwner(final InfoGlueRole role, final InfoGlueGroup group) 105 { 106 this.role = role; 107 this.group = group; 108 } 109 110 115 public String getIdentifier() 116 { 117 if(group == null) 118 { 119 return PREFIX + role.getName(); 120 } 121 else 122 { 123 return PREFIX + role.getName() + PREFIX + group.getName(); 124 } 125 } 126 } 127 128 131 public class OwnerFactory 132 { 133 136 private OwnerFactory() 137 { 138 } 139 140 146 public static final Owner create(final InfoGluePrincipal principal) 147 { 148 return new PrincipalOwner(principal); 149 } 150 151 157 public static final Owner create(final InfoGlueRole role) 158 { 159 return new RoleOwner(role); 160 } 161 162 169 public static final Owner create(final InfoGlueRole role, final InfoGlueGroup group) 170 { 171 return new RoleOwner(role, group); 172 } 173 174 180 public static final Collection createAll(final InfoGluePrincipal principal) 181 { 182 final List owners = new ArrayList (); 183 owners.add(OwnerFactory.create(principal)); 184 for(final Iterator roleIterator = principal.getRoles().iterator(); roleIterator.hasNext(); ) 185 { 186 final InfoGlueRole role = (InfoGlueRole) roleIterator.next(); 187 owners.add(create(role)); 188 for(final Iterator groupIterator = principal.getGroups().iterator(); groupIterator.hasNext(); ) 189 { 190 final InfoGlueGroup group = (InfoGlueGroup) groupIterator.next(); 191 owners.add(create(role, group)); 192 } 193 } 194 return owners; 195 } 196 197 } 198 | Popular Tags |