100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Throw not found instead of forbidden for restricted/realm checks
Ekhorn38ecd2ee42e9
diff --git a/manager/src/main/java/org/openremote/manager/gateway/GatewayServiceResourceImpl.java b/manager/src/main/java/org/openremote/manager/gateway/GatewayServiceResourceImpl.javaindex fc44cbd26..0e2756908 100644--- a/manager/src/main/java/org/openremote/manager/gateway/GatewayServiceResourceImpl.java+++ b/manager/src/main/java/org/openremote/manager/gateway/GatewayServiceResourceImpl.java@@ -54,7 +54,7 @@ public class GatewayServiceResourceImpl extends ManagerWebResource}if (!isSuperUser() && !getAuthenticatedRealmName().equals(realm)) {- throw new WebApplicationException(Response.Status.FORBIDDEN);+ throw new WebApplicationException(Response.Status.NOT_FOUND);}Stream<GatewayTunnelInfo> tunnels =@@ -79,7 +79,7 @@ public class GatewayServiceResourceImpl extends ManagerWebResource}if (!isSuperUser() && !getAuthenticatedRealmName().equals(realm)) {- throw new WebApplicationException(Response.Status.FORBIDDEN);+ throw new WebApplicationException(Response.Status.NOT_FOUND);}if (TextUtil.isNullOrEmpty(gatewayID)) {@@ -87,7 +87,7 @@ public class GatewayServiceResourceImpl extends ManagerWebResource}if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), gatewayID)) {- throw new WebApplicationException(Response.Status.FORBIDDEN);+ throw new WebApplicationException(Response.Status.NOT_FOUND);}return gatewayService.getGatewayTunnelInfos(realm, gatewayID);@@ -101,7 +101,7 @@ public class GatewayServiceResourceImpl extends ManagerWebResource}if (!isSuperUser() && !getAuthenticatedRealmName().equals(realm)) {- throw new WebApplicationException(Response.Status.FORBIDDEN);+ throw new WebApplicationException(Response.Status.NOT_FOUND);}if (TextUtil.isNullOrEmpty(gatewayId)) {@@ -109,7 +109,7 @@ public class GatewayServiceResourceImpl extends ManagerWebResource}if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), gatewayId)) {- throw new WebApplicationException(Response.Status.FORBIDDEN);+ throw new WebApplicationException(Response.Status.NOT_FOUND);}return this.gatewayService.getTunnelInfos().stream()@@ -136,12 +136,12 @@ public class GatewayServiceResourceImpl extends ManagerWebResourceif (TextUtil.isNullOrEmpty(tunnelInfo.getRealm())) {tunnelInfo.setRealm(getAuthenticatedRealmName());} else if (!isSuperUser() && !tunnelInfo.getRealm().equals(getAuthenticatedRealmName())) {- throw new ForbiddenException();+ throw new WebApplicationException(Response.Status.NOT_FOUND);}if (isRestrictedUser()&& !assetStorageService.isUserAsset(getUserId(), tunnelInfo.getGatewayId())) {- throw new ForbiddenException();+ throw new WebApplicationException(Response.Status.NOT_FOUND);}try {@@ -168,12 +168,12 @@ public class GatewayServiceResourceImpl extends ManagerWebResourceif (TextUtil.isNullOrEmpty(tunnelInfo.getRealm())) {tunnelInfo.setRealm(getAuthenticatedRealmName());} else if (!isSuperUser() && !tunnelInfo.getRealm().equals(getAuthenticatedRealmName())) {- throw new ForbiddenException();+ throw new WebApplicationException(Response.Status.NOT_FOUND);}if (isRestrictedUser()&& !assetStorageService.isUserAsset(getUserId(), tunnelInfo.getGatewayId())) {- throw new ForbiddenException();+ throw new WebApplicationException(Response.Status.NOT_FOUND);}try {diff --git a/test/src/test/groovy/org/openremote/test/gateway/GatewayTunnelAuthorizationTest.groovy b/test/src/test/groovy/org/openremote/test/gateway/GatewayTunnelAuthorizationTest.groovyindex c53c5bf96..08e3b000a 100644--- a/test/src/test/groovy/org/openremote/test/gateway/GatewayTunnelAuthorizationTest.groovy+++ b/test/src/test/groovy/org/openremote/test/gateway/GatewayTunnelAuthorizationTest.groovy@@ -380,10 +380,10 @@ class GatewayTunnelAuthorizationTest extends Specification implements ManagerConresource.getActiveTunnelInfo(null, realm, gateway.id, "10.0.0.1", 22).id == sshTunnel.idand: "a gateway in the same realm that is not linked to them is refused"- refusalOf { resource.getGatewayActiveTunnelInfos(null, realm, otherGateway.id) } == 403- refusalOf { resource.getActiveTunnelInfo(null, realm, otherGateway.id, "10.0.0.1", 22) } == 403- refusalOf { resource.startTunnel(newTunnel(otherGateway.id)) } == 403- refusalOf { resource.stopTunnel(otherGatewayTunnel) } == 403+ refusalOf { resource.getGatewayActiveTunnelInfos(null, realm, otherGateway.id) } == 404+ refusalOf { resource.getActiveTunnelInfo(null, realm, otherGateway.id, "10.0.0.1", 22) } == 404+ refusalOf { resource.startTunnel(newTunnel(otherGateway.id)) } == 404+ refusalOf { resource.stopTunnel(otherGatewayTunnel) } == 404}def "A restricted user linked to no gateway retrieves no tunnels and reaches no gateway"() {@@ -395,10 +395,10 @@ class GatewayTunnelAuthorizationTest extends Specification implements ManagerConresource.getAllActiveTunnelInfos(null, realm).length == 0and: "every gateway is refused"- refusalOf { resource.getGatewayActiveTunnelInfos(null, realm, gateway.id) } == 403- refusalOf { resource.getActiveTunnelInfo(null, realm, gateway.id, "10.0.0.1", 22) } == 403- refusalOf { resource.startTunnel(newTunnel(gateway.id)) } == 403- refusalOf { resource.stopTunnel(sshTunnel) } == 403+ refusalOf { resource.getGatewayActiveTunnelInfos(null, realm, gateway.id) } == 404+ refusalOf { resource.getActiveTunnelInfo(null, realm, gateway.id, "10.0.0.1", 22) } == 404+ refusalOf { resource.startTunnel(newTunnel(gateway.id)) } == 404+ refusalOf { resource.stopTunnel(sshTunnel) } == 404and: "the gateway was never asked to open or close a tunnel"openRequests.isEmpty()@@ -414,11 +414,11 @@ class GatewayTunnelAuthorizationTest extends Specification implements ManagerConids(resources.superUser.getAllActiveTunnelInfos(null, otherRealm)) == ids(otherRealmTunnel)and: "the user is refused every request naming the other realm"- refusalOf { resource.getAllActiveTunnelInfos(null, otherRealm) } == 403- refusalOf { resource.getGatewayActiveTunnelInfos(null, otherRealm, gateway.id) } == 403- refusalOf { resource.getActiveTunnelInfo(null, otherRealm, gateway.id, "10.0.0.1", 22) } == 403- refusalOf { resource.startTunnel(newTunnel(gateway.id).setRealm(otherRealm)) } == 403- refusalOf { resource.stopTunnel(otherRealmTunnel) } == 403+ refusalOf { resource.getAllActiveTunnelInfos(null, otherRealm) } == 404+ refusalOf { resource.getGatewayActiveTunnelInfos(null, otherRealm, gateway.id) } == 404+ refusalOf { resource.getActiveTunnelInfo(null, otherRealm, gateway.id, "10.0.0.1", 22) } == 404+ refusalOf { resource.startTunnel(newTunnel(gateway.id).setRealm(otherRealm)) } == 404+ refusalOf { resource.stopTunnel(otherRealmTunnel) } == 404}def "#user opens and closes a tunnel through the gateway"() {