Project

General

Profile

« Previous | Next » 

Revision 49845

Added by Sofia Baltzi over 6 years ago

Check if it is zombie user's username or email

View differences:

modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/utils/LDAPActions.java
264 264

  
265 265
    }
266 266

  
267
    public boolean isZombieUsersEmail(String email) throws Exception{
268
        LDAPConnection connection = ldapConnector.getConnection();
269

  
270
        try {
271
            logger.debug("checking if zombie user " + email + " exists in ldap");
272
            Filter filter = Filter.createEqualityFilter("mail", email);
273
            SearchRequest searchRequest = new SearchRequest(ldapConnector.getZombiesDN(), SearchScope.SUB, filter, "mail");
274
            SearchResult searchResult = connection.search(searchRequest);
275

  
276
            if (!searchResult.getSearchEntries().isEmpty()) {
277
                logger.info("Zombie user with email: " + email + " exists!");
278
                return true;
279
            } else {
280
                return false;
281
            }
282
        } catch (Exception e) {
283
            logger.error("Fail to check if zombie user email exists.", e);
284
            throw e;
285
        } finally {
286
            if (connection != null)
287
                connection.close();
288
        }
289
    }
290

  
291
    public boolean isZombieUsersUsername(String username) throws Exception {
292
        LDAPConnection connection = ldapConnector.getConnection();
293

  
294
        try {
295
            logger.debug("checking if zombie user " + username + " exists in ldap");
296
            Filter filter = Filter.createEqualityFilter("uid", username);
297
            SearchRequest searchRequest = new SearchRequest(ldapConnector.getZombiesDN(), SearchScope.SUB, filter, "uid");
298
            SearchResult searchResult = connection.search(searchRequest);
299

  
300
            if (!searchResult.getSearchEntries().isEmpty()) {
301
                logger.info("Zombie user with username: " + username + " exists!");
302
                return true;
303
            } else {
304
                return false;
305
            }
306

  
307
        } catch (Exception e) {
308
            logger.error("Fail to check if zombie username exists.", e);
309
            throw e;
310
        } finally {
311
            if (connection != null)
312
                connection.close();
313
        }
314
    }
315

  
316

  
267 317
    public boolean emailExists(String email) throws Exception {
268 318
        LDAPConnection connection = ldapConnector.getConnection();
269 319

  

Also available in: Unified diff