EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType); EntityIdentifier[] identifiers; Class<?> identifierType; if (entityEnum.isGroup()) { identifiers = GroupService.searchForGroups( searchTerm, GroupService.SearchMethod.CONTAINS_CI, entityEnum.getClazz()); identifierType = IEntityGroup.class; searchTerm, GroupService.SearchMethod.CONTAINS_CI, entityEnum.getClazz()); identifierType = entityEnum.getClazz();
public IAuthorizationPrincipal getPrincipalForEntity(Entity entity) { // attempt to determine the entity type class for this principal if (entity == null) { return null; } Class entityType; if (entity.getEntityType().equals(EntityEnum.GROUP.toString())) { entityType = IEntityGroup.class; } else { entityType = EntityEnum.getEntityEnum(entity.getEntityType()).getClazz(); } // construct an authorization principal for this JsonEntityBean AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance(); IAuthorizationPrincipal p = authService.newPrincipal(entity.getId(), entityType); return p; }
@Override public Set<String> getEntityTypesForGroupType(String groupType) { // add the group type itself to the allowed list Set<String> set = new HashSet<String>(); set.add(groupType); /* * If the supplied type is a person group, add the person entity type. * If the supplied type is a category, add the channel type. Otherwise, * throw an exception. * * This method will require an update if more entity types are added * in the future. */ EntityEnum type = EntityEnum.getEntityEnum(groupType); if (EntityEnum.GROUP.equals(type)) { set.add(EntityEnum.PERSON.toString()); } else if (EntityEnum.CATEGORY.equals(type)) { set.add(EntityEnum.PORTLET.toString()); } else { throw new IllegalArgumentException( "Unable to determine a root entity for group type '" + groupType + "'"); } return set; }
@Override public JsonEntityBean getRootEntity(String groupType) { EntityEnum type = EntityEnum.getEntityEnum(groupType); String rootKey; if (EntityEnum.GROUP.equals(type)) { rootKey = "local.0"; } else if (EntityEnum.CATEGORY.equals(type)) { IEntityGroup categoryGroup = GroupService.getDistinguishedGroup(IPortletDefinition.DISTINGUISHED_GROUP); return new JsonEntityBean(categoryGroup, EntityEnum.CATEGORY); } else { throw new IllegalArgumentException( "Unable to determine a root entity for group type '" + groupType + "'"); } JsonEntityBean bean = getEntity(groupType, rootKey, false); return bean; }
@Override public IAuthorizationPrincipal getPrincipalForEntity(JsonEntityBean entity) { if (entity == null) { throw new IllegalArgumentException("Parameter cannot be null."); } // attempt to determine the entity type class for this principal Class entityType; EntityEnum jsonType = entity.getEntityType(); if (jsonType == null) { throw new IllegalArgumentException("Parameter's entityType cannot be null."); } if (jsonType.isGroup()) { entityType = IEntityGroup.class; } else { entityType = jsonType.getClazz(); } // construct an authorization principal for this JsonEntityBean AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance(); IAuthorizationPrincipal p = authService.newPrincipal(entity.getId(), entityType); return p; }
return null; EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType); if (entityEnum.isGroup()) { IGroupMember groupMember = GroupService.getGroupMember(entityId, entityEnum.getClazz()); if (groupMember == null || groupMember instanceof IEntityGroup) { return null; if (EntityEnum.GROUP.toString().equals(entity.getEntityType()) || EntityEnum.PERSON.toString().equals(entity.getEntityType())) { IAuthorizationPrincipal authP = getPrincipalForEntity(entity); Principal principal = new PrincipalImpl(authP.getKey(), authP.getPrincipalString());
EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType); if (entityEnum == null) { throw new IllegalArgumentException( if (entityEnum.isGroup()) { jsonBean = populateChildren(jsonBean, members); if (jsonBean.getEntityType().isGroup() || EntityEnum.PERSON.equals(jsonBean.getEntityType())) { IAuthorizationPrincipal principal = getPrincipalForEntity(jsonBean); jsonBean.setPrincipalString(principal.getPrincipalString()); IGroupMember entity = GroupService.getGroupMember(entityId, entityEnum.getClazz()); if (entity == null || entity instanceof IEntityGroup) { return null; if (EntityEnum.GROUP.equals(jsonBean.getEntityType()) || EntityEnum.PERSON.equals(jsonBean.getEntityType())) { IAuthorizationPrincipal principal = getPrincipalForEntity(jsonBean); jsonBean.setPrincipalString(principal.getPrincipalString());
groupName, GroupService.SearchMethod.DISCRETE, EntityEnum.GROUP.getClazz()); for (EntityIdentifier entityIdentifier : identifiers) { if (entityIdentifier.getType().equals(IEntityGroup.class)) {
private AuthorizableActivity getViewActivity( final String activityKey, final JsonEntityBean entity) { if (entity != null && activityKey.equals("VIEW")) { final EntityEnum type = entity.getEntityType(); if (type.isGroup()) { return new AuthorizableActivity( IPermission.PORTAL_GROUPS, IPermission.VIEW_GROUP_ACTIVITY); } else if (type.equals(EntityEnum.PERSON)) { return new AuthorizableActivity( IPermission.PORTAL_USERS, IPermission.VIEW_USER_ACTIVITY); } else if (type.equals(EntityEnum.PORTLET)) { return new AuthorizableActivity( IPermission.PORTAL_SUBSCRIBE, IPermission.PORTLET_SUBSCRIBER_ACTIVITY); } } return null; }
@Override public Set<Entity> getGroupsForMember(String memberName) { Set<Entity> groups = new HashSet<Entity>(); if (StringUtils.isNotEmpty(memberName)) { EntityIdentifier[] identifiers = GroupService.searchForEntities( memberName, GroupService.SearchMethod.DISCRETE, EntityEnum.PERSON.getClazz()); for (EntityIdentifier entityIdentifier : identifiers) { if (entityIdentifier.getType().equals(EntityEnum.PERSON.getClazz())) { IGroupMember groupMember = GroupService.getGroupMember(entityIdentifier); if (memberName.equalsIgnoreCase(groupMember.getKey())) { Iterator it = GroupService.findParentGroups(groupMember); while (it.hasNext()) { IEntityGroup g = (IEntityGroup) it.next(); Entity e = EntityFactory.createEntity( g, EntityEnum.getEntityEnum(g.getLeafType(), true)); groups.add(e); } return groups; } } } } return groups; }
public Entity getEntity(IGroupMember member) { if (member == null) { return null; } // get the type of this member entity EntityEnum entityEnum = getEntityType(member); // construct a new entity bean for this entity Entity entity; if (entityEnum.isGroup()) { entity = EntityFactory.createEntity((IEntityGroup) member, entityEnum); } else { entity = EntityFactory.createEntity(member, entityEnum); } // if the name hasn't been set yet, look up the entity name if (entity.getName() == null) { entity.setName(lookupEntityName(entity)); } if (EntityEnum.GROUP.toString().equals(entity.getEntityType()) || EntityEnum.PERSON.toString().equals(entity.getEntityType())) { IAuthorizationPrincipal authP = getPrincipalForEntity(entity); Principal principal = new PrincipalImpl(authP.getKey(), authP.getPrincipalString()); entity.setPrincipal(principal); } return entity; }
/** * Get an EntityEnum for a String type representation. * * @param type * @return */ public static EntityEnum getEntityEnum(String type) { if (PORTLET.toString().equalsIgnoreCase(type)) { return PORTLET; } else if (CATEGORY.toString().equalsIgnoreCase(type)) { return CATEGORY; } else if (PERSON.toString().equalsIgnoreCase(type)) { return PERSON; } else if (GROUP.toString().equalsIgnoreCase(type)) { return GROUP; } return null; }
public void setEntityType(String entityType) { this.entityType = EntityEnum.getEntityEnum(entityType); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; JsonEntityBean other = (JsonEntityBean) obj; if (childrenInitialized != other.childrenInitialized) return false; if (creatorId == null) { if (other.creatorId != null) return false; } else if (!creatorId.equals(other.creatorId)) return false; if (description == null) { if (other.description != null) return false; } else if (!description.equals(other.description)) return false; if (entityType == null) { if (other.entityType != null) return false; } else if (!entityType.equals(other.entityType)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (childrenInitialized ? 1231 : 1237); result = prime * result + ((creatorId == null) ? 0 : creatorId.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((entityType == null) ? 0 : entityType.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; }
public String lookupEntityName(EntityEnum entityType, String entityId) { if (entityType == null && (StringUtils.isBlank(entityId))) { return null; } IEntityNameFinder finder; if (entityType.isGroup()) { finder = EntityNameFinderService.instance().getNameFinder(IEntityGroup.class); } else { finder = EntityNameFinderService.instance().getNameFinder(entityType.getClazz()); } try { return finder.getName(entityId); } catch (Exception e) { /* An exception here isn't the end of the world. Just log it and return null. */ log.warn("Couldn't find name for entity " + entityId, e); return null; } }
person.getUserName(), EntityEnum.PERSON.getClazz());
@Override public JsonEntityBean getEntity(IGroupMember member) { // get the type of this member entity EntityEnum entityEnum = getEntityType(member); // construct a new entity bean for this entity JsonEntityBean entity; if (entityEnum.isGroup()) { entity = new JsonEntityBean((IEntityGroup) member, entityEnum); } else { entity = new JsonEntityBean(member, entityEnum); } // if the name hasn't been set yet, look up the entity name if (entity.getName() == null) { entity.setName(lookupEntityName(entity)); } if (EntityEnum.GROUP.equals(entity.getEntityType()) || EntityEnum.PERSON.equals(entity.getEntityType())) { IAuthorizationPrincipal principal = getPrincipalForEntity(entity); entity.setPrincipalString(principal.getPrincipalString()); } return entity; }
public String getEntityTypeAsString() { return entityType.toString().toUpperCase(); }