Spring Security Basics — Interview Answer — Spring Technical Interview Questions & Answers

Model answer covering authentication vs authorization.

Spring Security Basics — Interview Answer

  • Model answer: Spring Security handles authentication and authorization.
  • Authentication proves identity; authorization checks permissions.
  • starter-security adds filter-based protection to HTTP requests.
  • I configure which URLs are public and which need roles.
  • Keep AuthN vs AuthZ crystal clear.

Technical Interview Tip: Two definitions + filters protect endpoints.

Code Examples for Spring Security Basics — Interview Answer

Spring Security Basics — Interview Answer — working example

// spring-boot-starter-security
// Example idea: permit health + auth, require auth elsewhere

@RestController
@RequestMapping("/api/auth")
class AuthController {
  @PostMapping("/login")
  Map<String, String> login(@RequestBody LoginRequest req) {
    // validate → return token
    return Map.of("token", "demo-jwt");
  }
}

// SecurityFilterChain bean configures authorizeHttpRequests + CSRF for APIs

Spring Security Basics — Interview Answer — spring Security filters the request chain; APIs often use token auth and disable browser CSRF patterns.

How to Explain Spring Security Basics — Interview Answer to an Interviewer

What is Security Basics — Interview Answer (sb)?

Used for protect /admin a Boot API Not just the heading

Give one small example of Security Basics — Interview Answer (sb).

SecurityFilterChain + roles Model answer covering authentication vs authorization

What mistake do beginners make with Security Basics — Interview Answer (sb)?

leaving actuator open Show the fix

Where do you use Security Basics — Interview Answer (sb)?

a Boot API protect /admin