Example usage for javax.naming.ldap LdapName equals

List of usage examples for javax.naming.ldap LdapName equals

Introduction

In this page you can find the example usage for javax.naming.ldap LdapName equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Determines whether two LDAP names are equal.

Usage

From source file:LdapNametoString.java

public static void main(String args[]) {
    String name = "cn=JuicyFruit, ou=Fruits";
    try {//from  ww w. j ava  2  s.c o m
        LdapName dn = new LdapName(name);
        String str = dn.toString();
        System.out.println(str);
        LdapName dn2 = new LdapName(str);
        System.out.println(dn.equals(dn2));
    } catch (InvalidNameException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    try {/* w  ww. j a  v  a 2  s . c  o  m*/
        LdapName one = new LdapName("cn=Abc Def, ou=People, o=JNDITutorial");
        LdapName two = new LdapName("cn=Abc Def");
        LdapName three = new LdapName("o=JNDITutorial");
        LdapName four = new LdapName("");

        System.out.println(one.equals(two));
        System.out.println(one.startsWith(three));
        System.out.println(one.endsWith(two));
        System.out.println(one.startsWith(four));
        System.out.println(one.endsWith(four));
        System.out.println(one.endsWith(three));
        System.out.println(one.isEmpty());
        System.out.println(four.isEmpty());
        System.out.println(four.size() == 0);
    } catch (InvalidNameException e) {
        e.printStackTrace();
    }
}

From source file:CompareLdapNames.java

public static void main(String args[]) {
    try {//from   ww w .  j  a v  a  2  s.  c om
        LdapName one = new LdapName("cn=Vincent Ryan, ou=People, o=JNDITutorial");
        LdapName two = new LdapName("cn=Vincent Ryan");
        LdapName three = new LdapName("o=JNDITutorial");
        LdapName four = new LdapName("");

        System.out.println(one.equals(two)); // false
        System.out.println(one.startsWith(three)); // true
        System.out.println(one.endsWith(two)); // true
        System.out.println(one.startsWith(four)); // true
        System.out.println(one.endsWith(four)); // true
        System.out.println(one.endsWith(three)); // false
        System.out.println(one.isEmpty()); // false
        System.out.println(four.isEmpty()); // true
        System.out.println(four.size() == 0); // true
    } catch (InvalidNameException e) {
        e.printStackTrace();
    }
}

From source file:com.ktds.ldap.service.UserService.java

/**
 * Update the user and - if its id changed - update all group references to
 * the user./*w ww  .j a  v  a 2  s  .  co  m*/
 * 
 * @param originalId
 *            the original id of the user.
 * @param existingUser
 *            the user, populated with new data
 * 
 * @return the updated entry
 */
private User updateUserStandard(LdapName originalId, User existingUser) {
    User savedUser = userRepo.save(existingUser);

    if (!originalId.equals(savedUser.getId())) {
        // The user has moved - we need to update group references.
        LdapName oldMemberDn = toAbsoluteDn(originalId);
        LdapName newMemberDn = toAbsoluteDn(savedUser.getId());

        Collection<Group> groups = groupRepo.findByMember(oldMemberDn);
        updateGroupReferences(groups, oldMemberDn, newMemberDn);
    }
    return savedUser;
}

From source file:com.ktds.ldap.service.UserService.java

/**
 * Special behaviour in AD forces us to get the group membership before the
 * user is updated, because AD clears group membership for removed entries,
 * which means that once the user is update we've lost track of which groups
 * the user was originally member of, preventing us to update the membership
 * references so that they point to the new DN of the user.
 * //w  ww .  ja  v  a 2  s.  co  m
 * This is slightly less efficient, since we need to get the group
 * membership for all updates even though the user may not have been moved.
 * Using our knowledge of which attributes are part of the distinguished
 * name we can do this more efficiently if we are implementing specifically
 * for Active Directory - this approach is just to highlight this quite
 * significant difference.
 * 
 * @param originalId
 *            the original id of the user.
 * @param existingUser
 *            the user, populated with new data
 * 
 * @return the updated entry
 */
private User updateUserAd(LdapName originalId, User existingUser) {
    LdapName oldMemberDn = toAbsoluteDn(originalId);
    Collection<Group> groups = groupRepo.findByMember(oldMemberDn);

    User savedUser = userRepo.save(existingUser);
    LdapName newMemberDn = toAbsoluteDn(savedUser.getId());

    if (!originalId.equals(savedUser.getId())) {
        // The user has moved - we need to update group references.
        updateGroupReferences(groups, oldMemberDn, newMemberDn);
    }
    return savedUser;
}

From source file:com.evolveum.midpoint.prism.match.DistinguishedNameMatchingRule.java

@Override
public boolean match(String a, String b) throws SchemaException {
    if (StringUtils.isBlank(a) && StringUtils.isBlank(b)) {
        return true;
    }//from  w  ww  . ja v  a  2s .  co  m
    if (StringUtils.isBlank(a) || StringUtils.isBlank(b)) {
        return false;
    }
    LdapName dnA;
    try {
        dnA = new LdapName(a);
    } catch (InvalidNameException e) {
        throw new SchemaException("String '" + a + "' is not a DN: " + e.getMessage(), e);
    }
    LdapName dnB;
    try {
        dnB = new LdapName(b);
    } catch (InvalidNameException e) {
        throw new SchemaException("String '" + b + "' is not a DN: " + e.getMessage(), e);
    }
    return dnA.equals(dnB);
}

From source file:hu.sztaki.lpds.pgportal.portlets.credential.AssertionPortlet.java

private List<String> getResourceList(PortletSession session, String DN) throws InvalidNameException {
    logger.trace("getResourceList");

    List<Middleware> pResources = (List<Middleware>) session.getAttribute("resources",
            session.APPLICATION_SCOPE);/*from w  ww.ja va2  s  .  com*/
    if (pResources == null) {
        return null;
    }

    List<String> Names = new Vector<String>();
    boolean flag = false;

    LdapName name = new LdapName(DN);
    logger.info("Comparing LDAP name " + name.toString());

    for (Middleware t : pResources) {
        flag = false;

        if (t.isEnabled()) {
            for (Certificate c : t.getCertificate()) {
                if (Certificate.SAML.equals(c)) {
                    flag = true;
                }
            }
        }

        if (flag) {
            for (Item i : t.getItem()) {
                Unicore uni = i.getUnicore();
                if (t.isEnabled()) {
                    try {
                        LdapName subject = new LdapName(uni.getSubjectdn());

                        logger.info("Checking DN: " + uni.getSubjectdn() + "?");
                        logger.info("Subject: " + subject.toString());
                        if (name.equals(subject)) {
                            Names.add(i.getName());
                        }
                    } catch (InvalidNameException e) {
                        logger.warn("Internal error: Reported certificate from service invalid" + uni);
                        logger.warn("Reported DN: " + uni.getSubjectdn());
                        logger.debug("Stack trace:", e);
                    }

                    logger.debug("Alias" + uni.getKeyalias());
                }
            }
        }
    }
    return Names;
}

From source file:hu.sztaki.lpds.pgportal.portlets.credential.AssertionPortlet.java

private List<String> getResourceList(ActionRequest request, String DN) throws InvalidNameException {
    @SuppressWarnings("unchecked")
    List<Middleware> pResources = (List<Middleware>) request.getPortletSession().getAttribute("resources",
            request.getPortletSession().APPLICATION_SCOPE);

    List<String> Names = new Vector<String>();
    boolean flag = false;

    LdapName name = new LdapName(DN);
    System.out.println("Comparing LDAP name " + name.toString());

    for (Middleware t : pResources) {
        flag = false;//from  ww  w . j  av a2s. c o m

        if (t.isEnabled()) {
            for (Certificate c : t.getCertificate()) {
                if (Certificate.SAML.equals(c)) {
                    flag = true;
                }
            }
        }

        if (flag) {
            for (Item i : t.getItem()) {
                Unicore uni = i.getUnicore();
                if (t.isEnabled()) {
                    try {
                        LdapName subject = new LdapName(uni.getSubjectdn());

                        System.out.println("Checking DN: " + uni.getSubjectdn() + "?");
                        System.out.println("Subject: " + subject.toString());
                        if (name.equals(subject)) {
                            Names.add(i.getName());
                        }
                    } catch (InvalidNameException e) {
                        logger.warn("Internal error: Reported certificate from service invalid", uni);
                        logger.warn("Reported DN: " + uni.getSubjectdn());
                        logger.trace("Stack trace:", e);
                    }

                    // System.out.println("uni-alias" + uni.getKeyalias());
                }
            }
        }
    }
    return Names;
}

From source file:org.apache.zeppelin.realm.LdapRealm.java

private void addRoleIfMember(final String userDn, final SearchResult group, final Set<String> roleNames,
        final Set<String> groupNames, final LdapContextFactory ldapContextFactory) throws NamingException {
    NamingEnumeration<? extends Attribute> attributeEnum = null;
    NamingEnumeration<?> ne = null;
    try {//w  w w  .ja va  2 s  .  com
        LdapName userLdapDn = new LdapName(userDn);
        Attribute attribute = group.getAttributes().get(getGroupIdAttribute());
        String groupName = attribute.get().toString();

        attributeEnum = group.getAttributes().getAll();
        while (attributeEnum.hasMore()) {
            final Attribute attr = attributeEnum.next();
            if (!memberAttribute.equalsIgnoreCase(attr.getID())) {
                continue;
            }
            ne = attr.getAll();
            while (ne.hasMore()) {
                String attrValue = ne.next().toString();
                if (memberAttribute.equalsIgnoreCase(MEMBER_URL)) {
                    boolean dynamicGroupMember = isUserMemberOfDynamicGroup(userLdapDn, attrValue,
                            ldapContextFactory);
                    if (dynamicGroupMember) {
                        groupNames.add(groupName);
                        String roleName = roleNameFor(groupName);
                        if (roleName != null) {
                            roleNames.add(roleName);
                        } else {
                            roleNames.add(groupName);
                        }
                    }
                } else {
                    // posix groups' members don' include the entire dn
                    if (groupObjectClass.equalsIgnoreCase(POSIX_GROUP)) {
                        attrValue = memberDn(attrValue);
                    }
                    if (userLdapDn.equals(new LdapName(attrValue))) {
                        groupNames.add(groupName);
                        String roleName = roleNameFor(groupName);
                        if (roleName != null) {
                            roleNames.add(roleName);
                        } else {
                            roleNames.add(groupName);
                        }
                        break;
                    }
                }
            }
        }
    } finally {
        try {
            if (attributeEnum != null) {
                attributeEnum.close();
            }
        } finally {
            if (ne != null) {
                ne.close();
            }
        }
    }
}