View Javadoc

1   /*
2    * Copyright (C) 2017-2019 Centre National d'Etudes Spatiales (CNES).
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 3.0 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not, write to the Free Software
16   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17   * MA 02110-1301  USA
18   */
19  package fr.cnes.doi.db;
20  
21  import fr.cnes.doi.db.model.DOIUser;
22  import java.util.List;
23  
24  import fr.cnes.doi.exception.DOIDbException;
25  import fr.cnes.doi.utils.spec.Requirement;
26  
27  /**
28   * Interface for handling users and role database. This database is used to
29   * authenticate the requests.
30   *
31   * @author Jean-Christophe Malapert (jean-christophe.malapert@cnes.fr)
32   */
33  @Requirement(reqId = Requirement.DOI_INTER_050, reqName = Requirement.DOI_INTER_050_NAME)
34  public abstract class AbstractUserRoleDBHelper {
35  
36      /**
37       * Notification message when an user is added
38       * {@value #ADD_USER_NOTIFICATION}.
39       */
40      public static final String ADD_USER_NOTIFICATION = "AddUserNotification";
41  
42      /**
43       * Notification message when an user is deleted
44       * {@value #REMOVE_USER_NOTIFICATION}.
45       */
46      public static final String REMOVE_USER_NOTIFICATION = "RemoveUserNotification";
47  
48      /**
49       * Realm.
50       */
51      private static final MyMemoryRealm REALM = new MyMemoryRealm();
52  
53      /**
54       * Returns the realm.
55       *
56       * @return the realm
57       */
58      public MyMemoryRealm getRealm() {
59          return REALM;
60      }
61  
62      /**
63       * Returns the allowed users for authentication.
64       *
65       * @return List of users to add for the authentication
66       * @throws fr.cnes.doi.exception.DOIDbException When an error occurs
67       */
68      public abstract List<DOIUser> getUsers() throws DOIDbException;
69  
70      /**
71       * Get users from a specific role.
72       *
73       * @param roleName role name
74       * @return The users related to a specific role
75       * @throws fr.cnes.doi.exception.DOIDbException When an error occurs
76       */
77      public abstract List<DOIUser> getUsersFromRole(final int roleName) throws DOIDbException;
78  
79      /**
80       * Adds an user to a specific role.
81       *
82       * @param user user to add
83       * @param role role
84       * @return True when the user is added otherwise False
85       */
86      public abstract boolean addUserToRole(final String user, final int role);
87  
88      /**
89       * Removes an user from a specific role.
90       *
91       * @param user user to remove
92       * @param role role
93       * @return True when the user is removed otherwise False
94       */
95      public abstract boolean removeUserToRole(final String user, final int role);
96  
97      /**
98       * Add user to Administrators group
99       *
100      * @param admin user to add
101      * @return True when the user is added in the admin group otherwise False
102      */
103     public abstract boolean setUserToAdminGroup(final String admin);
104 
105     /**
106      * Remove user to Administrators group
107      *
108      * @param admin user to add
109      * @return True when the user is removed from the admin group otherwise
110      * False
111      */
112     public abstract boolean unsetUserFromAdminGroup(final String admin);
113 
114     /**
115      * Add a DOI user
116      *
117      * @param username username
118      * @param admin True when the user must be added in the admin group
119      * otherwise False
120      * @return True when the user is added otherwise False
121      */
122     public abstract boolean addDOIUser(final String username, final Boolean admin);
123 
124     /**
125      * Add a DOI user
126      *
127      * @param username username
128      * @param admin True when the user must be added in the admin group
129      * otherwise False
130      * @param email email
131      * @return True when the the user is added otherwise false
132      */
133     public abstract boolean addDOIUser(final String username, final Boolean admin,
134             final String email);
135 
136     /**
137      * Tests if the user exists.
138      *
139      * @param username the user
140      * @return True when the user exists otherwise False
141      */
142     public abstract boolean isUserExist(final String username);
143 
144     /**
145      * Removes the user
146      *
147      * @param username user
148      * @return True when the user is removed otherwise false
149      */
150     public abstract boolean removeDOIUser(final String username);
151 
152 }