C. The user can access the page without restrictions.
D. The application will crash with an exception.
Solution
Step 1: Analyze the role restriction
The config restricts URLs starting with /admin/ to users with ADMIN role only.
Step 2: Understand unauthorized access behavior
Users without ADMIN role get a 403 Forbidden error, not redirected or crash.
Final Answer:
The user will get a 403 Forbidden error. -> Option B
Quick Check:
Unauthorized access = 403 error [OK]
Hint: No role match means 403 Forbidden error [OK]
Common Mistakes:
Thinking unauthorized users get redirected automatically
Assuming unrestricted access
Expecting application crash on access denial
4. Identify the error in this Spring Security method-level authorization code:
@Secured("USER")
public String getUserData() {
return "data";
}
medium
A. The role name should be prefixed with 'ROLE_'.
B. The method must return void for @Secured.
C. The annotation should be @Autowired instead of @Secured.
D. The method name cannot be getUserData.
Solution
Step 1: Check role naming convention
Spring Security expects roles to be prefixed with 'ROLE_', so "USER" should be "ROLE_USER".
Step 2: Validate other options
Return type can be String, @Autowired is unrelated, method name is valid.
Final Answer:
The role name should be prefixed with 'ROLE_'. -> Option A
Quick Check:
Role prefix 'ROLE_' required [OK]
Hint: Always prefix roles with 'ROLE_' in @Secured [OK]
Common Mistakes:
Omitting 'ROLE_' prefix in role names
Confusing @Secured with dependency injection
Thinking method name affects authorization
5. You want to allow only users with roles ADMIN or MANAGER to access a sensitive endpoint in Spring Boot. Which configuration snippet correctly implements this authorization rule?
A)