/** * Creates the user authority list from the values of the {@code memberOf} attribute * obtained from the user's Active Directory entry. */ @Override protected Collection<? extends GrantedAuthority> loadUserAuthorities( DirContextOperations userData, String username, String password) { String[] groups = userData.getStringAttributes("memberOf"); if (groups == null) { logger.debug("No values for 'memberOf' attribute."); return AuthorityUtils.NO_AUTHORITIES; } if (logger.isDebugEnabled()) { logger.debug("'memberOf' attribute values: " + Arrays.asList(groups)); } ArrayList<GrantedAuthority> authorities = new ArrayList<>( groups.length); for (String group : groups) { authorities.add(new SimpleGrantedAuthority(new DistinguishedName(group) .removeLast().getValue())); } return authorities; }
public String toString() { return getLdapEncoded(); }
@Test public void testLdapRdn_Parse_MultipleComponents() { LdapRdn rdn = new LdapRdn("cn=John Doe+sn=Doe"); assertThat(rdn.getComponent(0).encodeLdap()).isEqualTo("cn=John Doe"); assertThat(rdn.getComponent(1).encodeLdap()).isEqualTo("sn=Doe"); assertThat(rdn.getLdapEncoded()).isEqualTo("cn=John Doe+sn=Doe"); assertThat(rdn.getKey()).isEqualTo("cn"); assertThat(rdn.getValue()).isEqualTo("John Doe"); assertThat(rdn.getValue("cn")).isEqualTo("John Doe"); assertThat(rdn.getValue("sn")).isEqualTo("Doe"); }
@SuppressWarnings("unchecked") public List<Long> groups(String username, LdapConfig config, LdapOperations ldap, RoleProvider provider, final AttributeSet attrSet) { final List<Long> groups = new ArrayList<Long>(); final List<LdapRdn> names = dn.getNames(); for (int i = names.size(); i > 0; i--) { LdapRdn name = names.get(i-1); if ("ou".equals(name.getKey())) { final String grpName = name.getValue("ou"); groups.add(provider.createGroup(grpName, null, false, true)); break; } } return groups; }
@Test public void testLdapRdn_parse_escape() { LdapRdn rdn = new LdapRdn("foo=bar\\=fum"); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo("bar=fum"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\=fum"); }
/** * Add a new {@link LdapRdn} using the supplied key and value. * * @param key the key of the {@link LdapRdn}. * @param value the value of the {@link LdapRdn}. */ public void add(String key, String value) { names.add(new LdapRdn(key, value)); }
/** * Get the key of this LdapRdn. Note that if this Rdn is multi-value the * first key will be returned. E.g. for the Rdn * <code>cn=john doe+sn=doe</code>, the return value would be * <code>cn</code>. * * @return the (first) key of this LdapRdn. * @throws IndexOutOfBoundsException if there are no components in this Rdn. */ public String getKey() { return getComponent().getKey(); }
final public LdapRdn rdn() throws ParseException { LdapRdnComponent rdnComponent; LdapRdn rdn = new LdapRdn(); rdnComponent = attributeTypeAndValue(); rdn.addComponent(rdnComponent); label_2: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 21: ; break; default: jj_la1[2] = jj_gen; break label_2; } jj_consume_token(21); rdnComponent = attributeTypeAndValue(); rdn.addComponent(rdnComponent); } {if (true) return rdn;} throw new Error("Missing return statement in function"); }
/** * Get the {@link LdapRdn} with the specified key. If there are several * {@link Rdn}s with the same key, the first one found (in order of * significance) will be returned. * * @param key Attribute name of the {@link LdapRdn} to retrieve. * @return the {@link LdapRdn} with the requested key. * @throws IllegalArgumentException if no Rdn matches the given key. */ public LdapRdn getLdapRdn(String key) { for (Iterator iter = names.iterator(); iter.hasNext();) { LdapRdn rdn = (LdapRdn) iter.next(); if (ObjectUtils.nullSafeEquals(rdn.getKey(), key)) { return rdn; } } throw new IllegalArgumentException("No Rdn with the requested key: '" + key + "'"); }
while (!longname.equals(shortname) && longiter.hasNext()) { longname = (LdapRdn) longiter.next(); if (!shortiter.hasNext() && longname.equals(shortname)) { return true; while (longname.equals(shortname) && longiter.hasNext() && shortiter.hasNext()) { longname = (LdapRdn) longiter.next(); shortname = (LdapRdn) shortiter.next(); return !shortiter.hasNext() && longname.equals(shortname);
/** * Builds a complete LDAP path, ldap and url encoded. Separates only with * ",". * * @return the LDAP path, for use in an url. */ public String toUrl() { StringBuffer buffer = new StringBuffer(DEFAULT_BUFFER_SIZE); for (int i = names.size() - 1; i >= 0; i--) { LdapRdn n = (LdapRdn) names.get(i); buffer.append(n.encodeUrl()); if (i > 0) { buffer.append(","); } } return buffer.toString(); }
public int hashCode() { return this.getClass().hashCode() ^ new HashSet(getComponents()).hashCode(); }
@Test(expected = UnsupportedOperationException.class) public void testUnmodifiableDistinguishedNameFailsToModifyRdn() throws Exception { DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); LdapRdn ldapRdn = result.getLdapRdn(0); ldapRdn.addComponent(new LdapRdnComponent("somekey", "somevalue")); }
@Test public void testLdapRdn_parse_simple() { LdapRdn rdn = new LdapRdn("foo=bar"); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo("bar"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar"); assertThat(rdn.getKey()).isEqualTo("foo"); assertThat(rdn.getValue()).isEqualTo("bar"); }
@Test public void testLdapRdn_parse_spaces() { LdapRdn rdn = new LdapRdn(" foo = bar "); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo("bar"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar"); }