Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

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.java
index 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 ManagerWebResource
if (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 ManagerWebResource
if (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.groovy
index 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 ManagerCon
resource.getActiveTunnelInfo(null, realm, gateway.id, "10.0.0.1", 22).id == sshTunnel.id
and: "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 ManagerCon
resource.getAllActiveTunnelInfos(null, realm).length == 0
and: "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) } == 404
and: "the gateway was never asked to open or close a tunnel"
openRequests.isEmpty()
@@ -414,11 +414,11 @@ class GatewayTunnelAuthorizationTest extends Specification implements ManagerCon
ids(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"() {