1 13 package info.magnolia.cms.security; 14 15 import info.magnolia.cms.security.auth.Entity; 16 import info.magnolia.cms.security.auth.GroupList; 17 import info.magnolia.cms.security.auth.RoleList; 18 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 import java.util.Set ; 22 23 import javax.security.auth.Subject ; 24 25 import org.slf4j.Logger; 26 import org.slf4j.LoggerFactory; 27 28 29 35 public class ExternalUser implements User { 36 37 public static Logger log = LoggerFactory.getLogger(ExternalUser.class); 38 39 42 private Entity userDetails; 43 44 47 private RoleList roleList; 48 49 52 private GroupList groupList; 53 54 57 protected ExternalUser(Subject subject) { 58 Set principalSet = subject.getPrincipals(Entity.class); 59 Iterator entityIterator = principalSet.iterator(); 60 this.userDetails = (Entity) entityIterator.next(); 61 principalSet = subject.getPrincipals(RoleList.class); 62 Iterator roleListIterator = principalSet.iterator(); 63 this.roleList = (RoleList) roleListIterator.next(); 64 principalSet = subject.getPrincipals(GroupList.class); 65 Iterator groupListIterator = principalSet.iterator(); 66 this.groupList = (GroupList) groupListIterator.next(); 67 } 68 69 73 public boolean hasRole(String roleName) { 74 return this.roleList.has(roleName); 75 } 76 77 81 public void removeRole(String roleName) { 82 throw new UnsupportedOperationException ("not implemented for this ExternalUser"); 83 } 84 85 89 public void addRole(String roleName) { 90 throw new UnsupportedOperationException ("not implemented for this ExternalUser"); 91 } 92 93 98 public boolean inGroup(String groupName) { 99 return this.groupList.has(groupName); 100 } 101 102 106 public void removeGroup(String groupName) throws UnsupportedOperationException { 107 throw new UnsupportedOperationException ("not implemented for this ExternalUser"); 108 } 109 110 114 public void addGroup(String groupName) throws UnsupportedOperationException { 115 throw new UnsupportedOperationException ("not implemented for this ExternalUser"); 116 } 117 118 122 123 public String getLanguage() { 124 return (String ) this.userDetails.getProperty(Entity.LANGUAGE); 125 } 126 127 131 public String getName() { 132 return (String ) this.userDetails.getProperty(Entity.NAME); 133 } 134 135 139 public String getPassword() { 140 return (String ) this.userDetails.getProperty(Entity.PASSWORD); 141 } 142 143 146 public Collection getGroups() { 147 return this.groupList.getList(); 148 } 149 150 153 public Collection getRoles() { 154 return this.roleList.getList(); 155 } 156 } | Popular Tags |