private void cleanUp(InitialContext initialContext) { try { initialContext.close(); } catch ( NamingException e ) { LOG.unableToCloseInitialContext(e.toString()); } }
protected DirContext open() throws NamingException { if (context != null) { return context; } try { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); if (connectionUsername != null && !"".equals(connectionUsername)) { env.put(Context.SECURITY_PRINCIPAL, connectionUsername); } else { throw new NamingException("Empty username is not allowed"); } if (connectionPassword != null && !"".equals(connectionPassword)) { env.put(Context.SECURITY_CREDENTIALS, connectionPassword); } else { throw new NamingException("Empty password is not allowed"); } env.put(Context.SECURITY_PROTOCOL, connectionProtocol); env.put(Context.PROVIDER_URL, connectionURL); env.put(Context.SECURITY_AUTHENTICATION, authentication); context = new InitialDirContext(env); } catch (NamingException e) { LOG.error(e.toString()); throw e; } return context; }
public Set<GroupPrincipal> getTempDestinationReadACLs() { try { context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } SearchControls constraints = new SearchControls(); constraints.setReturningAttributes(new String[] {readAttribute}); return getACLs(tempSearchBase, constraints, readBase, readAttribute); }
public Set<GroupPrincipal> getTempDestinationAdminACLs() { try { context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } SearchControls constraints = new SearchControls(); constraints.setReturningAttributes(new String[] {adminAttribute}); return getACLs(tempSearchBase, constraints, adminBase, adminAttribute); }
public Set<GroupPrincipal> getTempDestinationWriteACLs() { try { context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } SearchControls constraints = new SearchControls(); constraints.setReturningAttributes(new String[] {writeAttribute}); return getACLs(tempSearchBase, constraints, writeBase, writeAttribute); }
protected Set<GroupPrincipal> getACLs(String destinationBase, SearchControls constraints, String roleBase, String roleAttribute) { try { Set<GroupPrincipal> roles = new HashSet<GroupPrincipal>(); Set<String> acls = new HashSet<String>(); NamingEnumeration<?> results = context.search(destinationBase, roleBase, constraints); while (results.hasMore()) { SearchResult result = (SearchResult)results.next(); Attributes attrs = result.getAttributes(); if (attrs == null) { continue; } acls = addAttributeValues(roleAttribute, attrs, acls); } for (Iterator<String> iter = acls.iterator(); iter.hasNext();) { String roleName = iter.next(); LdapName ldapname = new LdapName(roleName); Rdn rdn = ldapname.getRdn(ldapname.size() - 1); LOG.debug("Found role: [" + rdn.getValue().toString() + "]"); roles.add(new GroupPrincipal(rdn.getValue().toString())); } return roles; } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } }
protected DirContext open() throws NamingException { try { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, getLDAPPropertyValue(INITIAL_CONTEXT_FACTORY)); if (isLoginPropertySet(CONNECTION_USERNAME)) { env.put(Context.SECURITY_PRINCIPAL, getLDAPPropertyValue(CONNECTION_USERNAME)); } else { throw new NamingException("Empty username is not allowed"); } if (isLoginPropertySet(CONNECTION_PASSWORD)) { env.put(Context.SECURITY_CREDENTIALS, getLDAPPropertyValue(CONNECTION_PASSWORD)); } else { throw new NamingException("Empty password is not allowed"); } env.put(Context.SECURITY_PROTOCOL, getLDAPPropertyValue(CONNECTION_PROTOCOL)); env.put(Context.PROVIDER_URL, getLDAPPropertyValue(CONNECTION_URL)); env.put(Context.SECURITY_AUTHENTICATION, getLDAPPropertyValue(AUTHENTICATION)); context = new InitialDirContext(env); } catch (NamingException e) { log.error(e.toString()); throw e; } return context; }
context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>();
@Override protected Object doMapFromContext(DirContextOperations ctx) { if (resultFilter != null && !resultFilter.needSelect(ctx.getNameInNamespace())){ return null; } Map<String, Object> result = new HashMap<>(); result.put(LdapConstant.LDAP_DN_KEY, ctx.getNameInNamespace()); List<Object> list = new ArrayList<>(); result.put("attributes", list); Attributes attributes = ctx.getAttributes(); NamingEnumeration it = attributes.getAll(); try { while (it.hasMore()){ list.add(it.next()); } } catch (javax.naming.NamingException e){ logger.error("query ldap entry attributes fail", e.getCause()); throw new OperationFailureException(operr("query ldap entry fail, %s", e.toString())); } return result; } }, processor);
/** * @return Next object of the enumeration */ public T nextElement() { try { return next(); } catch (NamingException e) { throw new java.util.NoSuchElementException(e.toString()); } }
/** * Returns the next element of this enumeration if this enumeration * object has at least one more element to provide. * @return the next element of this enumeration. */ public T nextElement() { try { return next(); } catch (NamingException e) { throw new NoSuchElementException(e.toString()); } }
public void produce( SearchResult result ) throws SAXException { try { produce( result.getName(), result.getAttributes() ); } catch ( NamingException except ) { throw new SAXException( except.toString() ); } }
public Set<GroupPrincipal> getTempDestinationReadACLs() { try { context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } SearchControls constraints = new SearchControls(); constraints.setReturningAttributes(new String[] {readAttribute}); return getACLs(tempSearchBase, constraints, readBase, readAttribute); }
public Set<GroupPrincipal> getTempDestinationWriteACLs() { try { context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } SearchControls constraints = new SearchControls(); constraints.setReturningAttributes(new String[] {writeAttribute}); return getACLs(tempSearchBase, constraints, writeBase, writeAttribute); }
public Set<GroupPrincipal> getTempDestinationAdminACLs() { try { context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } SearchControls constraints = new SearchControls(); constraints.setReturningAttributes(new String[] {adminAttribute}); return getACLs(tempSearchBase, constraints, adminBase, adminAttribute); }
public Set<GroupPrincipal> getTempDestinationAdminACLs() { try { context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } SearchControls constraints = new SearchControls(); constraints.setReturningAttributes(new String[] {adminAttribute}); return getACLs(tempSearchBase, constraints, adminBase, adminAttribute); }
public Set<GroupPrincipal> getTempDestinationWriteACLs() { try { context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } SearchControls constraints = new SearchControls(); constraints.setReturningAttributes(new String[] {writeAttribute}); return getACLs(tempSearchBase, constraints, writeBase, writeAttribute); }
public Set<GroupPrincipal> getTempDestinationReadACLs() { try { context = open(); } catch (NamingException e) { LOG.error(e.toString()); return new HashSet<GroupPrincipal>(); } SearchControls constraints = new SearchControls(); constraints.setReturningAttributes(new String[] {readAttribute}); return getACLs(tempSearchBase, constraints, readBase, readAttribute); }
private void cleanUp(InitialContext initialContext) { try { initialContext.close(); } catch ( NamingException e ) { LOG.unableToCloseInitialContext(e.toString()); } }
private String getBase() { String base = null; try { base = ctx.getReadOnlyContext().getNameInNamespace(); } catch (NamingException e) { throw new ApiUsageException( "Cannot get BASE from ContextSource. Naming exception! " + e.toString()); } return base; }