use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.
the class GroupsDbImpl method removeMember.
/* (non-Javadoc)
* @see org.bedework.calfacade.ifs.Groups#removeMember(org.bedework.calfacade.BwGroup, org.bedework.calfacade.BwPrincipal)
*/
@Override
public void removeMember(final BwGroup group, final BwPrincipal val) throws CalFacadeException {
BwGroup g = findGroup(group.getAccount());
if (g == null) {
throw new CalFacadeException("Group " + group + " does not exist");
}
g.removeGroupMember(val);
cb.removeMember(group, val, false);
}
use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.
the class UserGroupsLdapImpl method findGroup.
/* Search for a group to ensure it exists
*
*/
private BwGroup findGroup(final DirConfigProperties dirProps, final String groupName) throws CalFacadeException {
LdapConfigProperties props = (LdapConfigProperties) dirProps;
InitialLdapContext ctx = null;
try {
ctx = createLdapInitContext(props);
BasicAttributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(props.getGroupIdAttr(), groupName);
String[] idAttr = { props.getGroupIdAttr() };
BwGroup group = null;
NamingEnumeration response = ctx.search(props.getGroupContextDn(), matchAttrs, idAttr);
while (response.hasMore()) {
if (group != null) {
throw new CalFacadeException("org.bedework.ldap.groups.multiple.result");
}
group = new BwGroup();
group.setAccount(groupName);
group.setPrincipalRef(makePrincipalUri(groupName, WhoDefs.whoTypeGroup));
}
return group;
} catch (Throwable t) {
if (debug) {
error(t);
}
throw new CalFacadeException(t);
} finally {
// Close the context to release the connection
if (ctx != null) {
closeContext(ctx);
}
}
}
use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.
the class UserGroupsLdapImpl method getGroups.
/* Return all groups for principal == null or all groups for which principal
* is a member
*
*/
private Collection<BwGroup> getGroups(final DirConfigProperties dirProps, final BwPrincipal principal) throws CalFacadeException {
final ArrayList<BwGroup> groups = new ArrayList<>();
final LdapConfigProperties props = (LdapConfigProperties) dirProps;
if (props.getGroupMemberAttr() == null) {
warn("No group member attribute set - assuming no groups");
return groups;
}
InitialLdapContext ctx = null;
String member = null;
if (principal != null) {
if (principal.getKind() == WhoDefs.whoTypeUser) {
member = getUserEntryValue(props, principal);
} else if (principal.getKind() == WhoDefs.whoTypeGroup) {
member = getGroupEntryValue(props, principal);
}
}
try {
try {
ctx = createLdapInitContext(props);
} catch (final Throwable t) {
warn("*******************************************");
warn("No group information available");
error(t);
return groups;
}
final BasicAttributes matchAttrs = new BasicAttributes(true);
if (member != null) {
matchAttrs.put(props.getGroupMemberAttr(), member);
}
final String[] idAttr = { props.getGroupIdAttr() };
final NamingEnumeration response = ctx.search(props.getGroupContextDn(), matchAttrs, idAttr);
while (response.hasMore()) {
final SearchResult sr = (SearchResult) response.next();
final Attributes attrs = sr.getAttributes();
final Attribute nmAttr = attrs.get(props.getGroupIdAttr());
if (nmAttr.size() != 1) {
throw new CalFacadeException("org.bedework.ldap.groups.multiple.result");
}
final BwGroup group = new BwGroup();
group.setAccount(nmAttr.get(0).toString());
group.setPrincipalRef(makePrincipalUri(group.getAccount(), WhoDefs.whoTypeGroup));
groups.add(group);
}
return groups;
} catch (final Throwable t) {
if (debug) {
error(t);
}
throw new CalFacadeException(t);
} finally {
// Close the context to release the connection
if (ctx != null) {
closeContext(ctx);
}
}
}
use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.
the class MemberRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
/* Top should be the principal info, underneath is the actual entity -
*/
PrincipalHref oi = (PrincipalHref) pop();
try {
if (oi.prefix == null) {
error("Unable to handle principal type " + oi.getKind());
}
oi.href = Util.buildPath(false, oi.prefix, "/", oi.account);
} catch (Throwable t) {
error("Unable to get user principal root", t);
return;
}
BwPrincipal pr = globals.principalsTbl.get(oi);
if (top() instanceof BwGroup) {
BwGroup gr = (BwGroup) top();
if (pr == null) {
if (gr instanceof BwAdminGroup) {
ArrayList<PrincipalHref> m = globals.adminGroupMembers.get(gr.getAccount());
if (m == null) {
m = new ArrayList<PrincipalHref>();
globals.adminGroupMembers.put(gr.getAccount(), m);
}
m.add(oi);
} else {
error("Cannot handle group " + gr);
}
return;
}
gr.addGroupMember(pr);
return;
}
error("Unknown class for member " + top());
}
use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.
the class AdminGroupsDbImpl method removeMember.
@Override
public void removeMember(final BwGroup group, final BwPrincipal val) throws CalFacadeException {
final BwGroup ag = findGroup(group.getAccount());
if (ag == null) {
throw new CalFacadeException(CalFacadeException.groupNotFound, group.getAccount());
}
ag.removeGroupMember(val);
cb.removeMember(group, val, true);
}
Aggregations