1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. 22 */ 23 package opengrok.auth.plugin.ldap; 24 25 import java.util.Map; 26 import java.util.Set; 27 28 public abstract class AbstractLdapProvider { 29 30 /** 31 * Encapsulates the result of LDAP search, namely single object's 32 * DN and attributes. 33 */ 34 public static class LdapSearchResult<T> { 35 private final String dn; 36 private final T attrs; 37 LdapSearchResult(String dn, T attrs)38 public LdapSearchResult(String dn, T attrs) { 39 this.dn = dn; 40 this.attrs = attrs; 41 } 42 getDN()43 public String getDN() { 44 return dn; 45 } 46 getAttrs()47 public T getAttrs() { 48 return attrs; 49 } 50 } 51 52 /** 53 * Perform LDAP lookup. 54 * 55 * @param dn LDAP DN 56 * @return set of attributes for the user or null 57 * @throws LdapException LDAP exception 58 * 59 * @see #lookupLdapContent(java.lang.String, java.lang.String) 60 */ lookupLdapContent(String dn)61 public LdapSearchResult<Map<String, Set<String>>> lookupLdapContent(String dn) throws LdapException { 62 return lookupLdapContent(dn, (String) null); 63 } 64 65 /** 66 * Perform LDAP lookup. 67 * 68 * @param dn LDAP DN 69 * @param filter the LDAP filter 70 * @return set of attributes for the user or null 71 * @throws LdapException LDAP exception 72 * 73 * @see #lookupLdapContent(java.lang.String, java.lang.String, java.lang.String[]) 74 */ lookupLdapContent(String dn, String filter)75 public LdapSearchResult<Map<String, Set<String>>> lookupLdapContent(String dn, String filter) throws LdapException { 76 return lookupLdapContent(dn, filter, null); 77 } 78 79 /** 80 * Perform LDAP lookup. 81 * 82 * @param dn LDAP DN 83 * @param values match these LDAP value 84 * @return set of attributes for the user or null 85 * @throws LdapException LDAP exception 86 * 87 * @see #lookupLdapContent(java.lang.String, java.lang.String, java.lang.String[]) 88 */ lookupLdapContent(String dn, String[] values)89 public LdapSearchResult<Map<String, Set<String>>> lookupLdapContent(String dn, String[] values) throws LdapException { 90 return lookupLdapContent(dn, null, values); 91 } 92 93 /** 94 * Perform LDAP lookup. 95 * 96 * @param dn LDAP DN 97 * @param filter the LDAP filter 98 * @param values match these LDAP value 99 * @return set of attributes for the user or null 100 * @throws LdapException LDAP exception 101 */ lookupLdapContent(String dn, String filter, String[] values)102 public abstract LdapSearchResult<Map<String, Set<String>>> lookupLdapContent(String dn, String filter, String[] values) throws LdapException; 103 104 /** 105 * @return if the provider is correctly configured 106 */ isConfigured()107 public abstract boolean isConfigured(); 108 109 /** 110 * Closes the LDAP provider. 111 */ close()112 public abstract void close(); 113 } 114