Joaquín Reñé
2025-10-07 146a0fb8b0e90f9196e569152f649baf60d6cc8f
securis/src/main/java/net/curisit/securis/services/helpers/UserHelper.java
....@@ -1,3 +1,6 @@
1
+/*
2
+ * Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
3
+ */
14 package net.curisit.securis.services.helpers;
25
36 import jakarta.enterprise.context.ApplicationScoped;
....@@ -8,14 +11,45 @@
811 import net.curisit.securis.security.BasicSecurityContext;
912 import net.curisit.securis.services.exception.SeCurisServiceException;
1013
14
+/**
15
+ * UserHelper
16
+ * <p>
17
+ * Small helper to resolve the current user (from security context) or by username.
18
+ * Throws a typed {@link SeCurisServiceException} if the user cannot be found.
19
+ *
20
+ * Thread-safety: ApplicationScoped, stateless.
21
+ *
22
+ * @author JRA
23
+ * Last reviewed by JRA on Oct 5, 2025.
24
+ */
1125 @ApplicationScoped
1226 public class UserHelper {
1327
28
+ /**
29
+ * getUser
30
+ * <p>
31
+ * Resolve the current authenticated user from {@link BasicSecurityContext}.
32
+ *
33
+ * @param bsc Security context containing a principal.
34
+ * @param em EntityManager to fetch the user.
35
+ * @return Managed {@link User}.
36
+ * @throws SeCurisServiceException if the principal is null or not found in DB.
37
+ */
1438 public User getUser(BasicSecurityContext bsc, EntityManager em) throws SeCurisServiceException {
1539 String username = bsc.getUserPrincipal().getName();
1640 return getUser(username, em);
1741 }
1842
43
+ /**
44
+ * getUser
45
+ * <p>
46
+ * Resolve a user by username.
47
+ *
48
+ * @param username Username to look up (nullable allowed; returns null).
49
+ * @param em EntityManager to fetch the user.
50
+ * @return Managed {@link User} or null if username is null.
51
+ * @throws SeCurisServiceException if a non-null username does not exist.
52
+ */
1953 public User getUser(String username, EntityManager em) throws SeCurisServiceException {
2054 User user = null;
2155 if (username != null) {