Revision 49785
Added by Sofia Baltzi about 7 years ago
modules/uoa-user-management/trunk/src/main/java/eu/dnetlib/openaire/user/utils/LDAPActions.java | ||
---|---|---|
172 | 172 |
// } |
173 | 173 |
// } |
174 | 174 |
|
175 |
public void deleteUser(String username/*, String email */) throws Exception { |
|
176 |
LDAPConnection connection = ldapConnector.getConnection(); |
|
177 |
List<Modification> mods = new ArrayList<>(); |
|
178 |
|
|
179 |
try { |
|
180 |
|
|
181 |
//mods.add(new Modification(ModificationType.DELETE, "mail", email)); |
|
182 |
mods.add(new Modification(ModificationType.DELETE, "uid", username)); |
|
183 |
logger.info("User: " + username + "was deleted!"); |
|
184 |
if(!mods.isEmpty()) { |
|
185 |
ldapConnector.getConnection().modify(ldapConnector.getUsersDN(), mods); |
|
186 |
} |
|
187 |
|
|
188 |
} catch (Exception e) { |
|
189 |
logger.error("Fail to delete user.", e); |
|
190 |
throw e; |
|
191 |
} finally { |
|
192 |
if (connection != null) |
|
193 |
connection.close(); |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
175 | 197 |
public boolean emailExists(String email) throws Exception { |
176 | 198 |
LDAPConnection connection = ldapConnector.getConnection(); |
177 | 199 |
|
... | ... | |
181 | 203 |
SearchRequest searchRequest = new SearchRequest(ldapConnector.getUsersDN(), SearchScope.SUB, filter, "mail"); |
182 | 204 |
SearchResult searchResult = connection.search(searchRequest); |
183 | 205 |
|
184 |
if (!searchResult.getSearchEntries().isEmpty()) {
|
|
185 |
logger.info("Email: " + email + "exists!");
|
|
206 |
if (searchResult.getSearchEntries().isEmpty()) { |
|
207 |
logger.info("User with email: " + email + " exists!");
|
|
186 | 208 |
return true; |
187 | 209 |
} else { |
188 | 210 |
return false; |
... | ... | |
205 | 227 |
SearchRequest searchRequest = new SearchRequest(ldapConnector.getUsersDN(), SearchScope.SUB, filter, "uid"); |
206 | 228 |
SearchResult searchResult = connection.search(searchRequest); |
207 | 229 |
|
208 |
if (!searchResult.getSearchEntries().isEmpty()) {
|
|
209 |
logger.info("Username: " + username + "exists!");
|
|
230 |
if (searchResult.getSearchEntries().isEmpty()) { |
|
231 |
logger.info("User with username: " + username + " exists!");
|
|
210 | 232 |
return true; |
211 | 233 |
} else { |
212 | 234 |
return false; |
Also available in: Unified diff
Fix errors in emailExists and UsernameExists