@Override public boolean passivate(final Connection c) { boolean success = false; if (c != null) { c.close(); success = true; } return success; } }
@Override public boolean passivate(final Connection c) { boolean success = false; if (c != null) { c.close(); success = true; } return success; } }
@Override public boolean passivate(final Connection c) { boolean success = false; if (c != null) { c.close(); success = true; } return success; } }
private void closeConnection(final Connection context) { if (context != null && context.isOpen()) { try { context.close(); } catch (final Exception ex) { logger.warn("Could not close ldap connection", ex); } } } }
private void closeConnection(final Connection context) { if (context != null && context.isOpen()) { try { context.close(); } catch (final Exception ex) { logger.warn("Could not close ldap connection", ex); } } } }
/** * Remove a connection from the available pool. * * @param pc connection that is in the available pool */ protected void removeAvailableConnection(final PooledConnectionProxy pc) { boolean destroy = false; poolLock.lock(); try { if (available.remove(pc)) { destroy = true; } else { logger.warn("attempt to remove unknown available connection: {}", pc); } } finally { poolLock.unlock(); } if (destroy) { pc.getConnection().close(); logger.info("destroyed connection: {}", pc); } }
@Override public Response<S> call() throws LdapException { try { conn.open(); return operation.execute(request); } finally { conn.close(); } } };
@Override public Response<S> call() throws LdapException { try { conn.open(); return operation.execute(request); } finally { conn.close(); } } };
@Override public Collection<Response<S>> call() throws LdapException { try { conn.open(); return worker.executeToCompletion(requests); } finally { conn.close(); } } };
@Override public AuthenticationHandlerResponse authenticate(final AuthenticationCriteria ac) throws LdapException { logger.debug("authenticate criteria={}", ac); AuthenticationHandlerResponse response = null; final Connection conn = getConnection(); boolean closeConn = false; try { response = authenticateInternal(conn, ac); } catch (LdapException | RuntimeException e) { closeConn = true; throw e; } finally { if (closeConn) { conn.close(); } } logger.debug("authenticate response={} for criteria={}", response, ac); return response; }
/** * Executes a {@link DeleteOperation} on the supplied DN. * * @param dn to delete * * @return response for the delete operation * * @throws LdapException if the operation fails */ @Nonnull private Response<Void> delete(@Nonnull final String dn) throws LdapException { Connection conn = null; try { conn = connectionFactory.getConnection(); final DeleteOperation delete = new DeleteOperation(conn); return delete.execute(new DeleteRequest(dn)); } finally { conn.close(); } }
/** * Executes a {@link MergeOperation} with the supplied entry. * * @param entry to merge * * @return response for the merge operation * * @throws LdapException if the operation fails */ @Nonnull private Response<Void> merge(@Nonnull final LdapEntry entry) throws LdapException { Connection conn = null; try { conn = connectionFactory.getConnection(); final MergeOperation merge = new MergeOperation(conn); final MergeRequest request = new MergeRequest(entry); request.setIncludeAttributes(entry.getAttributeNames()); return merge.execute(request); } finally { conn.close(); } }
@Override protected void update(final Map<String, Object> attributes) { Connection connection = null; try { connection = connectionFactory.getConnection(); connection.open(); final ModifyOperation modify = new ModifyOperation(connection); final ModifyRequest modifyRequest = new ModifyRequest(getEntryId(attributes)); final List<AttributeModification> modifications = new ArrayList<>(); for (final LdapAttribute attribute : getLdapAttributes(attributes)) { modifications.add(new AttributeModification(AttributeModificationType.REPLACE, attribute)); } modifyRequest.setAttributeModifications(modifications.toArray(new AttributeModification[modifications.size()])); modify.execute(modifyRequest); } catch (final LdapException e) { throw new TechnicalException(e); } finally { if (connection != null) { connection.close(); } } }
/** * Executes a {@link ModifyOperation} on the supplied DN, removing the supplied attribute. * * @param dn to modify * @param attrName to remove * * @return response for the modify operation * * @throws LdapException if the operation fails */ @Nonnull private Response<Void> deleteAttribute(@Nonnull final String dn, @Nonnull final String attrName) throws LdapException { Connection conn = null; try { conn = connectionFactory.getConnection(); final ModifyOperation modify = new ModifyOperation(conn); return modify.execute(new ModifyRequest(dn, new AttributeModification(AttributeModificationType.REMOVE, new LdapAttribute(attrName)))); } finally { conn.close(); } }
@Override public Set<LdapRole> search(final SearchRequest request) throws LdapException { Connection conn = null; try { conn = getConnection(); final SearchOperation op = createSearchOperation(conn); return LdapRole.toRoles(op.execute(request).getResult()); } finally { if (conn != null) { conn.close(); } } }
@Override public Set<LdapRole> search(final SearchRequest request) throws LdapException { Connection conn = null; try { conn = getConnection(); final SearchOperation op = createSearchOperation(conn); return LdapRole.toRoles(op.execute(request).getResult()); } finally { if (conn != null) { conn.close(); } } }
@Override public Set<LdapRole> search(final SearchRequest request) throws LdapException { Connection conn = null; try { conn = getConnection(); final SearchOperation op = createSearchOperation(conn); return LdapRole.toRoles(op.execute(request).getResult()); } finally { if (conn != null) { conn.close(); } } }
/** * Executes the ldap compare operation. * * @param cf connection factory * @param dn to compare attribute on * @param attr attribute to compare * * @return status code * * @throws Exception on any LDAP search error */ protected int compare(final ConnectionFactory cf, final String dn, final LdapAttribute attr) throws Exception { final Connection conn = cf.getConnection(); conn.open(); final CompareOperation op = new CompareOperation(conn); final Response<Boolean> response = op.execute(new CompareRequest(dn, attr)); System.out.println(response.getResult()); conn.close(); return response.getResultCode().value(); }
@Override protected void deleteById(final String id) { Connection connection = null; try { connection = connectionFactory.getConnection(); connection.open(); final DeleteOperation delete = new DeleteOperation(connection); delete.execute(new DeleteRequest(getIdAttribute() + "=" + id + "," + usersDn)); } catch (final LdapException e) { throw new TechnicalException(e); } finally { if (connection != null) { connection.close(); } } }
@Override protected void insert(final Map<String, Object> attributes) { attributes.put("objectClass", "person"); final LdapEntry ldapEntry = new LdapEntry(getEntryId(attributes)); ldapEntry.addAttributes(getLdapAttributes(attributes)); Connection connection = null; try { connection = connectionFactory.getConnection(); connection.open(); final AddOperation add = new AddOperation(connection); add.execute(new AddRequest(ldapEntry.getDn(), ldapEntry.getAttributes())); } catch (final LdapException e) { throw new TechnicalException(e); } finally { if (connection != null) { connection.close(); } } }