1 /*
2 * Copyright (2005-2009) Schibsted ASA
3 * This file is part of SESAT.
4 *
5 * SESAT is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * SESAT is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
17 */
18 package no.sesat.search.user.service;
19
20 import javax.ejb.Remote;
21 import no.sesat.search.user.BasicUser;
22
23 /**
24 * Service class with user services.
25 *
26 * A thorough client example using the service is found in
27 * sesat-kernel/war/src/main/java/no/sesat/search/http/filters/UserFilter.java
28 *
29 * @version $Id: BasicUserService.java 23 2009-06-23 16:17:24Z ssmiweve $
30 *
31 */
32 @Remote
33 public interface BasicUserService {
34
35 // Constants -----------------------------------------------------
36
37 /** The separator used in login keys. */
38 static String LOGIN_KEY_SEPARATOR = "###";
39
40 // Public --------------------------------------------------------
41
42 /**
43 * Authenticates a user by the given cookie value. The authenticated user is returned,
44 * <code>null</code> if the wanted user is not found.
45 *
46 * If the token part of the cookie value is illegal, an exception is thrown to
47 * signal a cookie theft.
48 *
49 * After a successful authentication, the login cookie value is updated in the database
50 * and the new valid login cookie is injected into the user object that is returned.
51 *
52 * @param loginKey the login key to use for authentication
53 * @return the authenticated user, <code>null</code> if not found
54 * @throws InvalidTokenException thrown if an illegal token part is used (stacktrace is blanked out)
55 */
56 BasicUser authenticateByLoginKey(String loginKey) throws InvalidTokenException;
57
58 /**
59 * Authenticates a user by the given username and password. The authenticated user is returned,
60 * <code>null</code> if the wanted user is not found.
61 *
62 * After a successful authentication, a legal login cookie value is created in the database
63 * and the new valid login cookie is injected into the user object that is returned.
64 *
65 * @param username the username to use for authentication
66 * @param password the password to use for authentication
67 * @return the authenticated user, <code>null</code> if not found
68 */
69 BasicUser authenticateByLogin(String login, int type, String password);
70
71 /**
72 * Method that takes a user object and refreshes it from the database.
73 *
74 * @param user the user object to refresh
75 * @return the refreshed user
76 */
77 BasicUser refreshUser(BasicUser user);
78
79 /**
80 * Method that invalidate the given login cookie.
81 *
82 * @param loginKey the login cookie to invalidate
83 */
84 void invalidateLogin(String loginKey);
85
86 /**
87 * Method that invalidate all logins for the user belonging to the given login cookie.
88 *
89 * @param loginKey the login cookie to invalidate all user logins
90 */
91 void invalidateAllLogins(String loginKey);
92
93 /**
94 * Method that invalidate all login cookies for the given user.
95 *
96 * @param user the user to invalidate all logins for
97 */
98 void invalidateAllLogins(BasicUser user);
99
100 /**
101 * Method that deletes a user from the database.
102 *
103 * @param user the user to delete.
104 */
105 void deleteUser(BasicUser user);
106
107 /**
108 * Sets a property for the user.
109 *
110 * @param user the user to set the property to
111 * @param propertyKey the propertyKey to add
112 * @param propertyValue the propertyValue to add
113 * @return the updated user object
114 */
115 BasicUser setUserProperty(BasicUser user, String propertyKey, String propertyValue);
116
117 /**
118 * Removes a property for the given user.
119 *
120 * @param user the user to remove the property from
121 * @param propertyKey the propertyKey to remove
122 */
123 BasicUser removeUserProperty(BasicUser user, String propertyKey);
124
125 /**
126 * Returns if the given login key has correct login key syntax.
127 *
128 * @param loginKey the login key to check
129 * @return if the login key has correct syntax or not
130 */
131 boolean isLegalLoginKey(String loginKey);
132
133 }