0
0
Spring Bootframework~5 mins

Securing endpoints by role in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of securing endpoints by role in Spring Boot?
It restricts access to certain parts of an application based on the user's assigned roles, ensuring only authorized users can perform specific actions.
Click to reveal answer
beginner
Which annotation is commonly used in Spring Boot to specify role-based access on methods or endpoints?
The @PreAuthorize annotation is used to define role-based access rules on methods or endpoints.
Click to reveal answer
intermediate
How do you configure role-based access for HTTP endpoints in Spring Security?
You configure it in the SecurityFilterChain bean using authorizeHttpRequests() with matchers and hasRole() or hasAuthority() methods.
Click to reveal answer
intermediate
What is the difference between hasRole('ADMIN') and hasAuthority('ROLE_ADMIN') in Spring Security?
hasRole('ADMIN') automatically adds the prefix ROLE_, so it checks for ROLE_ADMIN. hasAuthority('ROLE_ADMIN') checks the exact authority string without adding a prefix.
Click to reveal answer
beginner
Why is it important to use role-based security instead of just authentication?
Authentication confirms who the user is, but role-based security controls what the user is allowed to do, protecting sensitive actions and data.
Click to reveal answer
Which Spring Security annotation restricts access to a method based on user roles?
A@RequestMapping
B@Autowired
C@PreAuthorize
D@Component
In Spring Security, what prefix does hasRole('USER') automatically add when checking authorities?
AROLE-
BROLE_
CAUTH_
DUSER_
Where do you typically configure HTTP endpoint security rules in Spring Boot?
AIn a SecurityFilterChain bean
BIn the main application class
CIn the Controller class
DIn the application.properties file
What happens if a user without the required role tries to access a secured endpoint?
AAccess is granted anyway
BUser is redirected to the homepage
CUser is automatically logged out
DAccess is denied with a 403 Forbidden response
Which method is used to specify role requirements for HTTP requests in Spring Security?
AauthorizeHttpRequests()
BconfigureHttp()
CsetRoles()
DenableSecurity()
Explain how to secure a REST endpoint in Spring Boot so only users with the ADMIN role can access it.
Think about configuring HTTP security with role checks.
You got /4 concepts.
    Describe the difference between authentication and role-based authorization in Spring Security.
    Consider what each step confirms about the user.
    You got /4 concepts.