UserManager.java
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.myproject.service;
import com.myproject.dao.UserDao;
import com.myproject.model.User;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.util.List;
/**
* Business Service Interface to handle communication between web and
* persistence layer.
*
* @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
* Modified by <a href="mailto:dan@getrolling.com">Dan Kibler </a>
*/
public interface UserManager extends GenericManager<User, Long> {
/**
* Convenience method for testing - allows you to mock the DAO and set it on an interface.
* @param userDao the UserDao implementation to use
*/
void setUserDao(UserDao userDao);
/**
* Convenience method for testing - allows you to mock the PasswordEncoder and set it on an interface.
* @param passwordEncoder the PasswordEncoder implementation to use
*/
void setPasswordEncoder(PasswordEncoder passwordEncoder);
/**
* Retrieves a user by userId. An exception is thrown if user not found
*
* @param userId the identifier for the user
* @return User
*/
User getUser(String userId);
/**
* Finds a user by their username.
* @param username the user's username used to login
* @return User a populated user object
* @throws org.springframework.security.core.userdetails.UsernameNotFoundException
* exception thrown when user not found
*/
User getUserByUsername(String username) throws UsernameNotFoundException;
/**
* Retrieves a list of all users.
* @return List
*/
List<User> getUsers();
/**
* Saves a user's information.
*
* @param user the user's information
* @throws UserExistsException thrown when user already exists
* @return user the updated user object
*/
User saveUser(User user) throws UserExistsException;
/**
* Removes a user from the database
*
* @param user the user to remove
*/
void removeUser(User user);
/**
* Removes a user from the database by their userId
*
* @param userId the user's id
*/
void removeUser(String userId);
User getUserByAuthCode(String authCode);
/**
* Search a user for search terms.
* @param searchTerm the search terms.
* @return a list of matches, or all if no searchTerm.
*/
List<User> search(String searchTerm);
/**
* Builds a recovery password url by replacing placeholders with username and generated recovery token.
*
* UrlTemplate should include two placeholders '{username}' for username and '{token}' for the recovery token.
*
* @param user
* @param urlTemplateurl
* template including two placeholders '{username}' and '{token}'
* @return
*/
String buildRecoveryPasswordUrl(User user, String urlTemplate);
/**
*
* @param user
* @return
*/
String generateRecoveryToken(User user);
/**
*
* @param username
* @param token
* @return
*/
boolean isRecoveryTokenValid(String username, String token);
/**
*
* @param user
* @param token
* @return
*/
boolean isRecoveryTokenValid(User user, String token);
/**
* Sends a password recovery email to username.
*
* @param username
* @param urlTemplate
* url template including two placeholders '{username}' and '{token}'
*/
void sendPasswordRecoveryEmail(String username, String urlTemplate);
/**
*
* @param username
* @param currentPassword
* @param recoveryToken
* @param newPassword
* @param applicationUrl
* @return
* @throws UserExistsException
*/
User updatePassword(String username, String currentPassword, String recoveryToken, String newPassword, String applicationUrl) throws UserExistsException;
boolean checkPwd(User user, String password);
User findByAuthCode(String authCode);
}