How use security for protect some methods?

Hello everyone! I have Vaadin 24 and VaadinWebSecurity. How I can protect some methods? Annotation @RolesAllowed(“…”) work only with classes, right?

You can use this annotation @EnableMethodSecurityhttps://www.baeldung.com/spring-enablemethodsecurity At the end you will probably need to check by code (for example if this method is allowed then create or show a button)

@reliable-narwhal, out of curiosity: what is your case (aka what are you trying to achieve)?

(I’m asking in case we can improve the API of the Vaadin security helpers)

@practical-rat hello! I want user with role “READER” can’t execute the method “save()” on button “Save”. Now I use the trick: get role from security context and hide button.

That sounds like a way better version. For a user it’s not really convenient to see a button that he isn’t allowed to press :wink: