1 17 package org.alfresco.repo.security.authority; 18 19 import java.util.Collections ; 20 import java.util.HashSet ; 21 import java.util.Set ; 22 23 import org.alfresco.model.ContentModel; 24 import org.alfresco.repo.security.authentication.AuthenticationComponent; 25 import org.alfresco.service.cmr.repository.NodeRef; 26 import org.alfresco.service.cmr.repository.NodeService; 27 import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; 28 import org.alfresco.service.cmr.security.AuthorityService; 29 import org.alfresco.service.cmr.security.AuthorityType; 30 import org.alfresco.service.cmr.security.PermissionService; 31 import org.alfresco.service.cmr.security.PersonService; 32 33 38 public class SimpleAuthorityServiceImpl implements AuthorityService 39 { 40 private PersonService personService; 41 42 private NodeService nodeService; 43 44 private Set <String > adminSet = Collections.singleton(PermissionService.ADMINISTRATOR_AUTHORITY); 45 46 private Set <String > guestSet = Collections.singleton(PermissionService.GUEST_AUTHORITY); 47 48 private Set <String > allSet = Collections.singleton(PermissionService.ALL_AUTHORITIES); 49 50 private Set <String > adminUsers; 51 52 private AuthenticationComponent authenticationComponent; 53 54 public SimpleAuthorityServiceImpl() 55 { 56 super(); 57 } 58 59 public void setNodeService(NodeService nodeService) 60 { 61 this.nodeService = nodeService; 62 } 63 64 public void setPersonService(PersonService personService) 65 { 66 this.personService = personService; 67 } 68 69 73 public boolean hasAdminAuthority() 74 { 75 String currentUserName = authenticationComponent.getCurrentUserName(); 76 return ((currentUserName != null) && adminUsers.contains(currentUserName)); 77 } 78 79 81 public void setAuthenticationComponent(AuthenticationComponent authenticationComponent) 82 { 83 this.authenticationComponent = authenticationComponent; 84 } 85 86 public void setAdminUsers(Set <String > adminUsers) 87 { 88 this.adminUsers = adminUsers; 89 } 90 91 public Set <String > getAuthorities() 92 { 93 Set <String > authorities = new HashSet <String >(); 94 String currentUserName = authenticationComponent.getCurrentUserName(); 95 if (adminUsers.contains(currentUserName)) 96 { 97 authorities.addAll(adminSet); 98 } 99 if(AuthorityType.getAuthorityType(currentUserName) != AuthorityType.GUEST) 100 { 101 authorities.addAll(allSet); 102 } 103 return authorities; 104 } 105 106 public Set <String > getAllAuthorities(AuthorityType type) 107 { 108 Set <String > authorities = new HashSet <String >(); 109 switch (type) 110 { 111 case ADMIN: 112 authorities.addAll(adminSet); 113 break; 114 case EVERYONE: 115 authorities.addAll(allSet); 116 break; 117 case GUEST: 118 authorities.addAll(guestSet); 119 break; 120 case GROUP: 121 authorities.addAll(allSet); 122 break; 123 case OWNER: 124 break; 125 case ROLE: 126 break; 127 case USER: 128 for (NodeRef personRef : personService.getAllPeople()) 129 { 130 authorities.add(DefaultTypeConverter.INSTANCE.convert(String .class, nodeService.getProperty(personRef, 131 ContentModel.PROP_USERNAME))); 132 } 133 break; 134 default: 135 break; 136 } 137 return authorities; 138 } 139 140 public void addAuthority(String parentName, String childName) 141 { 142 143 } 144 145 146 public String createAuthority(AuthorityType type, String parentName, String shortName) 147 { 148 return ""; 149 } 150 151 public void deleteAuthority(String name) 152 { 153 154 } 155 156 public Set <String > getAllRootAuthorities(AuthorityType type) 157 { 158 return getAllAuthorities(type); 159 } 160 161 public Set <String > getContainedAuthorities(AuthorityType type, String name, boolean immediate) 162 { 163 return Collections.<String >emptySet(); 164 } 165 166 public Set <String > getContainingAuthorities(AuthorityType type, String name, boolean immediate) 167 { 168 return Collections.<String >emptySet(); 169 } 170 171 public String getName(AuthorityType type, String shortName) 172 { 173 if (type.isFixedString()) 174 { 175 return type.getFixedString(); 176 } 177 else if (type.isPrefixed()) 178 { 179 return type.getPrefixString() + shortName; 180 } 181 else 182 { 183 return shortName; 184 } 185 } 186 187 public String getShortName(String name) 188 { 189 AuthorityType type = AuthorityType.getAuthorityType(name); 190 if (type.isFixedString()) 191 { 192 return ""; 193 } 194 else if (type.isPrefixed()) 195 { 196 return name.substring(type.getPrefixString().length()); 197 } 198 else 199 { 200 return name; 201 } 202 203 } 204 205 public void removeAuthority(String parentName, String childName) 206 { 207 208 } 209 210 } 211 | Popular Tags |