dashboard
repositories
activity
search
login
common
/
securis
summary
reflog
commits
tree
compare
forks
blame
|
history
|
raw
|
HEAD
#4389 - Fix deprecated on FileUtils
Joaquín Reñé
2025-02-09
ef9b2d9b15a7f57c87f8e621d4e1d1818beb46b9
[common/securis.git]
/
securis
/
src
/
main
/
java
/
net
/
curisit
/
securis
/
services
/
helpers
/
UserHelper.java
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
package net.curisit.securis.services.helpers;
import javax.enterprise.context.ApplicationScoped;
import javax.persistence.EntityManager;
import javax.ws.rs.core.Response.Status;
import net.curisit.securis.db.User;
import net.curisit.securis.security.BasicSecurityContext;
import net.curisit.securis.services.exception.SeCurisServiceException;
@ApplicationScoped
public class UserHelper {
public User getUser(BasicSecurityContext bsc, EntityManager em) throws SeCurisServiceException {
String username = bsc.getUserPrincipal().getName();
return getUser(username, em);
}
public User getUser(String username, EntityManager em) throws SeCurisServiceException {
User user = null;
if (username != null) {
user = em.find(User.class, username);
if (user == null) {
throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "User not found with username: " + username);
}
}
return user;
}
}