Examples of LDAPConnection


Examples of com.google.enterprise.connector.sharepoint.ldap.UserGroupsService.LdapConnection

   */
  @VisibleForTesting
  public UserGroupsService(LdapConnectionSettings ldapConnectionSettings,
      int cacheSize, long refreshInterval, boolean enableLUGCache) {
    this.ldapConnectionSettings = ldapConnectionSettings;
    ldapConnection = new LdapConnection(ldapConnectionSettings);
    this.sharepointClientContext = null;
    if (enableLUGCache) {
      this.lugCacheStore = new UserGroupsCache<Object,
          ConcurrentHashMap<String, Set<Principal>>>(
              refreshInterval, cacheSize);
View Full Code Here

Examples of com.novell.ldap.LDAPConnection

    String sService = sConnStr.substring(0, sConnStr.indexOf('/'));
    String[] aService = Gadgets.split2(sService, ':');

    try {
      oConn = new LDAPConnection();
      if (aService.length<2)
        oConn.connect(aService[0].trim(), 389);
      else
        oConn.connect(aService[0].trim(), Integer.parseInt(aService[1]));
      setPartitionName(sConnStr.substring(sConnStr.indexOf('/')+1));
View Full Code Here

Examples of com.novell.ldap.LDAPConnection

            logger.debug("Anonymous bind is not currently allowed by the LDAP authentication provider.");
            return null;
        }

        // Connect to LDAP server
        LDAPConnection ldapConnection;
        try {

            ldapConnection = new LDAPConnection();
            ldapConnection.connect(
                    GuacamoleProperties.getRequiredProperty(LDAPGuacamoleProperties.LDAP_HOSTNAME),
                    GuacamoleProperties.getRequiredProperty(LDAPGuacamoleProperties.LDAP_PORT)
            );

        }
        catch (LDAPException e) {
            throw new GuacamoleServerException("Unable to connect to LDAP server.", e);
        }

        // Get username attribute
        String username_attribute = GuacamoleProperties.getRequiredProperty(
            LDAPGuacamoleProperties.LDAP_USERNAME_ATTRIBUTE
        );

        // Get user base DN
        String user_base_dn = GuacamoleProperties.getRequiredProperty(
                LDAPGuacamoleProperties.LDAP_USER_BASE_DN
        );

        // Construct user DN
        String user_dn =
            escapeDN(username_attribute) + "=" + escapeDN(credentials.getUsername())
            + "," + user_base_dn;

        try {

            // Bind as user
            try {
                ldapConnection.bind(
                        LDAPConnection.LDAP_V3,
                        user_dn,
                        credentials.getPassword().getBytes("UTF-8")
                );
            }
            catch (UnsupportedEncodingException e) {
                throw new GuacamoleException(e);
            }

        }
        catch (LDAPException e) {
            logger.debug("LDAP bind failed.", e);
            return null;
        }

        // Get config base DN
        String config_base_dn = GuacamoleProperties.getRequiredProperty(
                LDAPGuacamoleProperties.LDAP_CONFIG_BASE_DN
        );

        // Pull all connections
        try {

            // Find all guac configs for this user
            LDAPSearchResults results = ldapConnection.search(
                    config_base_dn,
                    LDAPConnection.SCOPE_SUB,
                    "(&(objectClass=guacConfigGroup)(member=" + escapeLDAPSearchFilter(user_dn) + "))",
                    null,
                    false
            );

            // Add all configs
            Map<String, GuacamoleConfiguration> configs = new TreeMap<String, GuacamoleConfiguration>();
            while (results.hasMore()) {

                LDAPEntry entry = results.next();

                // New empty configuration
                GuacamoleConfiguration config = new GuacamoleConfiguration();

                // Get CN
                LDAPAttribute cn = entry.getAttribute("cn");
                if (cn == null)
                    throw new GuacamoleException("guacConfigGroup without cn");

                // Get protocol
                LDAPAttribute protocol = entry.getAttribute("guacConfigProtocol");
                if (protocol == null)
                    throw new GuacamoleException("guacConfigGroup without guacConfigProtocol");

                // Set protocol
                config.setProtocol(protocol.getStringValue());

                // Get parameters, if any
                LDAPAttribute parameterAttribute = entry.getAttribute("guacConfigParameter");
                if (parameterAttribute != null) {

                    // For each parameter
                    Enumeration<String> parameters = parameterAttribute.getStringValues();
                    while (parameters.hasMoreElements()) {

                        String parameter = parameters.nextElement();

                        // Parse parameter
                        int equals = parameter.indexOf('=');
                        if (equals != -1) {

                            // Parse name
                            String name = parameter.substring(0, equals);
                            String value = parameter.substring(equals+1);

                            config.setParameter(name, value);

                        }

                    }

                }

                // Store config by CN
                configs.put(cn.getStringValue(), config);

            }

            // Disconnect
            ldapConnection.disconnect();
            return configs;

        }
        catch (LDAPException e) {
            throw new GuacamoleServerException("Error while querying for connections.", e);
View Full Code Here

Examples of com.unboundid.ldap.sdk.LDAPConnection

  public synchronized void sync() {
    final boolean enabled = settings.getBoolean(Keys.realm.ldap.synchronize, false);
    if (enabled) {
      logger.info("Synchronizing with LDAP @ " + settings.getRequiredString(Keys.realm.ldap.server));
      final boolean deleteRemovedLdapUsers = settings.getBoolean(Keys.realm.ldap.removeDeletedUsers, true);
      LDAPConnection ldapConnection = getLdapConnection();
      if (ldapConnection != null) {
        try {
          String accountBase = settings.getString(Keys.realm.ldap.accountBase, "");
          String uidAttribute = settings.getString(Keys.realm.ldap.uid, "uid");
          String accountPattern = settings.getString(Keys.realm.ldap.accountPattern, "(&(objectClass=person)(sAMAccountName=${username}))");
          accountPattern = StringUtils.replace(accountPattern, "${username}", "*");

          SearchResult result = doSearch(ldapConnection, accountBase, accountPattern);
          if (result != null && result.getEntryCount() > 0) {
            final Map<String, UserModel> ldapUsers = new HashMap<String, UserModel>();

            for (SearchResultEntry loggingInUser : result.getSearchEntries()) {
              Attribute uid = loggingInUser.getAttribute(uidAttribute);
              if (uid == null) {
                logger.error("Can not synchronize with LDAP, missing \"{}\" attribute", uidAttribute);
                continue;
              }
              final String username = uid.getValue();
              logger.debug("LDAP synchronizing: " + username);

              UserModel user = userManager.getUserModel(username);
              if (user == null) {
                user = new UserModel(username);
              }

              if (!supportsTeamMembershipChanges()) {
                getTeamsFromLdap(ldapConnection, username, loggingInUser, user);
              }

              // Get User Attributes
              setUserAttributes(user, loggingInUser);

              // store in map
              ldapUsers.put(username.toLowerCase(), user);
            }

            if (deleteRemovedLdapUsers) {
              logger.debug("detecting removed LDAP users...");

              for (UserModel userModel : userManager.getAllUsers()) {
                if (AccountType.LDAP == userModel.accountType) {
                  if (!ldapUsers.containsKey(userModel.username)) {
                    logger.info("deleting removed LDAP user " + userModel.username + " from user service");
                    userManager.deleteUser(userModel.username);
                  }
                }
              }
            }

            userManager.updateUserModels(ldapUsers.values());

            if (!supportsTeamMembershipChanges()) {
              final Map<String, TeamModel> userTeams = new HashMap<String, TeamModel>();
              for (UserModel user : ldapUsers.values()) {
                for (TeamModel userTeam : user.teams) {
                  userTeams.put(userTeam.name, userTeam);
                }
              }
              userManager.updateTeamModels(userTeams.values());
            }
          }
          if (!supportsTeamMembershipChanges()) {
            getEmptyTeamsFromLdap(ldapConnection);
          }
        } finally {
          ldapConnection.close();
        }
      }
    }
  }
View Full Code Here

Examples of netscape.ldap.LDAPConnection

    // filter darf nicht "" sein sondern null
    if(filter != null && filter.length() == 0) filter = null;
    this._filter    = filter;
   
   
    connection         = new LDAPConnection();
   
  }
View Full Code Here

Examples of org.apache.archiva.redback.common.ldap.connection.LdapConnection

    @Override
    public Boolean checkLdapConnection()
        throws ArchivaRestServiceException
    {
        LdapConnection ldapConnection = null;
        try
        {
            ldapConnection = ldapConnectionFactory.getConnection();
        }
        catch ( LdapException e )
        {
            log.warn( "fail to get ldapConnection: {}", e.getMessage(), e );
            throw new ArchivaRestServiceException( e.getMessage(), e );
        }
        finally
        {

            if ( ldapConnection != null )
            {
                ldapConnection.close();
            }
        }

        return Boolean.TRUE;
    }
View Full Code Here

Examples of org.apache.directory.ldap.client.api.LdapConnection

     * @throws LDAPException if we fail to connect and add entries
     */
    @Test
    public void testAddEntryWithTwoDescriptions() throws Exception
    {
        LdapConnection con = getAdminConnection( getLdapServer() );

        String dn = "cn=Kate Bush," + BASE;
        Entry kate = new DefaultEntry( dn );

        kate.add( "objectclass", "top", "person" );
        kate.add( "sn", "Bush" );
        kate.add( "cn", "Kate Bush" );

        String descr[] =
            { "a British singer-songwriter with an expressive four-octave voice",
                "one of the most influential female artists of the twentieth century" };

        kate.add( "description", descr );

        con.add( kate );

        // Analyze entry and description attribute
        Entry kateReloaded = con.lookup( dn );
        assertNotNull( kateReloaded );
        Attribute attr = kateReloaded.get( "description" );
        assertNotNull( attr );
        assertEquals( 2, attr.size() );

        // Remove entry
        con.delete( dn );
        con.unBind();
    }
View Full Code Here

Examples of org.apache.directory.ldap.client.api.LdapConnection

     * @throws LDAPException if we fail to connect and add entries
     */
    @Test
    public void testAddEntryWithTwoDescriptionsVariant() throws Exception
    {
        LdapConnection con = getAdminConnection( getLdapServer() );

        String dn = "cn=Kate Bush," + BASE;
        Entry kate = new DefaultEntry( dn );
        kate.add( "objectclass", "top", "person" );
        kate.add( "sn", "Bush" );
        kate.add( "cn", "Kate Bush" );

        String descr[] =
            { "a British singer-songwriter with an expressive four-octave voice",
                "one of the most influential female artists of the twentieth century" };

        kate.add( "description", descr[0] );
        kate.add( "description", descr[1] );

        con.add( kate );

        // Analyze entry and description attribute
        Entry kateReloaded = con.lookup( dn );
        assertNotNull( kateReloaded );
        Attribute attr = kateReloaded.get( "description" );
        assertNotNull( attr );
        assertEquals( 2, attr.size() );

        // Remove entry
        con.delete( dn );
        con.unBind();
    }
View Full Code Here

Examples of org.apache.directory.ldap.client.api.LdapConnection

     * @throws LDAPException if we fail to connect and add entries
     */
    @Test
    public void testAddEntryWithTwoDescriptionsSecondVariant() throws Exception
    {
        LdapConnection con = getAdminConnection( getLdapServer() );

        String dn = "cn=Kate Bush," + BASE;
        Entry kate = new DefaultEntry( dn );

        kate.add( "objectclass", "top", "person" );
        kate.add( "sn", "Bush" );

        String descr[] =
            { "a British singer-songwriter with an expressive four-octave voice",
                "one of the most influential female artists of the twentieth century" };

        kate.add( "description", descr[0] );
        kate.add( "cn", "Kate Bush" );
        kate.add( "description", descr[1] );

        con.add( kate );

        // Analyze entry and description attribute
        Entry kateReloaded = con.lookup( dn );
        assertNotNull( kateReloaded );
        Attribute attr = kateReloaded.get( "description" );
        assertNotNull( attr );
        assertEquals( 2, attr.size() );

        // Remove entry
        con.delete( dn );
        con.unBind();
    }
View Full Code Here

Examples of org.apache.directory.ldap.client.api.LdapConnection

    @Test
    public void testAddPDUExceedingMaxSizeLdapApi() throws Exception
    {
        // Limit the PDU size to 1024
        getLdapServer().getDirectoryService().setMaxPDUSize( 1024 );
        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
        connection.bind( "uid=admin,ou=system", "secret" );

        // Inject a 1024 bytes long description
        StringBuilder sb = new StringBuilder();

        for ( int i = 0; i < 128; i++ )
        {
            sb.append( "0123456789ABCDEF" );
        }

        Attribute description = new DefaultAttribute( "description", sb.toString() );

        try
        {
            Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, description );
            connection.modify( "cn=the person, ou=system", modification );
            fail();
        }
        catch ( Exception e )
        {
            // We are expecting the session to be close here.
            if ( connection.isConnected() )
            {
                // Race condition:
                // Upon NoticeOfDisconnection the API sends an abandon request but does not immediately close the connection.
                // So at this point it is not guaranteed that the connnection is already closed.
                // TODO: This is just a workaround, better check the connection for any outstanding abandon requests
                Thread.sleep( 1000 );
            }
            assertFalse( connection.isConnected() );
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.