View Javadoc

1   /*
2    * Copyright (c) 2004 UNINETT FAS
3    *
4    * This program is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU General Public License as published by the Free
6    * Software Foundation; either version 2 of the License, or (at your option)
7    * any later version.
8    *
9    * This program is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12   * more details.
13   *
14   * You should have received a copy of the GNU General Public License along with
15   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16   * Place - Suite 330, Boston, MA 02111-1307, USA.
17   *
18   */
19  
20  package no.feide.moria.directory.backend;
21  
22  import java.util.HashMap;
23  
24  import no.feide.moria.directory.Credentials;
25  import no.feide.moria.directory.index.IndexedReference;
26  
27  /***
28   *
29   */
30  public interface DirectoryManagerBackend {
31  
32      /***
33       * The character set used when encoding attribute values.<br>
34       * <br>
35       * Current value is <code>"ISO-8859-1"</code>.
36       */
37      public static final String ATTRIBUTE_VALUE_CHARSET = "ISO-8859-1";
38  
39      /***
40       * The list of "virtual" attributes, that is, attributes that are generated
41       * by Moria itself, and not read from any physical attribute through the
42       * backend.<br>
43       * <br>
44       * Current value is <code>{"tgt"}</code>.
45       */
46      // TODO: Use the identical constant value from MoriaController instead?
47      public static final String[] VIRTUAL_ATTRIBUTES = {"tgt"};
48  
49  
50      /***
51       * Opens a new backend connection.
52       * @param references
53       *            The backend references in question. Cannot be
54       *            <code>null</code>, and must contain at least one reference.
55       */
56      void open(IndexedReference[] references);
57  
58  
59      /***
60       * Checks whether a given user actually exists.
61       * @param username
62       *            The username to check for.
63       * @return <code>true</code> if we can find a user element with the given
64       *         username, otherwise <code>false</code>.
65       * @throws BackendException
66       *             If there was a problem accessing the backend.
67       */
68      boolean userExists(final String username) throws BackendException;
69  
70  
71      /***
72       * Attempts to authenticate a user and retrieve a set of user attributes.
73       * @param userCredentials
74       *            The user's credentials. Cannot be <code>null</code>.
75       * @param attributeRequest
76       *            A list of requested attributes from the user object. May be
77       *            <code>null</code> or an empty array. Not case sensitive.
78       * @return The requested user attributes, if any are requested and if they
79       *         can be retrieved from the backend following a successful
80       *         authentication. Otherwise, an empty <code>HashMap</code>.
81       *         Attribute values should be encoded using ISO-8859-1.
82       * @throws AuthenticationFailedException
83       *             If the authentication fails.
84       * @throws BackendException
85       *             If there was a problem accessing the backend.
86       */
87      HashMap authenticate(final Credentials userCredentials,
88                           final String[] attributeRequest) throws AuthenticationFailedException,
89                                                           BackendException;
90  
91  
92      /***
93       * Closes the current backend and releases any resources.
94       */
95      void close();
96  
97  }