Spring Certified Professional 2023 · Free Practice Question Easy

Question 21

To enable annotation-based security, we need to add the _______ annotation on any @Configuration class.

  • A

    @SpringSecurity

  • B

    @EnableMethodSecurity

  • C

    @EnableApplicationSecurity

  • D

    @SecuredApplication

Reveal correct answer

Correct answer: B

Explanation

@EnableMethodSecurity

To enable annotation-based security, we need to add the @EnableMethodSecurity annotation on any @Configuration class. This is how our configuration class will look like:

Let’s look at a few important parameters of the @EnableMethodSecurity  annotation

  • securedEnabled – Determine if the @Security annotation should be enabled.

  • jsr250Enabled – Allow us to use JSR250-based annotation (e.g. @RoleAllowed).

  • prePostEnabled – Enable Spring’s pre/post annotations.


https://www.javadevjournal.com/spring-security/spring-method-security/


https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/method/configuration/EnableMethodSecurity.html

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need