001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.core.user.directory; 017 018import java.util.Collection; 019import java.util.List; 020import java.util.Map; 021 022import org.ametys.core.user.User; 023 024/** 025 * Abstraction for getting users list and verify the presence of a particular user. 026 */ 027public interface UserDirectory 028{ 029 /** 030 * Enum for user credentials 031 */ 032 public enum CredentialsResult 033 { 034 /** The credentials are OK, user is authenticated */ 035 AUTHENTICATED, 036 /** The credentials are wrong, user cannot be authenticated */ 037 NOT_AUTHENTICATED, 038 /** When credentials are OK but user has a weak password */ 039 WEAK_PASSWORD 040 } 041 042 /** 043 * A unique identifier 044 * @return The non-null and non-empty identifier 045 */ 046 public String getId(); 047 048 /** 049 * Get the label of the CredentialProvider 050 * @return The optionnal label 051 */ 052 public String getLabel(); 053 054 /** 055 * Get the list of all users of one directory. 056 * @return list of users as Collection of <code>User</code>s, empty if a problem occurs. 057 */ 058 public Collection<User> getUsers(); 059 060 /** 061 * Get a list of users from a directory given the parameters 062 * @param count The limit of users to retrieve 063 * @param offset The number of result to ignore before starting to collect users. 064 * @param parameters A map of additional parameters, see implementation. 065 * @return The list of retrieved {@link User} 066 */ 067 public List<User> getUsers(int count, int offset, Map<String, Object> parameters); 068 069 /** 070 * Get a particular user by his login. 071 * @param login Login of the user to get. Cannot be null. 072 * @return User's information as a <code>User</code> instance or null if the user login does not exist. 073 */ 074 public User getUser(String login); 075 076 /** 077 * Get a particular user by his email (search should be case insensitive). 078 * @param email Email of the user to get. Cannot be null. 079 * @return User's information as a <code>User</code> instance or null if the user email does not exist. 080 * @throws NotUniqueUserException If many users match this email 081 */ 082 public User getUserByEmail(String email) throws NotUniqueUserException; 083 084 /** 085 * Get the id of the {@link UserDirectoryModel} extension point 086 * @return the id of extension point 087 */ 088 public String getUserDirectoryModelId(); 089 090 /** 091 * Get the values of parameters (from user directory model) 092 * @return the parameters' values 093 */ 094 public Map<String, Object> getParameterValues(); 095 096 /** 097 * Initialize the user's directory with given parameters' values. 098 * @param id The non-null and non-empty unique identifier 099 * @param udModelId The id of user directory extension point 100 * @param paramValues The parameters' values 101 * @param label The optional label 102 * @throws Exception If an error occurred 103 */ 104 public void init(String id, String udModelId, Map<String, Object> paramValues, String label) throws Exception; 105 106 /** 107 * Set the value of the id of the population this user directory belong to. 108 * @param populationId The id of the population the user directory belongs to. 109 */ 110 public void setPopulationId(String populationId); 111 112 /** 113 * Get the id of the population this user directory belongs to. 114 * @return The id of the population 115 */ 116 public String getPopulationId(); 117 118 /** 119 * Authenticate a user with its credentials 120 * @param login The login to check. Cannot be null. 121 * @param password The password to check. 122 * @return The credentials result 123 */ 124 public CredentialsResult checkCredentials(String login, String password); 125 126 /** 127 * Is the user directory case sensitive for login? 128 * @return true is the user directory is case sensitive 129 */ 130 public default boolean isCaseSensitive() 131 { 132 return true; 133 } 134}