Skip to content

Commit 47c2402

Browse files
committed
issue when starting sormas-rest
1 parent db84cc4 commit 47c2402

5 files changed

Lines changed: 94 additions & 15 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*******************************************************************************
2+
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
3+
* Copyright © 2016-2018 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*******************************************************************************/
18+
package de.symeda.sormas.api;
19+
20+
/**
21+
* This class hides the one in sormas-api.
22+
*
23+
* @deprecated FacadeProvider should not be used by the business logic because the facades can be accessed locally
24+
*/
25+
@Deprecated
26+
public final class FacadeProvider {
27+
28+
private FacadeProvider() {
29+
//NOOP
30+
}
31+
32+
public static void doNotUseInBackend() {
33+
throw new java.lang.IllegalStateException();
34+
}
35+
}

sormas-backend/src/main/java/de/symeda/sormas/backend/audit/AuditLoggerInterceptor.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.naming.InitialContext;
2525
import javax.naming.NamingException;
2626

27+
import de.symeda.sormas.backend.util.BackendFacadeProvider;
2728
import org.apache.commons.collections4.SetUtils;
2829
import org.hl7.fhir.r4.model.AuditEvent;
2930
import org.reflections.Reflections;
@@ -194,18 +195,8 @@ private Object backendAuditing(InvocationContext context, Method calledMethod) t
194195

195196
Date end = Calendar.getInstance(TimeZone.getDefault()).getTime();
196197

197-
getAuditLogger().logBackendCall(calledMethod, parameters, result, start, end);
198+
BackendFacadeProvider.getAuditLogger().logBackendCall(calledMethod, parameters, result, start, end);
198199
return result;
199200
}
200201

201-
private AuditLoggerEjb.AuditLoggerEjbLocal getAuditLogger() {
202-
try {
203-
InitialContext ctx = new InitialContext();
204-
// Use java:module for LOCAL lookup within same EJB module
205-
return (AuditLoggerEjb.AuditLoggerEjbLocal) ctx.lookup("java:module/AuditLoggerEjb");
206-
} catch (NamingException e) {
207-
throw new RuntimeException("Failed to lookup AuditLoggerEjb: " + e.getMessage(), e);
208-
}
209-
}
210-
211202
}

sormas-backend/src/main/java/de/symeda/sormas/backend/user/CurrentUserService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import de.symeda.sormas.backend.location.Location;
3131
import de.symeda.sormas.backend.util.ModelConstants;
3232

33-
@Stateless
33+
@Stateless(name = "CurrentUserService")
3434
@LocalBean
3535
@AuditIgnore
3636
public class CurrentUserService {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package de.symeda.sormas.backend.util;
2+
3+
import javax.naming.InitialContext;
4+
import javax.naming.NamingException;
5+
6+
import de.symeda.sormas.backend.audit.AuditLoggerEjb;
7+
import de.symeda.sormas.backend.user.CurrentUserService;
8+
9+
public class BackendFacadeProvider {
10+
11+
private final InitialContext ic;
12+
13+
private static volatile BackendFacadeProvider instance;
14+
15+
protected BackendFacadeProvider() {
16+
if (instance != null) {
17+
throw new IllegalStateException("BackendFacadeProvider instance already created");
18+
}
19+
20+
try {
21+
ic = new InitialContext();
22+
} catch (NamingException e) {
23+
throw new RuntimeException(e.getMessage(), e);
24+
}
25+
}
26+
27+
public static BackendFacadeProvider getInstance() {
28+
if (instance == null) {
29+
synchronized (BackendFacadeProvider.class) {
30+
if (instance == null) {
31+
instance = new BackendFacadeProvider();
32+
}
33+
}
34+
}
35+
return instance;
36+
}
37+
38+
public static AuditLoggerEjb.AuditLoggerEjbLocal getAuditLogger() {
39+
try {
40+
// Use java:module for LOCAL lookup within same EJB module
41+
return (AuditLoggerEjb.AuditLoggerEjbLocal) getInstance().ic.lookup("java:module/AuditLoggerEjb");
42+
} catch (NamingException e) {
43+
throw new RuntimeException("Failed to lookup AuditLoggerEjb: " + e.getMessage(), e);
44+
}
45+
}
46+
47+
public static CurrentUserService getCurrentUserService() {
48+
try {
49+
// Use java:module for LOCAL lookup within same EJB module
50+
return (CurrentUserService) getInstance().ic.lookup("java:module/CurrentUserService");
51+
} catch (NamingException e) {
52+
throw new RuntimeException("Failed to lookup AuditLoggerEjb: " + e.getMessage(), e);
53+
}
54+
}
55+
}

sormas-backend/src/main/java/de/symeda/sormas/backend/util/RightsAllowedInterceptor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public class RightsAllowedInterceptor {
4040

4141
@Resource
4242
private SessionContext sessionContext;
43-
@EJB
44-
private CurrentUserService currentUserService;
4543

4644
private final Logger logger = LoggerFactory.getLogger(getClass());
4745

@@ -92,7 +90,7 @@ public Object checkRightsAllowed(InvocationContext context) throws Exception {
9290
* 1. It's slow due to the same reason that lead us to implementing this
9391
* 2. It wouldn't work anyway, because roles need to be initialized by user any javax annotation (e.g. @DeclareRoles)
9492
*/
95-
} else if (currentUserService.hasUserRight(userRightValues.get(right))) {
93+
} else if (BackendFacadeProvider.getCurrentUserService().hasUserRight(userRightValues.get(right))) {
9694
hasAnyRight = true;
9795
break;
9896
}

0 commit comments

Comments
 (0)