Authentication Boundaries

Authentication boundaries define how an API establishes the identity of a caller before permitting access to protected operations. A Java backend should verify credentials at the boundary and then pass trusted identity information to application logic.

Authentication answers “who is calling?” while authorization answers “what is that caller allowed to do?” An API boundary is the point where an incoming request is checked before protected application behavior runs.

Common mechanisms include sessions with cookies, API keys, and bearer tokens such as JWTs. The server should validate credentials using the appropriate authority, reject invalid or missing credentials, and avoid treating user-supplied identity fields as proof of identity.

In a Java application, authentication is commonly enforced through a security filter or framework layer before a controller executes. Once authentication succeeds, the application can obtain the authenticated principal and use it when making authorization decisions.

A good boundary also considers transport security and credential handling. Credentials should be sent over TLS, secrets should not be logged, and expired, malformed, or otherwise invalid credentials should fail closed rather than granting access.

Key points

Interview questions

What is authentication, and where should it happen in a Java API?

Authentication verifies the identity associated with an incoming request. It should normally happen before protected controller or business logic executes, such as in a security filter or framework-managed security layer. After successful authentication, the application can access the authenticated principal. Authorization can then decide whether that principal may perform the requested operation.

Why should an API not trust a userId supplied in the request body?

A request body is controlled by the caller, so a supplied user ID is not proof that the caller is that user. The server should derive the caller identity from successfully validated authentication credentials. It can then compare that identity with the requested resource or use it for authorization decisions. This prevents a caller from simply changing an identifier to act as another account.

What happens after authentication succeeds?

The security layer establishes an authenticated principal for the request. Application code can use that principal to make authorization decisions and to associate actions with the authenticated identity. Authentication alone does not imply unrestricted access. The required permissions, roles, scopes, or resource ownership still need to be checked.

What security properties should an API authentication boundary have?

It should validate credentials consistently before protected operations and fail closed when credentials are absent, invalid, or expired. Credentials should be protected in transit with TLS and should not appear in application logs or error messages. The design should also limit credential lifetime or scope where appropriate and provide a clear trust boundary between the security layer and business logic. Centralizing these checks reduces inconsistent security behavior across endpoints.