Skip to content

The Unified and Autonomous Development Platform

feat: Able to access label spec resource without administrative permission (OD-2496)

Robin Shendfd5109a0a85
diff --git a/server-core/src/main/java/io/onedev/server/rest/resource/LabelSpecResource.java b/server-core/src/main/java/io/onedev/server/rest/resource/LabelSpecResource.java
index 9e8710b6d7..4104595fff 100644
--- a/server-core/src/main/java/io/onedev/server/rest/resource/LabelSpecResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/resource/LabelSpecResource.java
@@ -16,6 +16,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
@@ -48,8 +49,9 @@ public class LabelSpecResource {
@Path("/{labelSpecId}")
@GET
public LabelSpec getSpec(@PathParam("labelSpecId") Long labelSpecId) {
- if (!SecurityUtils.isAdministrator())
- throw new UnauthorizedException();
+ if (SecurityUtils.getAuthUser() == null)
+ throw new UnauthenticatedException();
+
return labelSpecManager.load(labelSpecId);
}
@@ -58,9 +60,9 @@ public class LabelSpecResource {
public List<LabelSpec> querySpecs(@QueryParam("name") String name,
@QueryParam("offset") @Api(example="0") int offset,
@QueryParam("count") @Api(example="100") int count) {
- if (!SecurityUtils.isAdministrator())
- throw new UnauthorizedException();
-
+ if (SecurityUtils.getAuthUser() == null)
+ throw new UnauthenticatedException();
+
EntityCriteria<LabelSpec> criteria = EntityCriteria.of(LabelSpec.class);
if (name != null)
criteria.add(Restrictions.ilike("name", name.replace('*', '%'), MatchMode.EXACT));
diff --git a/server-core/src/main/java/io/onedev/server/rest/resource/RoleResource.java b/server-core/src/main/java/io/onedev/server/rest/resource/RoleResource.java
index e9f20eff2a..42d192d92d 100644
--- a/server-core/src/main/java/io/onedev/server/rest/resource/RoleResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/resource/RoleResource.java
@@ -17,6 +17,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
@@ -78,6 +79,9 @@ public class RoleResource {
@Path("/ids/{name}")
@GET
public Long getRoleId(@PathParam("name") String name) {
+ if (SecurityUtils.getAuthUser() == null)
+ throw new UnauthenticatedException();
+
var role = roleManager.find(name);
if (role != null)
return role.getId();
diff --git a/server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java b/server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java
index a1f58afeca..e1c97f3857 100644
--- a/server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java
@@ -32,6 +32,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.shiro.authc.credential.PasswordService;
+import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.commons.utils.ExplicitException;
@@ -314,6 +315,9 @@ public class UserResource {
@Path("/ids/{name}")
@GET
public Long getUserId(@PathParam("name") @Api(description = "Login name of user") String name) {
+ if (SecurityUtils.getAuthUser() == null)
+ throw new UnauthenticatedException();
+
var user = userManager.findByName(name);
if (user != null)
return user.getId();