From 8ec7c4edea3a30b0c1a9134d8360d1e781e2915c Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 19 Nov 2023 07:57:23 -0800 Subject: [PATCH] Move couple of classes to services Improve label security. --- .../com/wisemapping/config/MethodSecurityConfig.java | 1 - .../java/com/wisemapping/service/LabelServiceImpl.java | 10 ++++++++-- .../java/com/wisemapping/service/RecaptchaService.java | 8 +++++++- .../com/wisemapping/util/VelocityEngineWrapper.java | 2 ++ .../src/main/webapp/WEB-INF/wisemapping-service.xml | 10 ---------- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/config/MethodSecurityConfig.java b/wise-webapp/src/main/java/com/wisemapping/config/MethodSecurityConfig.java index 5e7d328b..c046f169 100644 --- a/wise-webapp/src/main/java/com/wisemapping/config/MethodSecurityConfig.java +++ b/wise-webapp/src/main/java/com/wisemapping/config/MethodSecurityConfig.java @@ -12,7 +12,6 @@ import org.springframework.security.config.annotation.method.configuration.Enabl @Configuration @EnableMethodSecurity( - prePostEnabled = true, securedEnabled = true, jsr250Enabled = true) public class MethodSecurityConfig { diff --git a/wise-webapp/src/main/java/com/wisemapping/service/LabelServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/LabelServiceImpl.java index daaa0c9b..c152b3da 100644 --- a/wise-webapp/src/main/java/com/wisemapping/service/LabelServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/LabelServiceImpl.java @@ -24,6 +24,7 @@ import com.wisemapping.model.User; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +39,8 @@ public class LabelServiceImpl implements LabelService { private LabelManager labelManager; @Override - public void addLabel(@NotNull final Label label, @NotNull final User user) throws WiseMappingException { + @PreAuthorize("hasAnyRole('USER', 'ADMIN') && hasPermission(#user, 'WRITE')") + public void addLabel(@NotNull final Label label, @NotNull final User user) { label.setCreator(user); labelManager.addLabel(label); @@ -46,22 +48,26 @@ public class LabelServiceImpl implements LabelService { @NotNull @Override + @PreAuthorize("hasAnyRole('USER', 'ADMIN') && hasPermission(#user, 'READ')") public List