#4479 - upgrade SecurisServer to Java 21
| .. | .. |
|---|
| 59 | 59 | <artifactId>resteasy-jackson2-provider</artifactId> |
|---|
| 60 | 60 | <version>${resteasy.version}</version> |
|---|
| 61 | 61 | </dependency> |
|---|
| 62 | + <dependency> |
|---|
| 63 | + <groupId>org.jboss.resteasy</groupId> |
|---|
| 64 | + <artifactId>resteasy-cdi</artifactId> |
|---|
| 65 | + <version>${resteasy.version}</version> |
|---|
| 66 | + </dependency> |
|---|
| 62 | 67 | <dependency> |
|---|
| 63 | 68 | <groupId>org.apache.httpcomponents</groupId> |
|---|
| 64 | 69 | <artifactId>httpmime</artifactId> |
|---|
| .. | .. |
|---|
| 102 | 107 | <version>${hibernate.version}</version> |
|---|
| 103 | 108 | </dependency> |
|---|
| 104 | 109 | --> |
|---|
| 110 | + <!-- |
|---|
| 105 | 111 | <dependency> |
|---|
| 106 | 112 | <groupId>org.hibernate</groupId> |
|---|
| 107 | 113 | <artifactId>hibernate-core</artifactId> |
|---|
| 108 | 114 | <version>${hibernate.version}</version> |
|---|
| 109 | 115 | </dependency> |
|---|
| 116 | + --> |
|---|
| 117 | + <dependency> |
|---|
| 118 | + <groupId>org.hibernate</groupId> |
|---|
| 119 | + <artifactId>hibernate-core-jakarta</artifactId> |
|---|
| 120 | + <version>5.6.15.Final</version> |
|---|
| 121 | + </dependency> |
|---|
| 110 | 122 | |
|---|
| 111 | 123 | <!-- Logging --> |
|---|
| 112 | 124 | <dependency> |
|---|
| .. | .. |
|---|
| 8 | 8 |
|
|---|
| 9 | 9 | import jakarta.ws.rs.core.Application;
|
|---|
| 10 | 10 |
|
|---|
| 11 | | -///import net.curisit.securis.ioc.RequestsInterceptor;
|
|---|
| 11 | +/// import net.curisit.securis.ioc.RequestsInterceptor;
|
|---|
| 12 | 12 | import net.curisit.securis.services.ApiResource;
|
|---|
| 13 | 13 | import net.curisit.securis.services.ApplicationResource;
|
|---|
| 14 | 14 | import net.curisit.securis.services.BasicServices;
|
|---|
| .. | .. |
|---|
| 6 | 6 | import java.io.Serializable; |
|---|
| 7 | 7 | import java.util.Date; |
|---|
| 8 | 8 | |
|---|
| 9 | | -import javax.persistence.Column; |
|---|
| 10 | | -import javax.persistence.Entity; |
|---|
| 11 | | -import javax.persistence.EntityListeners; |
|---|
| 12 | | -import javax.persistence.Id; |
|---|
| 13 | | -import javax.persistence.NamedQueries; |
|---|
| 14 | | -import javax.persistence.NamedQuery; |
|---|
| 15 | | -import javax.persistence.Table; |
|---|
| 9 | +import jakarta.persistence.Column; |
|---|
| 10 | +import jakarta.persistence.Entity; |
|---|
| 11 | +import jakarta.persistence.EntityListeners; |
|---|
| 12 | +import jakarta.persistence.Id; |
|---|
| 13 | +import jakarta.persistence.NamedQueries; |
|---|
| 14 | +import jakarta.persistence.NamedQuery; |
|---|
| 15 | +import jakarta.persistence.Table; |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | import net.curisit.securis.db.common.ModificationTimestampEntity; |
|---|
| 18 | 18 | import net.curisit.securis.db.listeners.ModificationTimestampListener; |
|---|
| .. | .. |
|---|
| 5 | 5 | |
|---|
| 6 | 6 | import java.util.Date; |
|---|
| 7 | 7 | |
|---|
| 8 | | -import javax.persistence.PrePersist; |
|---|
| 8 | +import jakarta.persistence.PrePersist; |
|---|
| 9 | 9 | |
|---|
| 10 | 10 | import net.curisit.securis.db.common.CreationTimestampEntity; |
|---|
| 11 | 11 | |
|---|
| .. | .. |
|---|
| 5 | 5 | |
|---|
| 6 | 6 | import java.util.Date; |
|---|
| 7 | 7 | |
|---|
| 8 | | -import javax.persistence.PrePersist; |
|---|
| 9 | | -import javax.persistence.PreUpdate; |
|---|
| 8 | +import jakarta.persistence.PrePersist; |
|---|
| 9 | +import jakarta.persistence.PreUpdate; |
|---|
| 10 | 10 | |
|---|
| 11 | 11 | import net.curisit.securis.db.common.ModificationTimestampEntity; |
|---|
| 12 | 12 | |
|---|
| .. | .. |
|---|
| 19 | 19 | @RequestScoped |
|---|
| 20 | 20 | public class EntityManagerProducer { |
|---|
| 21 | 21 | |
|---|
| 22 | | - private static final Logger LOG = LogManager.getLogger(EntityManagerProducer.class); |
|---|
| 22 | + private static final Logger log = LogManager.getLogger(EntityManagerProducer.class); |
|---|
| 23 | 23 | |
|---|
| 24 | 24 | @Inject |
|---|
| 25 | 25 | private EntityManagerProvider emProvider; |
|---|
| .. | .. |
|---|
| 28 | 28 | @RequestScoped |
|---|
| 29 | 29 | public EntityManager produceEntityManager() { |
|---|
| 30 | 30 | EntityManager em = emProvider.getEntityManager(); |
|---|
| 31 | | - LOG.info("Produced EntityManager: {}", em); |
|---|
| 31 | + if (em == null) { |
|---|
| 32 | + throw new IllegalStateException("EntityManagerProvider returned null EntityManager"); |
|---|
| 33 | + } |
|---|
| 34 | + log.info("Produced EntityManager: {}", em); |
|---|
| 32 | 35 | return em; |
|---|
| 33 | 36 | } |
|---|
| 34 | 37 | |
|---|
| 35 | 38 | public void closeEntityManager(@Disposes EntityManager em) { |
|---|
| 36 | 39 | if (em != null && em.isOpen()) { |
|---|
| 37 | | - LOG.info("Closing produced EntityManager: {}", em); |
|---|
| 40 | + log.info("Closing produced EntityManager: {}", em); |
|---|
| 38 | 41 | em.close(); |
|---|
| 39 | 42 | } |
|---|
| 40 | 43 | } |
|---|
| .. | .. |
|---|
| 45 | 45 | log.info("EntityManagerFactory initialized correctly: {}", entityManagerFactory); |
|---|
| 46 | 46 | } catch (Exception e) { |
|---|
| 47 | 47 | log.error("Error creating EntityManagerFactory for persistence unit 'localdb'", e); |
|---|
| 48 | | - entityManagerFactory = null; |
|---|
| 48 | + throw new IllegalStateException("Could not initialize EntityManagerFactory", e); |
|---|
| 49 | 49 | } |
|---|
| 50 | 50 | } |
|---|
| 51 | 51 | |
|---|
| .. | .. |
|---|
| 56 | 56 | * @return a new EntityManager; caller must close it |
|---|
| 57 | 57 | */ |
|---|
| 58 | 58 | public EntityManager getEntityManager() { |
|---|
| 59 | | - try { |
|---|
| 60 | | - if (entityManagerFactory == null) { |
|---|
| 61 | | - log.error("EntityManagerFactory is null"); |
|---|
| 62 | | - return null; |
|---|
| 63 | | - } |
|---|
| 64 | | - EntityManager em = entityManagerFactory.createEntityManager(); |
|---|
| 65 | | - log.info("Created EntityManager: {}", em); |
|---|
| 66 | | - return em; |
|---|
| 67 | | - } catch (Exception e) { |
|---|
| 68 | | - log.error("Error creating EntityManager", e); |
|---|
| 69 | | - return null; |
|---|
| 59 | + if (entityManagerFactory == null) { |
|---|
| 60 | + throw new IllegalStateException("EntityManagerFactory is null"); |
|---|
| 70 | 61 | } |
|---|
| 62 | + EntityManager em = entityManagerFactory.createEntityManager(); |
|---|
| 63 | + log.info("Created EntityManager: {}", em); |
|---|
| 64 | + return em; |
|---|
| 71 | 65 | } |
|---|
| 72 | 66 | } |
|---|
| .. | .. |
|---|
| 9 | 9 | import java.util.Set; |
|---|
| 10 | 10 | |
|---|
| 11 | 11 | import jakarta.annotation.Priority; |
|---|
| 12 | +import jakarta.enterprise.context.ApplicationScoped; |
|---|
| 12 | 13 | import jakarta.inject.Inject; |
|---|
| 13 | 14 | import jakarta.persistence.EntityManager; |
|---|
| 14 | 15 | import jakarta.servlet.http.HttpServletRequest; |
|---|
| .. | .. |
|---|
| 53 | 54 | * Last reviewed by JRA on Oct 5, 2025. |
|---|
| 54 | 55 | */ |
|---|
| 55 | 56 | @Provider |
|---|
| 57 | +@ApplicationScoped |
|---|
| 56 | 58 | @Priority(Priorities.AUTHENTICATION) |
|---|
| 57 | 59 | public class RequestsInterceptor implements ContainerRequestFilter, WriterInterceptor { |
|---|
| 58 | 60 | |
|---|
| .. | .. |
|---|
| 82 | 84 | @Override |
|---|
| 83 | 85 | public void filter(ContainerRequestContext requestContext) throws IOException { |
|---|
| 84 | 86 | |
|---|
| 87 | + log.info("RequestsInterceptor instance={}", this); |
|---|
| 88 | + log.info("Injected tokenHelper={}", tokenHelper); |
|---|
| 89 | + log.info("Injected cache={}", cache); |
|---|
| 90 | + log.info("Injected em={}", em); |
|---|
| 91 | + |
|---|
| 85 | 92 | Method method = resourceInfo != null ? resourceInfo.getResourceMethod() : null; |
|---|
| 86 | 93 | if (method == null) { |
|---|
| 87 | 94 | log.warn("RequestsInterceptor: resource method is null"); |
|---|
| .. | .. |
|---|
| 74 | 74 | @Inject MetadataHelper metadataHelper; |
|---|
| 75 | 75 | @Inject private LicenseHelper licenseHelper; |
|---|
| 76 | 76 | |
|---|
| 77 | | - @Context EntityManager em; |
|---|
| 77 | + @Inject EntityManager em; |
|---|
| 78 | 78 | |
|---|
| 79 | 79 | /** |
|---|
| 80 | 80 | * index |
|---|
| .. | .. |
|---|
| 310 | 310 | * @throws SeCurisServiceException on invalid state. |
|---|
| 311 | 311 | */ |
|---|
| 312 | 312 | @POST |
|---|
| 313 | | - @Path("/{packId}/putonhold}") |
|---|
| 313 | + @Path("/{packId}/putonhold") |
|---|
| 314 | 314 | @EnsureTransaction |
|---|
| 315 | 315 | @Securable(roles = Rol.ADMIN | Rol.ADVANCE) |
|---|
| 316 | 316 | @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| .. | .. |
|---|
| 406 | 406 | LOG.info("index session: " + request.getSession()); |
|---|
| 407 | 407 | LOG.info("login() called. session={}", request.getSession(false)); |
|---|
| 408 | 408 | LOG.info("login() username='{}'", username); |
|---|
| 409 | + |
|---|
| 410 | + LOG.info("UserResource instance={}", this); |
|---|
| 411 | + LOG.info("Injected em={}", em); |
|---|
| 412 | + LOG.info("Injected tokenHelper={}", tokenHelper); |
|---|
| 413 | + LOG.info("Injected cache={}", cache); |
|---|
| 409 | 414 | |
|---|
| 410 | 415 | if (username == null || username.trim().isEmpty()) { |
|---|
| 411 | 416 | LOG.error("login() username is null or empty"); |
|---|
| .. | .. |
|---|
| 36 | 36 | <param-name>resteasy.providers</param-name> |
|---|
| 37 | 37 | <param-value>net.curisit.securis.DefaultExceptionHandler</param-value> |
|---|
| 38 | 38 | </context-param> |
|---|
| 39 | + |
|---|
| 39 | 40 | <context-param> |
|---|
| 40 | 41 | <param-name>resteasy.servlet.mapping.prefix</param-name> |
|---|
| 41 | 42 | <param-value>/api</param-value> |
|---|
| 42 | 43 | </context-param> |
|---|
| 43 | 44 | |
|---|
| 44 | | - <!-- |
|---|
| 45 | 45 | <context-param> |
|---|
| 46 | 46 | <param-name>resteasy.injector.factory</param-name> |
|---|
| 47 | 47 | <param-value>org.jboss.resteasy.cdi.CdiInjectorFactory</param-value> |
|---|
| 48 | 48 | </context-param> |
|---|
| 49 | | - --> |
|---|
| 49 | + |
|---|
| 50 | 50 | |
|---|
| 51 | 51 | <filter> |
|---|
| 52 | 52 | <filter-name>DevFilter</filter-name> |
|---|
| .. | .. |
|---|
| 17 | 17 | |
|---|
| 18 | 18 | ngOnInit(): void { |
|---|
| 19 | 19 | //TODO Move to service |
|---|
| 20 | | - this.http.get("api/version", /* workaround to avoid OPTIONS method request*/ new BaseRequestOptions()) |
|---|
| 20 | + this.http.get("version", /* workaround to avoid OPTIONS method request*/ new BaseRequestOptions()) |
|---|
| 21 | 21 | .map((res) => <string>res.json().version) |
|---|
| 22 | 22 | .subscribe( |
|---|
| 23 | 23 | version => this.securisVersion = version, |
|---|
| .. | .. |
|---|
| 27 | 27 | params.append('username', username); |
|---|
| 28 | 28 | params.append('password', password); |
|---|
| 29 | 29 | let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })}); |
|---|
| 30 | | - return this.http.post('api/user/login', params.toString(), options) |
|---|
| 30 | + return this.http.post('user/login', params.toString(), options) |
|---|
| 31 | 31 | .map((resp) => this.mapLogin(resp)) |
|---|
| 32 | 32 | .catch((err) => super.processErrorResponse(err)); |
|---|
| 33 | 33 | } |
|---|
| .. | .. |
|---|
| 47 | 47 | } |
|---|
| 48 | 48 | var token = this.store.get("token"); |
|---|
| 49 | 49 | let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) }); |
|---|
| 50 | | - return this.http.get('api/check', option) |
|---|
| 50 | + return this.http.get('check', option) |
|---|
| 51 | 51 | .map((resp) => this.mapCheck(resp)) |
|---|
| 52 | 52 | .catch((err) => super.processErrorResponse(err)); |
|---|
| 53 | 53 | } |
|---|