|
3 | 3 | import io.jans.as.server.service.AuthenticationService; |
4 | 4 | import io.jans.service.cdi.util.CdiUtil; |
5 | 5 | import io.jans.service.custom.script.CustomScriptManager; |
| 6 | +import io.jans.as.common.model.common.User; |
| 7 | +import io.jans.as.common.service.common.UserService; |
6 | 8 | import org.slf4j.Logger; |
7 | 9 | import org.slf4j.LoggerFactory; |
8 | 10 |
|
9 | 11 | public class BasicAuthentication { |
10 | 12 |
|
11 | | - private static final Logger scriptLogger = LoggerFactory.getLogger(CustomScriptManager.java.class); |
| 13 | + private static final Logger scriptLogger = LoggerFactory.getLogger(CustomScriptManager.class); |
12 | 14 | private static AuthenticationService authenticationService = CdiUtil.bean(AuthenticationService.class); |
| 15 | + private static UserService userService = CdiUtil.bean(UserService.class); |
13 | 16 |
|
14 | 17 | public static boolean authenticate(String username, String password) { |
15 | | - System.out.println("Looooooooooooooooooogs!"); |
16 | | - scriptLogger.info("Passclub BasicAuthentication. authenticating with user: " + username); |
17 | | - return authenticationService.authenticate("idm", password); |
18 | 18 |
|
| 19 | + User user = userService.getUserByAttribute("uid", username); |
| 20 | + if (user == null) { |
| 21 | + scriptLogger.info("Passclub BasicAuthentication. User not found for username: " + username + "creating it..."); |
| 22 | + user = new User(); |
| 23 | + user.setAttribute("uid", username); |
| 24 | + user.setAttribute("userPassword", password); |
| 25 | + user = userService.addUser(user, true); |
| 26 | + } |
| 27 | + scriptLogger.info("Passclub BasicAuthentication. User added for username: " + username + "password: " + password); |
| 28 | + boolean isAuthenticated = authenticationService.authenticate(username, password); |
| 29 | + scriptLogger.info("Passclub BasicAuthentication. is authenticated: " + isAuthenticated); |
| 30 | + |
| 31 | + return isAuthenticated; |
19 | 32 | } |
20 | 33 |
|
21 | 34 | public static void testNoArg() { |
22 | | - System.out.println("Looooooooooooooooooogs!"); |
| 35 | + |
23 | 36 | scriptLogger.info("Passclub BasicAuthentication. Called with no arguments"); |
24 | 37 |
|
25 | 38 | } |
|
0 commit comments