Search in sources :

Example 1 with BwGroup

use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.

the class Users method getPrincipal.

@Override
public BwPrincipal getPrincipal(final String val) throws CalFacadeException {
    if (val == null) {
        return null;
    }
    final String href;
    if (val.endsWith("/")) {
        href = val.substring(0, val.length() - 1);
    } else {
        href = val;
    }
    final BwPrincipal p = mappedPrincipal(href);
    if (p != null) {
        return p;
    }
    setRoots(getSvc());
    if (!href.startsWith(principalRoot)) {
        return null;
    }
    if (href.startsWith(userPrincipalRoot)) {
        final BwPrincipal u = getSvc().getPrincipal(href);
        if (u != null) {
            principalMap.put(href, u);
        }
        return u;
    }
    if (href.startsWith(groupPrincipalRoot)) {
        final BwGroup g = getSvc().getDirectories().findGroup(href.substring(groupPrincipalRootLen));
        if (g != null) {
            principalMap.put(href, g);
        }
        return g;
    }
    return null;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwGroup(org.bedework.calfacade.BwGroup)

Example 2 with BwGroup

use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.

the class PrincipalsAndPrefsDAO method findGroup.

public BwGroup findGroup(final String account, final boolean admin) throws CalFacadeException {
    final HibSession sess = getSess();
    if (admin) {
        sess.createQuery(getAdminGroupQuery);
    } else {
        sess.createQuery(getGroupQuery);
    }
    sess.setString("account", account);
    return (BwGroup) sess.getUnique();
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwGroup(org.bedework.calfacade.BwGroup)

Example 3 with BwGroup

use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.

the class PrincipalsAndPrefsDAO method getGroups.

@SuppressWarnings("unchecked")
public Collection<BwGroup> getGroups(final BwPrincipal val, final boolean admin) throws CalFacadeException {
    final HibSession sess = getSess();
    if (admin) {
        sess.createQuery(getAdminGroupsQuery);
    } else {
        sess.createQuery(getGroupsQuery);
    }
    sess.setInt("entId", val.getId());
    /* This is what I want to do but it inserts 'true' or 'false'
    sess.setBool("isgroup", (val instanceof BwGroup));
    */
    if (val.getKind() == WhoDefs.whoTypeGroup) {
        sess.setString("isgroup", "T");
    } else {
        sess.setString("isgroup", "F");
    }
    final Set<BwGroup> gs = new TreeSet<>(sess.getList());
    if (admin && (val.getKind() == WhoDefs.whoTypeUser)) {
        /* Event owner for group is implicit member of group. */
        sess.createQuery(getAdminGroupsByEventOwnerQuery);
        sess.setString("ownerHref", val.getPrincipalRef());
        gs.addAll(sess.getList());
    }
    return gs;
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwGroup(org.bedework.calfacade.BwGroup) TreeSet(java.util.TreeSet)

Example 4 with BwGroup

use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.

the class PrincipalsAndPrefsDAO method removeMember.

public void removeMember(final BwGroup group, final BwPrincipal val, final boolean admin) throws CalFacadeException {
    final HibSession sess = getSess();
    if (admin) {
        sess.createQuery(findAdminGroupEntryQuery);
    } else {
        sess.createQuery(findGroupEntryQuery);
    }
    sess.setEntity("grp", group);
    sess.setInt("mbrId", val.getId());
    /* This is what I want to do but it inserts 'true' or 'false'
    sess.setBool("isgroup", (val instanceof BwGroup));
    */
    if (val instanceof BwGroup) {
        sess.setString("isgroup", "T");
    } else {
        sess.setString("isgroup", "F");
    }
    final Object ent = sess.getUnique();
    if (ent == null) {
        return;
    }
    sess.delete(ent);
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwGroup(org.bedework.calfacade.BwGroup)

Example 5 with BwGroup

use of org.bedework.calfacade.BwGroup in project bw-calendar-engine by Bedework.

the class AdminGroupsDbImpl method getAllGroups.

@Override
public Collection<BwGroup> getAllGroups(final BwPrincipal val) throws CalFacadeException {
    final Collection<BwGroup> groups = getGroups(val);
    final Collection<BwGroup> allGroups = new TreeSet<>(groups);
    for (final BwGroup adgrp : groups) {
        // BwGroup grp = new BwGroup(adgrp.getAccount());
        final Collection<BwGroup> gg = getAllGroups(adgrp);
        if (!gg.isEmpty()) {
            allGroups.addAll(gg);
        }
    }
    return allGroups;
}
Also used : BwGroup(org.bedework.calfacade.BwGroup) TreeSet(java.util.TreeSet)

Aggregations

BwGroup (org.bedework.calfacade.BwGroup)19 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)10 NamingEnumeration (javax.naming.NamingEnumeration)6 BasicAttributes (javax.naming.directory.BasicAttributes)6 InitialLdapContext (javax.naming.ldap.InitialLdapContext)6 LdapConfigProperties (org.bedework.calfacade.configs.LdapConfigProperties)6 TreeSet (java.util.TreeSet)5 Attribute (javax.naming.directory.Attribute)4 Attributes (javax.naming.directory.Attributes)4 SearchResult (javax.naming.directory.SearchResult)4 BwPrincipal (org.bedework.calfacade.BwPrincipal)4 HibSession (org.bedework.calcorei.HibSession)3 ArrayList (java.util.ArrayList)2 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)1 PrincipalHref (org.bedework.dumprestore.restore.PrincipalHref)1