/** * 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; }
/** * 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); }
public Object doInHibernate(Session session) throws HibernateException, SQLException { return session.createQuery("from HibernateGroup as group" + " where domain= :domain and name = :name") .setString("domain", groupName.getDomain()).setString("name", groupName.getName()) .uniqueResult(); } };
@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); } }
@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); } }
xGroup.addContent(xDomain); Element xName = new Element("name", ns); xName.setText(group.getGroupName().getName()); xGroup.addContent(xName);
for (GroupName groupName : userData.getDirectGroups()) { Element xGroupName = new Element("groupName", ns); xGroupName.setText(groupName.getName()); xGroups.addContent(xGroupName);
/** * Fill group related fields. * * @param group the group */ public void fillGroupRelatedFields(Group group) { setName(group.getGroupName().getName()); if (CollectionUtils.isNotEmpty(getEffectiveRoles())) { getEffectiveRoles().removeAll(getRoles()); if (CollectionUtils.isNotEmpty(group.getRoles())) { getEffectiveRoles().addAll(group.getRoles()); } } else { if (CollectionUtils.isNotEmpty(group.getRoles())) { setEffectiveRoles(new HashSet<String>(group.getRoles())); } } if (CollectionUtils.isNotEmpty(group.getRoles())) { setRoles(new HashSet<String>(group.getRoles())); } else { setRoles(new HashSet<String>(0)); } if (MapUtils.isNotEmpty(group.getAttributes())) { setAttributes(new HashMap<String, String>(group.getAttributes())); } else { setAttributes(new HashMap<String, String>()); } }
@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); }
"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);
} else { if (group.equals(parent)) { throw new GroupAssigmentException("Group " + group.getName() + " can not be assigned to itself.");
request.getGroup().getName()); if (request.getGroup().getDomain()!=null) { auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_ROOT_SUFFIX,
request.getGroup().getName()); if (request.getGroup().getDomain()!=null) { auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_ROOT_SUFFIX,
request.getGroup().getName()); if (request.getGroup().getDomain()!=null) { auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_ROOT_SUFFIX,
request.getGroup().getName()); if (request.getGroup().getDomain()!=null) { auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_ROOT_SUFFIX,