Joaquín Reñé
18 hours ago 78b085815b9873acdf178b2e9c9598d065fd40c0
#4479 - upgrade SecurisServer to Java 21
23 files modified
changed files
securis/src/main/java/net/curisit/securis/LicenseGenerator.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/RestServicesApplication.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/ioc/EntityManagerProducer.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/ioc/RequestsInterceptor.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/ApiResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/PackResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/UserResource.java patch | view | blame | history
securis/src/main/webapp/WEB-INF/log4j2.xml patch | view | blame | history
securis/src/main/webapp/WEB-INF/web.xml patch | view | blame | history
securis/src/main/webapp/src/app/footer.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/base.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/pack.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/applications.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/base.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/license_types.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/licenses.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/organizations.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/packs.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/users.ts patch | view | blame | history
securis/src/main/webapp/src/app/user.service.ts patch | view | blame | history
securis/src/main/java/net/curisit/securis/LicenseGenerator.java
....@@ -27,7 +27,7 @@
2727 import org.apache.logging.log4j.LogManager;
2828 import org.apache.logging.log4j.Logger;
2929
30
-import jakarta.inject.Singleton;
30
+import jakarta.enterprise.context.ApplicationScoped;
3131
3232 /**
3333 * LicenseGenerator
....@@ -39,7 +39,7 @@
3939 * @author JRA
4040 * Last reviewed by JRA on Oct 5, 2025.
4141 */
42
-@Singleton
42
+@ApplicationScoped
4343 public class LicenseGenerator {
4444
4545 private static final Logger LOG = LogManager.getLogger(LicenseGenerator.class);
securis/src/main/java/net/curisit/securis/RestServicesApplication.java
....@@ -8,7 +8,7 @@
88
99 import jakarta.ws.rs.core.Application;
1010
11
-/// import net.curisit.securis.ioc.RequestsInterceptor;
11
+import net.curisit.securis.ioc.RequestsInterceptor;
1212 import net.curisit.securis.services.ApiResource;
1313 import net.curisit.securis.services.ApplicationResource;
1414 import net.curisit.securis.services.BasicServices;
....@@ -50,7 +50,7 @@
5050 classes.add(OrganizationResource.class);
5151 classes.add(LicenseTypeResource.class);
5252 classes.add(PackResource.class);
53
- /// classes.add(RequestsInterceptor.class);
53
+ classes.add(RequestsInterceptor.class);
5454 // classes.add(TransactionsInterceptor.class);
5555 // classes.add(JpaJacksonProvider.class);
5656 // classes.add(JacksonConfig.class);
securis/src/main/java/net/curisit/securis/ioc/EntityManagerProducer.java
....@@ -21,8 +21,7 @@
2121
2222 private static final Logger log = LogManager.getLogger(EntityManagerProducer.class);
2323
24
- @Inject
25
- private EntityManagerProvider emProvider;
24
+ @Inject private EntityManagerProvider emProvider;
2625
2726 @Produces
2827 @RequestScoped
securis/src/main/java/net/curisit/securis/ioc/RequestsInterceptor.java
....@@ -28,7 +28,7 @@
2828
2929 import org.apache.logging.log4j.LogManager;
3030 import org.apache.logging.log4j.Logger;
31
-
31
+import org.jboss.resteasy.core.ResteasyContext;
3232 import net.curisit.securis.db.User;
3333 import net.curisit.securis.security.BasicSecurityContext;
3434 import net.curisit.securis.security.Securable;
....@@ -189,6 +189,9 @@
189189 sc.setOrganizationsIds(getUserOrganizations(username));
190190 sc.setApplicationsIds(getUserApplications(username));
191191 ctx.setSecurityContext(sc);
192
+
193
+ ResteasyContext.pushContext(BasicSecurityContext.class, sc);
194
+
192195 return true;
193196 }
194197
securis/src/main/java/net/curisit/securis/services/ApiResource.java
....@@ -7,6 +7,7 @@
77 import java.util.Date;
88 import java.util.List;
99
10
+import jakarta.enterprise.context.RequestScoped;
1011 import jakarta.inject.Inject;
1112 import jakarta.persistence.EntityManager;
1213 import jakarta.persistence.NoResultException;
....@@ -76,6 +77,7 @@
7677 * Last reviewed by JRA on Oct 5, 2025.
7778 */
7879 @Path("/api")
80
+@RequestScoped
7981 public class ApiResource {
8082
8183 private static final Logger LOG = LogManager.getLogger(ApiResource.class);
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
....@@ -10,6 +10,7 @@
1010 import java.util.Set;
1111
1212 import jakarta.annotation.security.RolesAllowed;
13
+import jakarta.enterprise.context.RequestScoped;
1314 import jakarta.inject.Inject;
1415 import jakarta.persistence.EntityManager;
1516 import jakarta.persistence.TypedQuery;
....@@ -63,12 +64,13 @@
6364 * Last reviewed by JRA on Oct 5, 2025.
6465 */
6566 @Path("/application")
67
+@RequestScoped
6668 public class ApplicationResource {
6769
6870 @Inject TokenHelper tokenHelper;
6971 @Inject MetadataHelper metadataHelper;
7072
71
- @Context EntityManager em;
73
+ @Inject EntityManager em;
7274
7375 private static final Logger LOG = LogManager.getLogger(ApplicationResource.class);
7476
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
....@@ -10,6 +10,7 @@
1010 import java.util.stream.Collectors;
1111
1212 import jakarta.annotation.security.RolesAllowed;
13
+import jakarta.enterprise.context.RequestScoped;
1314 import jakarta.inject.Inject;
1415 import jakarta.persistence.EntityManager;
1516 import jakarta.persistence.TypedQuery;
....@@ -57,6 +58,7 @@
5758 * Last reviewed by JRA on Oct 5, 2025.
5859 */
5960 @Path("/licensetype")
61
+@RequestScoped
6062 public class LicenseTypeResource {
6163
6264 private static final Logger LOG = LogManager.getLogger(LicenseTypeResource.class);
....@@ -64,7 +66,7 @@
6466 @Inject TokenHelper tokenHelper;
6567 @Inject MetadataHelper metadataHelper;
6668
67
- @Context EntityManager em;
69
+ @Inject EntityManager em;
6870
6971 public LicenseTypeResource() { }
7072
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
....@@ -10,6 +10,7 @@
1010
1111 import jakarta.annotation.security.RolesAllowed;
1212 import jakarta.enterprise.context.RequestScoped;
13
+import jakarta.inject.Inject;
1314 import jakarta.persistence.EntityManager;
1415 import jakarta.persistence.TypedQuery;
1516 import jakarta.servlet.http.HttpServletRequest;
....@@ -26,6 +27,7 @@
2627 import jakarta.ws.rs.core.MediaType;
2728 import jakarta.ws.rs.core.Response;
2829 import jakarta.ws.rs.core.Response.Status;
30
+import jakarta.ws.rs.core.SecurityContext;
2931
3032 import org.apache.logging.log4j.LogManager;
3133 import org.apache.logging.log4j.Logger;
....@@ -55,8 +57,7 @@
5557
5658 private static final Logger LOG = LogManager.getLogger(OrganizationResource.class);
5759
58
- @Context EntityManager em;
59
- @Context BasicSecurityContext bsc;
60
+ @Inject EntityManager em;
6061
6162 public OrganizationResource() { }
6263
....@@ -72,23 +73,28 @@
7273 @Path("/")
7374 @Produces({ MediaType.APPLICATION_JSON })
7475 @Securable
75
- public Response index() {
76
- LOG.info("Getting organizations list ");
77
- em.clear();
78
- TypedQuery<Organization> q;
79
- if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
80
- LOG.info("GEtting all orgs for user: " + bsc.getUserPrincipal());
81
- q = em.createNamedQuery("list-organizations", Organization.class);
82
- } else {
83
- if (bsc.getOrganizationsIds() == null || bsc.getOrganizationsIds().isEmpty()) {
84
- return Response.ok().build();
85
- } else {
86
- q = em.createNamedQuery("list-organizations-by-ids", Organization.class);
87
- q.setParameter("list_ids", bsc.getOrganizationsIds());
88
- }
89
- }
90
- List<Organization> list = q.getResultList();
91
- return Response.ok(list).build();
76
+ public Response index(@Context SecurityContext securityContext) {
77
+ BasicSecurityContext bsc = org.jboss.resteasy.core.ResteasyContext.getContextData(BasicSecurityContext.class);
78
+ if (bsc == null) {
79
+ LOG.error("BasicSecurityContext not found in ResteasyContext");
80
+ return Response.status(Status.UNAUTHORIZED).build();
81
+ }
82
+ LOG.info("Getting organizations list ");
83
+ em.clear();
84
+ TypedQuery<Organization> q;
85
+ if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
86
+ LOG.info("Getting all orgs for user: " + bsc.getUserPrincipal());
87
+ q = em.createNamedQuery("list-organizations", Organization.class);
88
+ } else {
89
+ if (bsc.getOrganizationsIds() == null || bsc.getOrganizationsIds().isEmpty()) {
90
+ return Response.ok().build();
91
+ } else {
92
+ q = em.createNamedQuery("list-organizations-by-ids", Organization.class);
93
+ q.setParameter("list_ids", bsc.getOrganizationsIds());
94
+ }
95
+ }
96
+ List<Organization> list = q.getResultList();
97
+ return Response.ok(list).build();
9298 }
9399
94100 /**
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -11,6 +11,7 @@
1111 import java.util.Set;
1212
1313 import jakarta.annotation.security.RolesAllowed;
14
+import jakarta.enterprise.context.RequestScoped;
1415 import jakarta.inject.Inject;
1516 import jakarta.persistence.EntityManager;
1617 import jakarta.persistence.TypedQuery;
....@@ -66,6 +67,7 @@
6667 * Last reviewed by JRA on Oct 5, 2025.
6768 */
6869 @Path("/pack")
70
+@RequestScoped
6971 public class PackResource {
7072
7173 private static final Logger LOG = LogManager.getLogger(PackResource.class);
securis/src/main/java/net/curisit/securis/services/UserResource.java
....@@ -407,11 +407,15 @@
407407 LOG.info("login() called. session={}", request.getSession(false));
408408 LOG.info("login() username='{}'", username);
409409
410
- LOG.info("UserResource instance={}", this);
411
- LOG.info("Injected em={}", em);
412
- LOG.info("Injected tokenHelper={}", tokenHelper);
413
- LOG.info("Injected cache={}", cache);
414
-
410
+ boolean trazalogin = false;
411
+
412
+ if (trazalogin) {
413
+ LOG.info("UserResource instance={}", this);
414
+ LOG.info("Injected em={}", em);
415
+ LOG.info("Injected tokenHelper={}", tokenHelper);
416
+ LOG.info("Injected cache={}", cache);
417
+ }
418
+
415419 if (username == null || username.trim().isEmpty()) {
416420 LOG.error("login() username is null or empty");
417421 throw new SeCurisServiceException(ErrorCodes.UNAUTHORIZED_ACCESS, "Wrong credentials");
....@@ -432,6 +436,27 @@
432436 String securedPassword = Utils.sha256(password);
433437 LOG.info("login() hashed password generated? {}", securedPassword != null);
434438
439
+ if (trazalogin) {
440
+ LOG.info("login() stored password hash='{}'", user.getPassword());
441
+ LOG.info("login() computed password hash='{}'", securedPassword);
442
+ LOG.info("login() stored length={}, computed length={}",
443
+ user.getPassword() == null ? null : user.getPassword().length(),
444
+ securedPassword == null ? null : securedPassword.length());
445
+
446
+
447
+ LOG.info("raw password='{}'", password);
448
+ LOG.info("sha256(raw)='{}'", Utils.sha256(password));
449
+ LOG.info("sha256(trim)='{}'", Utils.sha256(password == null ? null : password.trim()));
450
+ LOG.info("sha256(lower)='{}'", Utils.sha256(password == null ? null : password.toLowerCase()));
451
+ LOG.info("sha256(upper)='{}'", Utils.sha256(password == null ? null : password.toUpperCase()));
452
+ LOG.info("sha256(username+password)='{}'", Utils.sha256(username + password));
453
+ LOG.info("sha256(password+username)='{}'", Utils.sha256(password + username));
454
+ LOG.info("stored hash='{}'", user.getPassword());
455
+
456
+ LOG.info("password.equals('admin')={}", "admin".equals(password));
457
+ LOG.info("password length={}", password == null ? null : password.length());
458
+ }
459
+
435460 if (securedPassword == null || !securedPassword.equals(user.getPassword())) {
436461 LOG.error("Wrong password for user '{}'", username);
437462 throw new SeCurisServiceException(ErrorCodes.UNAUTHORIZED_ACCESS, "Wrong credentials");
securis/src/main/webapp/WEB-INF/log4j2.xml
....@@ -1,48 +1,13 @@
11 <?xml version="1.0" encoding="UTF-8"?>
22 <Configuration>
3
- <Appenders>
4
-
5
- <RollingFile name="defaultFile"
6
- fileName="${sys:catalina.home}/logs/securis-server.log" append="true"
7
- filePattern="${sys:catalina.home}/logs/securis-server-%d{yyyy-MM-dd-HH}.log.gz">
8
- <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n" />
9
- <Policies>
10
- <TimeBasedTriggeringPolicy interval="1"
11
- modulate="true" />
12
- </Policies>
13
- <DefaultRolloverStrategy max="10" />
14
- </RollingFile>
15
- <Async name="defaultFileAsync" includeLocation="true">
16
- <AppenderRef ref="defaultFile" />
17
- </Async>
18
-
19
- <Console name="stdout" target="SYSTEM_OUT">
20
- <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n" />
21
- </Console>
22
-
23
- <Console name="console" target="SYSTEM_OUT">
24
- <PatternLayout pattern="%m%n" />
25
- </Console>
26
- </Appenders>
27
- <Loggers>
28
-
29
- <Logger name="net.curisit" level="INFO" additivity="false">
30
- <AppenderRef ref="defaultFileAsync" />
31
- <AppenderRef ref="stdout" />
32
- </Logger>
33
-
34
- <Logger name="console" level="INFO" additivity="false">
35
- <AppenderRef ref="console" />
36
- </Logger>
37
-
38
-<!-- <logger name="org.hibernate.type.descriptor.sql.BasicBinder"
39
- level="TRACE" additivity="false">
40
- <appender-ref ref="stdout" />
41
- </logger> -->
42
-
43
- <Root level="INFO">
44
- <AppenderRef ref="stdout" />
45
- </Root>
46
-
47
- </Loggers>
3
+ <Appenders>
4
+ <Console name="STDOUT" target="SYSTEM_OUT">
5
+ <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
6
+ </Console>
7
+ </Appenders>
8
+ <Loggers>
9
+ <Root level="info">
10
+ <AppenderRef ref="STDOUT"/>
11
+ </Root>
12
+ </Loggers>
4813 </Configuration>
securis/src/main/webapp/WEB-INF/web.xml
....@@ -36,16 +36,18 @@
3636 <param-name>resteasy.providers</param-name>
3737 <param-value>net.curisit.securis.DefaultExceptionHandler</param-value>
3838 </context-param>
39
+
40
+ <context-param>
41
+ <param-name>resteasy.injector.factory</param-name>
42
+ <param-value>org.jboss.resteasy.cdi.CdiInjectorFactory</param-value>
43
+ </context-param>
3944
45
+
4046 <context-param>
4147 <param-name>resteasy.servlet.mapping.prefix</param-name>
4248 <param-value>/api</param-value>
4349 </context-param>
4450
45
- <context-param>
46
- <param-name>resteasy.injector.factory</param-name>
47
- <param-value>org.jboss.resteasy.cdi.CdiInjectorFactory</param-value>
48
- </context-param>
4951
5052
5153 <filter>
....@@ -56,7 +58,7 @@
5658 </filter>
5759 <filter-mapping>
5860 <filter-name>DevFilter</filter-name>
59
- <url-pattern>/api/*</url-pattern>
61
+ <url-pattern>/*</url-pattern>
6062 </filter-mapping>
6163
6264 <filter>
securis/src/main/webapp/src/app/footer.component.ts
....@@ -17,7 +17,7 @@
1717
1818 ngOnInit(): void {
1919 //TODO Move to service
20
- this.http.get("version", /* workaround to avoid OPTIONS method request*/ new BaseRequestOptions())
20
+ this.http.get("api/version", /* workaround to avoid OPTIONS method request*/ new BaseRequestOptions())
2121 .map((res) => <string>res.json().version)
2222 .subscribe(
2323 version => this.securisVersion = version,
securis/src/main/webapp/src/app/forms/base.ts
....@@ -84,7 +84,7 @@
8484 this.toaster.success(this.$L.get('{} was sucessfully deleted', this.resourceName.capitalize()));
8585 this.goBack();
8686 },
87
- err => this.toaster.success(err.message, this.$L.get('Error deleting the {}', this.resourceName))
87
+ err => this.toaster.error(err.message, this.$L.get('Error deleting the {}', this.resourceName))
8888 );
8989 }
9090 });
securis/src/main/webapp/src/app/forms/pack.form.component.ts
....@@ -34,7 +34,7 @@
3434 }
3535
3636 loadCombos(): void {
37
- this.http.get('organization')
37
+ this.http.get('api/organization')
3838 .map(response => response.json().map((org : any) => <IComboOption>{id: org.id, label: `(${org.code}) ${org.name}`}))
3939 .subscribe(
4040 data => super.setViewData(() => this.organizations = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label))),
securis/src/main/webapp/src/app/resources/applications.ts
....@@ -1,6 +1,7 @@
11 import { Observable } from 'rxjs/Rx';
22 import { Injectable } from '@angular/core';
33 import { Http, RequestOptions } from '@angular/http';
4
+import { Locker } from 'angular-safeguard';
45 import { SeCurisResourceServices } from './base';
56 import { LocaleService } from '../common/i18n';
67
....@@ -18,8 +19,8 @@
1819
1920 @Injectable()
2021 export class ApplicationsService extends SeCurisResourceServices {
21
- constructor(http: Http, $L: LocaleService) {
22
- super($L, http, 'application');
22
+ constructor(http: Http, $L: LocaleService, store: Locker) {
23
+ super($L, http, store, 'application');
2324 }
2425
2526
securis/src/main/webapp/src/app/resources/base.ts
....@@ -1,53 +1,77 @@
11 import { LocaleService } from '../common/i18n';
22 import { BasicService } from '../common/utils';
33 import { Observable } from 'rxjs/Observable';
4
-import { Http, RequestOptionsArgs, URLSearchParams } from '@angular/http';
4
+import { Http, RequestOptionsArgs, URLSearchParams, Headers } from '@angular/http';
5
+import { Locker } from 'angular-safeguard';
6
+
57
68 export class MySearchParams extends URLSearchParams {
7
- constructor(obj : any = {}) {
8
- var searchQuery = Object.keys(obj).map(key => `${key}=${encodeURIComponent(obj[key])}`).join('&');
9
+ constructor(obj: any = {}) {
10
+ const searchQuery = Object.keys(obj).map(key => `${key}=${encodeURIComponent(obj[key])}`).join('&');
911 super(searchQuery);
1012 }
1113 }
1214
1315 export class SeCurisResourceServices extends BasicService {
14
- constructor($L: LocaleService,
15
- protected http: Http,
16
- protected resource: string) {
17
- super($L);
18
- }
16
+ constructor($L: LocaleService,
17
+ protected http: Http,
18
+ protected store: Locker,
19
+ protected resource: string) {
20
+ super($L);
21
+ this.resource = `api/${resource}`;
22
+ }
1923
20
- public get(id?: any) : Observable<any> {
21
- let url = `${this.resource}/${id || ''}`;
22
- return this.http.get(url).map(response => response.json()).catch(err => super.processErrorResponse(err));
24
+ protected getAuthHeaders(): RequestOptionsArgs {
25
+ const token = this.store.get('token');
26
+ const headers = new Headers();
27
+ if (token) {
28
+ headers.append('X-SECURIS-TOKEN', token);
2329 }
30
+ headers.append('Content-Type', 'application/json');
31
+ return { headers: headers };
32
+ }
2433
25
- public create(data: any) : Observable<any> {
26
- let url = `${this.resource}`;
27
- return this.http.post(url, JSON.stringify(data)).map(response => response.json()).catch(err => super.processErrorResponse(err));
28
- }
34
+ public get(id?: any): Observable<any> {
35
+ const url = `${this.resource}/${id || ''}`;
36
+ return this.http.get(url, this.getAuthHeaders())
37
+ .map(response => response.json())
38
+ .catch(err => super.processErrorResponse(err));
39
+ }
2940
30
- public modify(id: any, data: any) : Observable<any> {
31
- let url = `${this.resource}/${id}`;
32
- return this.http.post(url, JSON.stringify(data)).map(response => response.json()).catch(err => super.processErrorResponse(err));
33
- }
41
+ public create(data: any): Observable<any> {
42
+ const url = `${this.resource}`;
43
+ return this.http.post(url, JSON.stringify(data), this.getAuthHeaders())
44
+ .map(response => response.json())
45
+ .catch(err => super.processErrorResponse(err));
46
+ }
3447
35
- public remove(id: any) : Observable<any> {
36
- let url = `${this.resource}/${id}`;
37
- return this.http.delete(url).map(response => response.json()).catch(err => super.processErrorResponse(err));
38
- }
39
-
40
- public action(id: any, action: string, method = 'POST', params : any = {}) : Observable<any> {
41
- let url = `${this.resource}/${id}/${action}`;
42
- params.action = action;
43
- var options:RequestOptionsArgs = {
44
- url: url,
45
- method: method,
46
- search: (method == 'GET') && new MySearchParams(params) || undefined,
47
- body: (method == 'POST') && JSON.stringify(params) || undefined
48
- };
49
- return this.http.request(url, options).map(response => response.json()).catch(err => super.processErrorResponse(err));
50
- }
48
+ public modify(id: any, data: any): Observable<any> {
49
+ const url = `${this.resource}/${id}`;
50
+ // Se usa POST para modificar (según tu diseño original)
51
+ return this.http.post(url, JSON.stringify(data), this.getAuthHeaders())
52
+ .map(response => response.json())
53
+ .catch(err => super.processErrorResponse(err));
54
+ }
5155
56
+ public remove(id: any): Observable<any> {
57
+ const url = `${this.resource}/${id}`;
58
+ return this.http.delete(url, this.getAuthHeaders())
59
+ .map(response => response.json())
60
+ .catch(err => super.processErrorResponse(err));
61
+ }
5262
63
+ public action(id: any, action: string, method: string = 'POST', params: any = {}): Observable<any> {
64
+ const url = `${this.resource}/${id}/${action}`;
65
+ params.action = action;
66
+ const options: RequestOptionsArgs = {
67
+ url: url,
68
+ method: method,
69
+ search: (method === 'GET') ? new MySearchParams(params) : undefined,
70
+ headers: this.getAuthHeaders().headers,
71
+ body: (method === 'POST') ? JSON.stringify(params) : undefined
72
+ };
73
+ return this.http.request(url, options)
74
+ .map(response => response.json())
75
+ .catch(err => super.processErrorResponse(err));
76
+ }
5377 }
securis/src/main/webapp/src/app/resources/license_types.ts
....@@ -1,6 +1,7 @@
11 import { Observable } from 'rxjs/Rx';
22 import { Injectable } from '@angular/core';
33 import { Http, RequestOptions } from '@angular/http';
4
+import { Locker } from 'angular-safeguard';
45 import { SeCurisResourceServices } from './base';
56 import { LocaleService } from '../common/i18n';
67
....@@ -15,8 +16,8 @@
1516
1617 @Injectable()
1718 export class LicenseTypesService extends SeCurisResourceServices {
18
- constructor(http: Http, $L: LocaleService) {
19
- super($L, http, 'licensetype');
19
+ constructor(http: Http, $L: LocaleService, store: Locker) {
20
+ super($L, http, store, 'licensetype');
2021 }
2122
2223
securis/src/main/webapp/src/app/resources/licenses.ts
....@@ -2,6 +2,7 @@
22 import { Observable } from 'rxjs/Rx';
33 import { Injectable } from '@angular/core';
44 import { Http, RequestOptions, ResponseContentType, Response } from '@angular/http';
5
+import { Locker } from 'angular-safeguard';
56 import { SeCurisResourceServices } from './base';
67 import { saveAs } from "file-saver";
78
....@@ -78,14 +79,13 @@
7879
7980 @Injectable()
8081 export class LicensesService extends SeCurisResourceServices {
81
- constructor(http: Http,
82
- $L: LocaleService) {
83
- super($L, http, 'license');
82
+ constructor(http: Http, $L: LocaleService, store: Locker) {
83
+ super($L, http, store, 'license');
8484 }
8585
8686 public getByPack(packId: number) {
8787 let url = `${this.resource}?packId=${packId}`;
88
- return this.http.get(url).map(response => response.json());
88
+ return this.http.get(url, this.getAuthHeaders()).map(response => response.json());
8989 }
9090
9191 public activate(id: number) {
....@@ -114,12 +114,14 @@
114114
115115 public download(id: number) {
116116 let url = `${this.resource}/${id}/download`;
117
- return this.http.get(url).map((response : Response) => {
118
- let filename = JSON.parse(response.headers.get('Content-Disposition').match(/".*"$/g)[0]);
119
- let content = JSON.stringify(response.json(), null, 2);
120
- saveAs( new Blob([ content ], { type : 'application/octet-stream' }), filename);
121
- return Observable.of(true);
122
- }).catch(err => super.processErrorResponse(err));
117
+ return this.http.get(url, this.getAuthHeaders())
118
+ .map((response: Response) => {
119
+ let filename = JSON.parse(response.headers.get('Content-Disposition').match(/".*"$/g)[0]);
120
+ let content = JSON.stringify(response.json(), null, 2);
121
+ saveAs(new Blob([content], { type: 'application/octet-stream' }), filename);
122
+ return Observable.of(true);
123
+ })
124
+ .catch(err => super.processErrorResponse(err));
123125 }
124126
125127 public isActionAvailable(action:string, lic:any) {
securis/src/main/webapp/src/app/resources/organizations.ts
....@@ -1,6 +1,7 @@
11 import { Observable } from 'rxjs/Rx';
22 import { Injectable } from '@angular/core';
33 import { Http, RequestOptions } from '@angular/http';
4
+import { Locker } from 'angular-safeguard';
45 import { SeCurisResourceServices } from './base';
56 import { LocaleService } from '../common/i18n';
67
....@@ -13,8 +14,8 @@
1314 @Injectable()
1415 export class OrganizationsService extends SeCurisResourceServices {
1516
16
- constructor(http: Http, $L: LocaleService) {
17
- super($L, http, 'organization');
17
+ constructor(http: Http, $L: LocaleService, store: Locker) {
18
+ super($L, http, store, 'organization');
1819 }
1920
2021
securis/src/main/webapp/src/app/resources/packs.ts
....@@ -1,6 +1,7 @@
11 import { Observable } from 'rxjs/Rx';
22 import { Injectable } from '@angular/core';
33 import { Http, RequestOptions } from '@angular/http';
4
+import { Locker } from 'angular-safeguard';
45 import { SeCurisResourceServices, MySearchParams } from './base';
56 import { LocaleService } from '../common/i18n';
67
....@@ -82,19 +83,21 @@
8283
8384 @Injectable()
8485 export class PacksService extends SeCurisResourceServices {
85
- constructor(http: Http, $L: LocaleService) {
86
- super($L, http, 'pack');
86
+ constructor(http: Http, $L: LocaleService, store: Locker) {
87
+ super($L, http, store, 'pack');
8788 }
8889
8990 public get(filter?: PacksFilter | number | string) {
90
- if (!filter || typeof filter === "number" || typeof filter === "string") {
91
- return super.get(filter);
92
- }
93
- let searchParams = new MySearchParams(filter);
94
- let url = `${this.resource}/?${searchParams}`;
95
- return this.http.get(url).map(response => response.json()).catch(err => super.processErrorResponse(err));
96
- }
97
-
91
+ if (!filter || typeof filter === "number" || typeof filter === "string") {
92
+ return super.get(filter);
93
+ }
94
+ const searchParams = new MySearchParams(filter);
95
+ const url = `${this.resource}/?${searchParams}`;
96
+ // Añade las cabeceras usando el método de la base
97
+ return this.http.get(url, this.getAuthHeaders())
98
+ .map(response => response.json())
99
+ .catch(err => super.processErrorResponse(err));
100
+ }
98101
99102 public activate(id: number) {
100103 return super.action(id, "activate");
....@@ -108,12 +111,12 @@
108111 return super.action(id, "putonhold");
109112 }
110113 public nextLicCode(id: number) {
111
- let url = `pack/${id}/next_license_code`
112
- return this.http.get(url).map(response => response.text());
114
+ const url = `api/pack/${id}/next_license_code`;
115
+ return this.http.get(url, this.getAuthHeaders())
116
+ .map(response => response.text());
113117 }
114
-
115
-
116
- public isActionAvailable(action:string, pack:any) {
118
+
119
+ public isActionAvailable(action:string, pack:any) {
117120 var validStatuses = PACK_ACTIONS_BY_STATUS[action];
118121 return pack && validStatuses && validStatuses.indexOf(pack.status) !== -1;
119122 }
securis/src/main/webapp/src/app/resources/users.ts
....@@ -1,6 +1,7 @@
11 import { Observable } from 'rxjs/Rx';
22 import { Injectable } from '@angular/core';
33 import { Http, RequestOptions } from '@angular/http';
4
+import { Locker } from 'angular-safeguard';
45 import { SeCurisResourceServices } from './base';
56 import { LocaleService } from '../common/i18n';
67
....@@ -18,8 +19,8 @@
1819
1920 @Injectable()
2021 export class UsersService extends SeCurisResourceServices {
21
- constructor(http: Http, $L: LocaleService) {
22
- super($L, http, 'user');
22
+ constructor(http: Http, $L: LocaleService, store: Locker) {
23
+ super($L, http, store, 'user');
2324 }
2425
2526
securis/src/main/webapp/src/app/user.service.ts
....@@ -27,7 +27,7 @@
2727 params.append('username', username);
2828 params.append('password', password);
2929 let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })});
30
- return this.http.post('user/login', params.toString(), options)
30
+ return this.http.post('api/user/login', params.toString(), options)
3131 .map((resp) => this.mapLogin(resp))
3232 .catch((err) => super.processErrorResponse(err));
3333 }
....@@ -47,7 +47,7 @@
4747 }
4848 var token = this.store.get("token");
4949 let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) });
50
- return this.http.get('check', option)
50
+ return this.http.get('api/check', option)
5151 .map((resp) => this.mapCheck(resp))
5252 .catch((err) => super.processErrorResponse(err));
5353 }