From 240332d5103cdc25036edffaf181953337b8e072 Mon Sep 17 00:00:00 2001 From: Alex Robin Date: Wed, 10 Jan 2024 10:38:17 +0100 Subject: [PATCH] [Core] Delay use of IUserRegistry since it may not be registered when HTTP server starts --- .../java/org/sensorhub/impl/service/HttpServer.java | 8 ++++---- .../org/sensorhub/impl/service/OshLoginService.java | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/sensorhub-core/src/main/java/org/sensorhub/impl/service/HttpServer.java b/sensorhub-core/src/main/java/org/sensorhub/impl/service/HttpServer.java index 20466540d..427a44431 100644 --- a/sensorhub-core/src/main/java/org/sensorhub/impl/service/HttpServer.java +++ b/sensorhub-core/src/main/java/org/sensorhub/impl/service/HttpServer.java @@ -40,7 +40,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.SslConnectionFactory; -import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker; +import org.eclipse.jetty.server.SymlinkAllowedResourceAliasChecker; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.server.handler.ResourceHandler; @@ -180,7 +180,7 @@ protected synchronized void doStart() throws SensorHubException fileResourceContext.setResourceBase(config.staticDocsRootDir); //fileResourceContext.clearAliasChecks(); - fileResourceContext.addAliasCheck(new AllowSymLinkAliasChecker()); + fileResourceContext.addAliasCheck(new SymlinkAllowedResourceAliasChecker(fileResourceContext)); handlers.addHandler(fileResourceContext); getLogger().info("Static resources root is " + config.staticDocsRootUrl); @@ -200,9 +200,9 @@ protected synchronized void doStart() throws SensorHubException { jettySecurityHandler = new ConstraintSecurityHandler(); - // load user list + // create login service connected to OSH security manager ISecurityManager securityManager = getParentHub().getSecurityManager(); - OshLoginService loginService = new OshLoginService(securityManager.getUserRegistry()); + OshLoginService loginService = new OshLoginService(securityManager); if (config.authMethod == AuthMethod.BASIC) jettySecurityHandler.setAuthenticator(new HttpLogoutWrapper(new BasicAuthenticator(), getLogger())); diff --git a/sensorhub-core/src/main/java/org/sensorhub/impl/service/OshLoginService.java b/sensorhub-core/src/main/java/org/sensorhub/impl/service/OshLoginService.java index a8cf5e70c..a287e422c 100644 --- a/sensorhub-core/src/main/java/org/sensorhub/impl/service/OshLoginService.java +++ b/sensorhub-core/src/main/java/org/sensorhub/impl/service/OshLoginService.java @@ -22,15 +22,14 @@ import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.UserIdentity; import org.eclipse.jetty.util.security.Credential; +import org.sensorhub.api.security.ISecurityManager; import org.sensorhub.api.security.IUserInfo; -import org.sensorhub.api.security.IUserRegistry; public class OshLoginService implements LoginService { + final ISecurityManager securityManager; IdentityService identityService = new DefaultIdentityService(); - IUserRegistry users; - //Map public static class UserPrincipal implements Principal @@ -73,9 +72,9 @@ public String getName() } - public OshLoginService(IUserRegistry users) + public OshLoginService(ISecurityManager securityManager) { - this.users = users; + this.securityManager = securityManager; } @@ -106,7 +105,7 @@ public UserIdentity login(String username, Object credentials, ServletRequest re isCert = true; } - IUserInfo user = users.get(username); + IUserInfo user = securityManager.getUserInfo(username); if (user == null) return null;