Java Code Examples for org.apache.directory.api.ldap.model.name.Dn#isEmpty()
The following examples show how to use
org.apache.directory.api.ldap.model.name.Dn#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DnNode.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Creates a new instance of DnNode. * * @param dn the node's Dn * @param element the element to store */ public DnNode( Dn dn, N element ) { if ( ( dn == null ) || ( dn.isEmpty() ) ) { children = new HashMap<>(); this.nodeDn = Dn.EMPTY_DN; return; } try { DnNode<N> rootNode = createNode( dn, element, dn.size() ); // Now copy back the created node into this this.children = rootNode.children; this.depth = rootNode.depth; this.nodeDn = rootNode.nodeDn; this.nodeElement = rootNode.nodeElement; this.nodeRdn = rootNode.nodeRdn; this.parent = null; } catch ( LdapException le ) { // Special cas e: the Dn is empty, this is not allowed throw new IllegalArgumentException( le.getMessage(), le ); } }
Example 2
Source File: DnNode.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Check that the Dn is not null * * @param dn The Dn to check * @throws LdapException If teh Dn is null or empty */ private void checkDn( Dn dn ) throws LdapException { if ( ( dn == null ) || dn.isEmpty() ) { String message = I18n.err( I18n.ERR_12000_CANNOT_PROCESS_EMPTY_DN ); LOG.error( message ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, message ); } }
Example 3
Source File: SearchRequestHandler.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Searches up the ancestry of a Dn searching for the farthest referral * ancestor. This is required to properly handle referrals. Note that * this function is quite costly since it attempts to lookup all the * ancestors up the hierarchy just to see if they represent referrals. * Techniques can be employed later to improve this performance hit by * having an intelligent referral cache. * * @return the farthest referral ancestor or null * @throws Exception if there are problems during this search */ // This will suppress PMD.EmptyCatchBlock warnings in this method @SuppressWarnings("PMD.EmptyCatchBlock") public static final Entry getFarthestReferralAncestor( LdapSession session, Dn target ) throws Exception { Entry entry; Entry farthestReferralAncestor = null; Dn dn = target; dn = dn.getParent(); while ( !dn.isEmpty() ) { if ( IS_DEBUG ) { LOG.debug( "Walking ancestors of {} to find referrals.", dn ); } try { entry = session.getCoreSession().lookup( dn ); boolean isReferral = ( ( ClonedServerEntry ) entry ).getOriginalEntry().contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.REFERRAL_OC ); if ( isReferral ) { farthestReferralAncestor = entry; } dn = dn.getParent(); } catch ( LdapException e ) { if ( IS_DEBUG ) { LOG.debug( "Entry for {} not found.", dn ); } // update the Dn as we strip last component dn = dn.getParent(); } } return farthestReferralAncestor; }
Example 4
Source File: SearchRequestHandler.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Searches up the ancestry of a Dn searching for the farthest referral * ancestor. This is required to properly handle referrals. Note that * this function is quite costly since it attempts to lookup all the * ancestors up the hierarchy just to see if they represent referrals. * Techniques can be employed later to improve this performance hit by * having an intelligent referral cache. * * @return the farthest referral ancestor or null * @throws Exception if there are problems during this search */ // This will suppress PMD.EmptyCatchBlock warnings in this method @SuppressWarnings("PMD.EmptyCatchBlock") public static final Entry getFarthestReferralAncestor( LdapSession session, Dn target ) throws Exception { Entry entry; Entry farthestReferralAncestor = null; Dn dn = target; dn = dn.getParent(); while ( !dn.isEmpty() ) { if ( IS_DEBUG ) { LOG.debug( "Walking ancestors of {} to find referrals.", dn ); } try { entry = session.getCoreSession().lookup( dn ); boolean isReferral = ( ( ClonedServerEntry ) entry ).getOriginalEntry().contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.REFERRAL_OC ); if ( isReferral ) { farthestReferralAncestor = entry; } dn = dn.getParent(); } catch ( LdapException e ) { if ( IS_DEBUG ) { LOG.debug( "Entry for {} not found.", dn ); } // update the Dn as we strip last component dn = dn.getParent(); } } return farthestReferralAncestor; }
Example 5
Source File: AuthenticationProviderService.java From guacamole-client with Apache License 2.0 | 4 votes |
/** * Returns an AuthenticatedUser representing the user authenticated by the * given credentials. Also adds custom LDAP attributes to the * AuthenticatedUser. * * @param credentials * The credentials to use for authentication. * * @return * An AuthenticatedUser representing the user authenticated by the * given credentials. * * @throws GuacamoleException * If an error occurs while authenticating the user, or if access is * denied. */ public LDAPAuthenticatedUser authenticateUser(Credentials credentials) throws GuacamoleException { String username = credentials.getUsername(); String password = credentials.getPassword(); // Username and password are required if (username == null || username.isEmpty() || password == null || password.isEmpty()) { throw new GuacamoleInvalidCredentialsException( "Anonymous bind is not currently allowed by the LDAP" + " authentication provider.", CredentialsInfo.USERNAME_PASSWORD); } Dn bindDn = getUserBindDN(username); if (bindDn == null || bindDn.isEmpty()) { throw new GuacamoleInvalidCredentialsException("Unable to determine" + " DN of user " + username, CredentialsInfo.USERNAME_PASSWORD); } // Attempt bind LdapNetworkConnection ldapConnection = ldapService.bindAs(bindDn, password); if (ldapConnection == null) throw new GuacamoleInvalidCredentialsException("Invalid login.", CredentialsInfo.USERNAME_PASSWORD); try { // Retrieve group membership of the user that just authenticated Set<String> effectiveGroups = userGroupService.getParentUserGroupIdentifiers(ldapConnection, bindDn); // Return AuthenticatedUser if bind succeeds LDAPAuthenticatedUser authenticatedUser = authenticatedUserProvider.get(); authenticatedUser.init(credentials, getAttributeTokens(ldapConnection, bindDn), effectiveGroups, bindDn); return authenticatedUser; } // Always disconnect finally { ldapConnection.close(); } }
Example 6
Source File: AuthenticationProviderService.java From guacamole-client with Apache License 2.0 | 4 votes |
/** * Returns an AuthenticatedUser representing the user authenticated by the * given credentials. Also adds custom LDAP attributes to the * AuthenticatedUser. * * @param credentials * The credentials to use for authentication. * * @return * An AuthenticatedUser representing the user authenticated by the * given credentials. * * @throws GuacamoleException * If an error occurs while authenticating the user, or if access is * denied. */ public LDAPAuthenticatedUser authenticateUser(Credentials credentials) throws GuacamoleException { String username = credentials.getUsername(); String password = credentials.getPassword(); // Username and password are required if (username == null || username.isEmpty() || password == null || password.isEmpty()) { throw new GuacamoleInvalidCredentialsException( "Anonymous bind is not currently allowed by the LDAP" + " authentication provider.", CredentialsInfo.USERNAME_PASSWORD); } Dn bindDn = getUserBindDN(username); if (bindDn == null || bindDn.isEmpty()) { throw new GuacamoleInvalidCredentialsException("Unable to determine" + " DN of user " + username, CredentialsInfo.USERNAME_PASSWORD); } // Attempt bind LdapNetworkConnection ldapConnection = ldapService.bindAs(bindDn, password); if (ldapConnection == null) throw new GuacamoleInvalidCredentialsException("Invalid login.", CredentialsInfo.USERNAME_PASSWORD); try { // Retrieve group membership of the user that just authenticated Set<String> effectiveGroups = userGroupService.getParentUserGroupIdentifiers(ldapConnection, bindDn); // Return AuthenticatedUser if bind succeeds LDAPAuthenticatedUser authenticatedUser = authenticatedUserProvider.get(); authenticatedUser.init(credentials, getAttributeTokens(ldapConnection, bindDn), effectiveGroups, bindDn); return authenticatedUser; } // Always disconnect finally { ldapConnection.close(); } }