@Override public Group getGroup(String groupName) throws GroupNotFoundException { LdapContext ctx = null; try { String groupDN = manager.findGroupDN(groupName); // Load record. ctx = manager.getContext(manager.getGroupsBaseDN(groupName)); Attributes attrs = ctx.getAttributes(groupDN, standardAttributes); return processGroup(ctx, attrs); } catch (Exception e) { Log.error(e.getMessage(), e); throw new GroupNotFoundException("Group with name " + groupName + " not found.", e); } finally { try { if (ctx != null) { ctx.setRequestControls(null); ctx.close(); } } catch (Exception ignored) { // Ignore. } } }
@Override public Attributes execute(LdapContext context) throws NamingException { return context.getAttributes(strObjectGUID); } });
@Override public Attributes execute(LdapContext context) throws NamingException { return context.getAttributes(strObjectGUID); } });
LdapContext ctx = new InitialLdapContext(env, null); Attributes attributes = ctx.getAttributes("", new String[] { "supportedSASLMechanisms" }); System.out.println(attributes); // {supportedsaslmechanisms=supportedSASLMechanisms: GSSAPI, EXTERNAL, DIGEST-MD5} Attribute a = atts.get("supportedsaslmechanisms"); System.out.println(a); // supportedSASLMechanisms: GSSAPI, EXTERNAL, DIGEST-MD5 System.out.println(a.get()); // GSSAPI for (int i = 0; i < a.size(); i++) { System.out.print(a.get(i) + " "); // GSSAPI EXTERNAL DIGEST-MD5 }
private Attributes getAttrs() { LdapContext ctx = getLdapContext(); try { return ctx.getAttributes( "cn=your,ou=object,o=dn" , { "cn", "yourattribute" } ); } catch (NamingException e) { // Handle error } catch (NullPointerException e) { // Handle error } finally { try { ctx.close(); } catch (NamingException e) {} } }
public List<String> getUpnSuffixes( LdapContext ctx, String domainName ) { // Domain name should be in DC=you,DC=domain,DC=com format String domConfig = "CN=Partitions,CN=Configuration," +domainName ; List<String> names = new ArrayList<String>(); // Dirty hack to get the default suffix names.add( domainName.replaceAll( "DC=", "" ).replaceAll( "," , "." ); // Read the configuration Attributes attrs = ctx.getAttributes( domConfig , new String[] { "uPNSuffixes" } ); Attribute attr = attrs.get( "uPNSuffixes" ); for ( int i=0; i<attr.size(); i++ ) { names.add( attr.get(i) ); } // Now you have all the suffixes in the "names" list. return names; }
@Override public boolean validateObject(PooledObject<LdapContext> p) { try { p.getObject().getAttributes(new LdapName(config.getDomain())); return true; } catch (NamingException e) { logger.info("Failed to validate an existing ldap service context: {}", e.getMessage()); return false; } }
public static Attributes getUserAttributes(LdapContext ldapContext, String fullDistinguishedName, Properties ldapUserAttributes) throws Exception { Attributes attributes = null; if (!ldapUserAttributes.isEmpty()) { String[] attributeIds = ArrayUtil.toStringArray(ldapUserAttributes.values().toArray(new Object[ldapUserAttributes.size()])); Name fullDN = new CompositeName().add(fullDistinguishedName); int attributeCount = attributeIds.length + AUDIT_ATTRIBUTE_IDS.length; String[] allAttributeIds = new String[attributeCount]; System.arraycopy(attributeIds, 0, allAttributeIds, 0, attributeIds.length); System.arraycopy(AUDIT_ATTRIBUTE_IDS, 0, allAttributeIds, attributeIds.length, AUDIT_ATTRIBUTE_IDS.length); attributes = ldapContext.getAttributes(fullDN, allAttributeIds); } return attributes; }
public static Attributes getUserAttributes(LdapContext ldapContext, String fullDistinguishedName, Properties ldapUserAttributes) throws Exception { Attributes attributes = null; if (!ldapUserAttributes.isEmpty()) { String[] attributeIds = ArrayUtil.toStringArray(ldapUserAttributes.values().toArray(new Object[ldapUserAttributes.size()])); Name fullDN = new CompositeName().add(fullDistinguishedName); int attributeCount = attributeIds.length + AUDIT_ATTRIBUTE_IDS.length; String[] allAttributeIds = new String[attributeCount]; System.arraycopy(attributeIds, 0, allAttributeIds, 0, attributeIds.length); System.arraycopy(AUDIT_ATTRIBUTE_IDS, 0, allAttributeIds, attributeIds.length, AUDIT_ATTRIBUTE_IDS.length); attributes = ldapContext.getAttributes(fullDN, allAttributeIds); } return attributes; }
public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException { Attributes ap = apCtx.getAttributes( "", new String[] { ADMINISTRATIVE_ROLE_ATTR } ); Attribute administrativeRole = ap.get( ADMINISTRATIVE_ROLE_ATTR ); if ( administrativeRole == null || !AttributeUtils.containsValueCaseIgnore( administrativeRole, TRIGGER_EXECUTION_SPECIFIC_AREA_ATTR_VALUE ) ) { Attributes changes = new BasicAttributes( ADMINISTRATIVE_ROLE_ATTR, TRIGGER_EXECUTION_SPECIFIC_AREA_ATTR_VALUE, true ); apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException { Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } ); Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT ); if ( administrativeRole == null || !AttributeUtils.containsValueCaseIgnore( administrativeRole, TRIGGER_EXECUTION_SPECIFIC_AREA_VALUE ) ) { Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT, TRIGGER_EXECUTION_SPECIFIC_AREA_VALUE, true ); apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
private void enableKerberoseSchema() throws DirectoryServerException { // check if krb5kdc is disabled Attributes krb5kdcAttrs; try { krb5kdcAttrs = schemaRoot.getAttributes("cn=Krb5kdc"); boolean isKrb5KdcDisabled = false; if (krb5kdcAttrs.get("m-disabled") != null) { isKrb5KdcDisabled = "TRUE".equalsIgnoreCase((String) krb5kdcAttrs.get("m-disabled").get()); } // if krb5kdc is disabled then enable it if (isKrb5KdcDisabled) { Attribute disabled = new BasicAttribute("m-disabled"); ModificationItem[] mods = new ModificationItem[]{new ModificationItem( DirContext.REMOVE_ATTRIBUTE, disabled)}; schemaRoot.modifyAttributes("cn=Krb5kdc", mods); } } catch (NamingException e) { String msg = "An error occurred while enabling Kerberos schema."; logger.error(msg, e); throw new DirectoryServerException(msg, e); } }
@Override public void testConnection(LdapContextFactory ldapContextFactory) throws NamingException { // get the connection and close it, if this throws an exception, then the config is wrong. LdapContext ctx = null; try { ctx = ldapContextFactory.getSystemLdapContext(); ctx.getAttributes(""); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { // ignore, it might not even be open } } } }
private Set<String> retrieveGroupsFromCallerObject(String callerDn, LdapContext searchContext) { try { Attributes attributes = searchContext.getAttributes(callerDn, new String[] { ldapIdentityStoreDefinition.groupMemberOfAttribute() }); Attribute memberOfAttribute = attributes.get(ldapIdentityStoreDefinition.groupMemberOfAttribute()); Set<String> groups = new HashSet<>(); if (memberOfAttribute != null) { for (Object group : list(memberOfAttribute.getAll())) { if (group != null) { String groupName = getGroupNameFromDn(group.toString(), ldapIdentityStoreDefinition.groupNameAttribute()); if (groupName != null) { groups.add(groupName); } } } } return groups; } catch (NamingException e) { throw new IdentityStoreRuntimeException(e); } }
/** * Defines the Administration point and administrative role for the TriggerExecution specific point * @param apCtx The administrative point context * @throws NamingException If the operation failed */ public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException { Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } ); Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT ); if ( administrativeRole == null || !AttributeUtils.containsValueCaseIgnore( administrativeRole, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) ) { Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA, true ); apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
private Set<String> retrieveGroupsFromCallerObject(String callerDn, LdapContext searchContext) { try { Attributes attributes = searchContext.getAttributes(callerDn, new String[] { ldapIdentityStoreDefinition.groupMemberOfAttribute() }); Attribute memberOfAttribute = attributes.get(ldapIdentityStoreDefinition.groupMemberOfAttribute()); Set<String> groups = new HashSet<>(); if (memberOfAttribute != null) { for (Object group : list(memberOfAttribute.getAll())) { if (group != null) { String groupName = getGroupNameFromDn(group.toString(), ldapIdentityStoreDefinition.groupNameAttribute()); if (groupName != null) { groups.add(groupName); } } } } return groups; } catch (NamingException e) { throw new IdentityStoreRuntimeException(e); } }
/** * Defines the Administration point and administrative role for the TriggerExecution specific point * @param apCtx The administrative point context * @throws NamingException If the operation failed */ public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException { Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } ); Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT ); if ( administrativeRole == null || !AttributeUtils.containsValueCaseIgnore( administrativeRole, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) ) { Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA, true ); apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
private void recursiveSearch(LdapContext ctx, String dn, String field, Set<String> results) throws NamingException { Attributes attrs = ctx.getAttributes(dn, new String[] { field }); NamingEnumeration<? extends Attribute> en = null; for (en = attrs.getAll(); en.hasMoreElements();) { Object aobj = en.nextElement(); if (aobj instanceof Attribute) { Attribute attr = (Attribute) aobj; NamingEnumeration<?> e = null; for (e = attr.getAll(); e.hasMoreElements();) { Object vobj = e.nextElement(); if (vobj instanceof String) { String value = (String) vobj; if (!results.contains(value)) { results.add(value); recursiveSearch(ctx, value, field, results); } } } closeEnumerations(e); } } closeEnumerations(en); }
/** * @param dn * @return * @throws LDAPException * @see org.mule.module.ldap.api.LDAPConnection#lookup(java.lang.String) */ public LDAPEntry lookup(String dn) throws LDAPException { try { return LDAPJNDIUtils.buildEntry(dn, getConn().getAttributes(dn)); } catch (NamingException nex) { throw handleNamingException(nex, "Lookup failed."); } }
/** * @param dn * @param attributes * @return * @throws LDAPException * @see org.mule.module.ldap.api.LDAPConnection#lookup(java.lang.String, * java.lang.String[]) */ public LDAPEntry lookup(String dn, String[] attributes) throws LDAPException { try { return LDAPJNDIUtils.buildEntry(dn, getConn().getAttributes(dn, attributes)); } catch (NamingException nex) { throw handleNamingException(nex, "Lookup failed."); } }