/** * Fetch child groups. * * @param groupName the group name * @return the sets the */ public Set<HibernateGroup> fetchChildGroups(GroupName groupName) { @SuppressWarnings("unchecked") List<HibernateGroup> childGroups = (List<HibernateGroup>) getHibernateTemplate().find( "from HibernateGroup as hg where hg.parentGroup.name = ? and hg.parentGroup.domain = ?", new Object[] { groupName.getName(), groupName.getDomain() }); return new HashSet<HibernateGroup>(childGroups); }
/** * Transform hibernate group to group name. * * @param hibernateGroup the hibernate group * @return the group name */ public static GroupName transformHibernateGroupToGroupName(HibernateGroup hibernateGroup) { if (hibernateGroup == null) { return null; } return new GroupName(hibernateGroup.getDomain(), hibernateGroup.getName()); }
@Override public String addGroup(Group group) throws GroupExistsException, DomainNotSupportedException { if (group.getGroupName().getDomain() == null) { group.getGroupName().setDomain(UserCatalogConstants.DEFAULT_DOMAIN_NAME); } else { checkIfDomainSupported(group.getGroupName().getDomain()); } return groupDao.save(UserCatalogModelHibernateModelTransformer.transformGroupToHibernateGroup(group)); }
/** * Prepares results in proper format. * @param groups * @return results in proper format */ protected AttributeValue[] prepareGroupResults(Set<GroupName> groups) throws IndeterminateException { if (groups==null) { return new AttributeValue[0]; } AttributeValue[] result = new AttributeValue[groups.size()]; int idx = 0; for (GroupName current : groups) { try { result[idx] = AttributeValue.getInstance( Constants.TYPE_STRING, current.getName()); idx++; } catch (XMLDataTypeMappingException e) { throw new IndeterminateException("exception occurred when " + "creating attribute value: " + current.getName(), e); } } return result; }
@Override public void assignGroup(GroupName group, GroupName parent) throws GroupNotFoundException, GroupAssigmentException, CrossDomainOperationException { if (!group.getDomain().equals(parent.getDomain())) { throw new CrossDomainOperationException(); } else { if (group.equals(parent)) { throw new GroupAssigmentException("Group " + group.getName() + " can not be assigned to itself.");
@Override public void assignUser(String userId, GroupName group) throws UserNotFoundException, GroupNotFoundException, CrossDomainOperationException { HibernateUser hibernateUser = userDao.load(userId, null); if (hibernateUser == null) { throw new UserNotFoundException(userId); } else { if (!hibernateUser.getDomain().equals(group.getDomain())) { throw new CrossDomainOperationException(); } else { HibernateGroup hibernateGroup = groupDao.load(group); if (hibernateGroup == null) { throw new GroupNotFoundException(group); } else { hibernateUser.getDirectGroups().add(hibernateGroup); hibernateUser.getEffectiveGroups().add(hibernateGroup); hibernateUser.getEffectiveGroups().addAll(groupDao.getEffectiveGroups(group)); hibernateUser.getEffectiveRoles().addAll(hibernateGroup.getEffectiveRoles()); userDao.update(hibernateUser); } } } }
@Override public void unassignUser(String userId, GroupName group) throws UserNotFoundException, GroupNotFoundException { if (userId==null) { throw new UserNotFoundException(userId); } if (group==null || group.getName()==null) { throw new GroupNotFoundException(group); } try { Name userDN = builUserDn(userId); DirContextOperations ctxOps = ldapTemplate.lookupContext(userDN); Attributes allAttrs = ctxOps.getAttributes(); Attribute groupAttr = allAttrs.get(JoomlaLDAPConstants.GROUP_ATTR_NAME); // disallowing unassigning user from predefined required group name if (groupAttr.contains(group.getName()) && !PREDEFINED_REQUIRED_GROUP_NAME.equals(group.getName())) { groupAttr.remove(group.getName()); ldapTemplate.modifyAttributes(userDN, new ModificationItem[] { new ModificationItem(DirContext.REPLACE_ATTRIBUTE, groupAttr)}); } } catch (NameNotFoundException e) { throw new UserNotFoundException(userId); } }
/** * Transform group to hibernate group. * * @param group the group * @return the hibernate group */ public static HibernateGroup transformGroupToHibernateGroup(Group group) { if (group == null) { return null; } HibernateGroup hibernateGroup = new HibernateGroup(); hibernateGroup.setId(group.getId()); hibernateGroup.setDomain(group.getGroupName().getDomain()); hibernateGroup.fillGroupRelatedFields(group); return hibernateGroup; }
@Override public void assignUser(String userId, GroupName group) throws UserNotFoundException, GroupNotFoundException { if (userId==null) { throw new UserNotFoundException(userId); } if (group==null || group.getName()==null) { throw new GroupNotFoundException(group); } try { Name userDN = builUserDn(userId); DirContextOperations ctxOps = ldapTemplate.lookupContext(userDN); Attributes allAttrs = ctxOps.getAttributes(); Attribute groupAttr = allAttrs.get(JoomlaLDAPConstants.GROUP_ATTR_NAME); if (!groupAttr.contains(group.getName())) { groupAttr.add(group.getName()); ldapTemplate.modifyAttributes(userDN, new ModificationItem[] { new ModificationItem(DirContext.REPLACE_ATTRIBUTE, groupAttr)}); } } catch (NameNotFoundException e) { throw new UserNotFoundException(userId); } }
@Override public GenericResponse deleteGroup(DeleteGroupRequest request) { Map<String, Serializable> auxParams = new HashMap<String, Serializable>(); if (request.getGroupName()!=null && request.getGroupName().getDomain()!=null) { auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_ROOT_SUFFIX, extractDomainRoot(request.getGroupName().getDomain())); auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_SUFFIX, request.getGroupName().getDomain());
for (GroupName groupName : userData.getDirectGroups()) { Element xGroupName = new Element("groupName", ns); xGroupName.setText(groupName.getName()); xGroups.addContent(xGroupName);
NamingEnumeration<?> enumer = attr.getAll(); while (enumer.hasMore()) { groups.add(new GroupName( JoomlaLDAPConstants.DEFAULT_DOMAIN, (String) enumer.next()));
"select count(user) from HibernateGroup as gr " + "left join gr.users as user where gr.name = :name and gr.domain = :domain", new String[] { "name", "domain" }, new Object[] { groupName.getName(), groupName.getDomain() }); return new PaginationResult<HibernateUser>(listCountValues.iterator().next().intValue(), listHibernateUsers);
@SuppressWarnings("unchecked") @Override public PaginationResult<UserData> fetchGroupUsers(GroupName groupName, int firstResult, int maxResults, UserDataParts... fetchParameters) throws GroupNotFoundException { if (groupName==null) { throw new GroupNotFoundException(groupName, "unable to find null group!"); } EqualsFilter filter = new EqualsFilter( JoomlaLDAPConstants.GROUP_ATTR_NAME, groupName.getName()); // FIXME currently no pagination is being performed, it seems LDAP does not provide this functionality List<UserData> results = ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.encode(), new UserDataAttributesMapper(passwordEncoding, fetchEffectiveGroupsSpecified(fetchParameters))); return new PaginationResult<UserData>(results!=null?results.size():0, results); }
ObligationContext obligCtx = new ObligationContext(); Map<String, Serializable> auxParams = new HashMap<String, Serializable>(); if (request.getGroupName()!=null && request.getGroupName().getDomain()!=null) { auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_ROOT_SUFFIX, extractDomainRoot(request.getGroupName().getDomain())); auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_SUFFIX, request.getGroupName().getDomain());