public void setEntityType(String entityType) { this.entityType = EntityEnum.getEntityEnum(entityType); }
/** * 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; }
@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; }
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; }
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<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 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; } }
@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(); }
public EntityEnum getEntityType(IGroupMember entity) { if (IEntityGroup.class.isAssignableFrom(entity.getClass())) { return EntityEnum.getEntityEnum(entity.getLeafType(), true); } else { return EntityEnum.getEntityEnum(entity.getLeafType(), false); } }
/** * Compute a hash based on type and ID to uniquely identify this bean. This method helps avoid * the unlikely case where a group and person in the same principal list have the same ID. * * <p>Periods are replaced to avoid issues in JSP EL and form names can't contain spaces. Also * SpEL parsing of form field names fails with characters such as dash or parenthesis (which * PAGS groups can have) and likely other characters so they are also replaced with underscores. * * @return EntityType + "_" + ID */ public String getTypeAndIdHash() { assert (entityType != null); assert (id != null); String idStr = id.replaceAll("\\W", "__"); return entityType.toString().toLowerCase() + "_" + idStr; }
@Override public EntityEnum getEntityType(IGroupMember entity) { if (entity == null) { throw new IllegalArgumentException("Parameter must not be null"); } if (IEntityGroup.class.isAssignableFrom(entity.getClass())) { return EntityEnum.getEntityEnum(entity.getLeafType(), true); } else { return EntityEnum.getEntityEnum(entity.getLeafType(), false); } }
@Override public Entity getGroup(String groupId, boolean populateChildren) { return EntityService.instance() .getEntity(EntityEnum.GROUP.toString(), groupId, populateChildren); }
/** * Convenience method that looks up the name of the given group member. Used for person types. * * @param entity Entity to look up * @return groupMember's name or null if there's an error */ public String lookupEntityName(Entity entity) { if (entity == null) { return null; } EntityEnum entityEnum = EntityEnum.getEntityEnum(entity.getEntityType()); return lookupEntityName(entityEnum, entity.getId()); }
public static Entity createEntity(IGroupMember member, EntityEnum entityType) { if (member == null) { return null; } Entity entity = new EntityImpl(); entity.setEntityType(entityType.toString()); entity.setId(member.getKey()); setPrincipal(entity); return entity; }
public static Entity createEntity(IEntityGroup group, EntityEnum entityType) { if (group == null) { return null; } Entity entity = new EntityImpl(); entity.setEntityType(entityType.toString()); entity.setId(group.getKey()); entity.setName(group.getName()); entity.setCreatorId(group.getCreatorID()); entity.setDescription(group.getDescription()); setPrincipal(entity); return entity; }