You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 23, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: src/main/doc/authenticationMechanism.asciidoc
+150Lines changed: 150 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -215,10 +215,160 @@ It MUST be possible for the definition of an _HttpAuthenticationMechanism_ to ex
215
215
216
216
The server MAY make available an _HttpAuthenticationMechanism_ other than one supplied by the application, and SHOULD provide configuration to allow control over whether a system _HttpAuthenticationMechanism_, or the application's, is chosen at runtime, when both are present. This enables an application to provide its own _HttpAuthenticationMechanism_, for use when the deployment environment is not configured with identity stores for authentication, while allowing the same application to be deployed, unchanged, in environments where authentication against known identity stores must be enforced.
217
217
218
+
=== Annotations and Built-In HttpAuthenticationMechanism Beans
219
+
220
+
A Java EE container MUST support built-in beans for the following _HttpAuthenticationMechanism_ types, to be made available via configuration:
221
+
222
+
* Basic - Authenticates according to the mechanism as described in 13.6.1 of the Servlet spec (HTTP Basic Authentication). See also RFC 2617. This bean is activated and configured via the _@BasicAuthenticationMechanismDefinition_ annotation.
223
+
* Form - Authenticates according to the mechanism as described in 13.6.3 of the Servlet spec (Form Based Authentication). This bean is activated and configured via the _@FormAuthenticationMechanismDefinition_ annotation.
224
+
* Custom Form - A variant on Form, with the difference that continuing the authentication dialog as described in Servlet 13.6.3 step 3, and further clarified in 13.6.3.1, does not happen by posting back to j_security_check, but by invoking _SecurityContext.authenticate_ with the credentials the application collected. This bean is activated and configured via the _@CustomFormAuthenticationMechanismDefinition_ annotation.
225
+
226
+
All of all these beans MUST have the qualifier @Default and the scope @ApplicationScoped, as defined by the CDI specification.
227
+
228
+
==== Implementation Notes ====
229
+
230
+
Implementations are NOT required to provide independent implementations of the above mentioned authentication mechanisms "Basic" and "Form", but are allowed, encouraged even, to use the above annotations as the annotation variant of the _login-config_ element as described by the Servlet spec 14.4 item 18, and additionally implement the described CDI beans as a wrapper or delegator to the existing Servlet based implementations of these mechanisms.
231
+
232
+
==== Custom Form Notes ====
233
+
234
+
The Custom Form variant is intended to align better with modern Java EE technologies such as CDI, Expression Language, Bean Validation and specifically JSF.
235
+
236
+
Below is an example showing how the mechanism can be used with those technologies.
The "Username" and "Password" inputs are bound via expression language to properties of a named CDI bean which can have bean validation constraints associated with them, for instance as in the example below:
267
+
268
+
[source,java]
269
+
----
270
+
@Named
271
+
@RequestScoped
272
+
public class LoginBacking {
273
+
274
+
@NotNull
275
+
@Size(min = 3, max = 15, message="Username must be between 3 and 15 characters")
276
+
private String username;
277
+
278
+
@NotNull
279
+
@Size(min = 5, max = 50, message="Password must be between 5 and 50 characters")
280
+
private String password;
281
+
282
+
// ...
283
+
}
284
+
----
285
+
286
+
The authentication dialog can then be continued as shown in the example below:
287
+
288
+
[source,java]
289
+
----
290
+
@Inject
291
+
private SecurityContext securityContext;
292
+
293
+
@Inject
294
+
private FacesContext facesContext;
295
+
296
+
public void login() {
297
+
298
+
Credential credential = new UsernamePasswordCredential(username, new Password(password));
299
+
300
+
AuthenticationStatus status = securityContext.authenticate(
301
+
getRequest(facesContext),
302
+
getResponse(facesContext),
303
+
withParams()
304
+
.credential(credential));
305
+
306
+
if (status.equals(IN_PROGRESS)) {
307
+
facesContext.responseComplete();
308
+
} else if (status.equals(FAILURE)) {
309
+
addError(facesContext, "Authentication failed");
310
+
}
311
+
312
+
}
313
+
----
314
+
315
+
The annotations are defined as shown in the following sections.
316
+
317
+
==== Basic Annotation
318
+
319
+
[source,java]
320
+
----
321
+
@Retention(RUNTIME)
322
+
@Target(TYPE)
323
+
public @interface BasicAuthenticationMechanismDefinition {
324
+
325
+
/**
326
+
* Name of realm that will be send via the <code>WWW-Authenticate</code> header.
327
+
* <p>
328
+
* Note that contrary to what happens in some proprietary Servlet products, this
329
+
* realm name <b>does not</b> couple a named identity store configuration to the
330
+
* authentication mechanism.
331
+
*
332
+
* @return Name of realm
333
+
*/
334
+
String realmName() default "";
335
+
}
336
+
----
337
+
338
+
==== Form Annotation
339
+
340
+
[source,java]
341
+
----
342
+
@Retention(RUNTIME)
343
+
@Target(TYPE)
344
+
public @interface FormAuthenticationMechanismDefinition {
345
+
346
+
@Nonbinding
347
+
LoginToContinue loginToContinue();
348
+
349
+
}
350
+
----
351
+
352
+
==== Custom Form Annotation
353
+
354
+
[source,java]
355
+
----
356
+
@Retention(RUNTIME)
357
+
@Target(TYPE)
358
+
public @interface CustomFormAuthenticationMechanismDefinition {
359
+
360
+
@Nonbinding
361
+
LoginToContinue loginToContinue();
362
+
363
+
}
364
+
----
365
+
218
366
=== Relationship to other specifications
219
367
220
368
An _HttpAuthenticationMechanism_ is a CDI bean, as defined by the CDI (JSR 346) specification. The methods defined by the _HttpAuthenticationMechanism_ closely map to the methods and semantics of a _ServerAuthModule_ as defined by the Servlet Container Profile of the JASPIC (JSR 196) specification (but an _HttpAuthenticationMechanism_ is itself not a _ServerAuthModule_). The servlet container MUST use JASPIC mechanisms to arrange for an _HttpAuthenticationMechanism_ to be placed in service.
221
369
222
370
This specification mandates that when a _ServerAuthModule_ is called by the Servlet container, CDI services (such as the _BeanManager_) are fully available and all scopes that are defined to be active during the _service()_ method of a servlet, or during the _doFilter()_ method of servlet filter are active. Specifically this means that the request scope, session scope and application scope MUST be active, and that a _ServerAuthModule_ method such as _validateRequest_ MUST be capable of 1) obtaining a reference to the CDI _BeanManager_ via programmatic means (for example, by doing a JNDI lookup) and 2) can use this reference to obtain a valid request-scoped, session-scoped or application-scoped bean. This specification *does not* mandate that a _ServerAuthModule_ itself is a CDI bean or that a _ServerAuthModule_ is injectable.
223
371
224
372
An _HttpAuthenticationMechanism_ implementation is logically equivalent to a build-in authentication mechanism as defined by the Servlet spec, being HTTP Basic Authentication, HTTP Digest Authentication, Form Based Authentication and HTTPS Client Authentication, and more specifically is corresponding to an "additional container authentication mechanism" as described in section 13.6.5 of the Servlet spec.
373
+
374
+
The _Basic_ and _Form_ authentication mechanisms as defined by this specification are logically equivalent to the similarly named authentication mechanisms in the Servlet spec, respectively 13.6.1 - HTTP Basic Authentication and 13.6.3 - Form Based Authentication. Implementations are allowed to re-implement these authentication mechanisms for this specification, but are encouraged to re-use the existing Servlet implementation, for instance by wrapping these in the CDI bean required by this specification or delegating to them from that CDI bean.
0 commit comments