blob: 845d9aeb5e8f6ca7f5b95275b97fe93d744ba89b [file] [log] [blame]
margaretha56e8e552017-12-05 16:31:21 +01001package de.ids_mannheim.korap.authentication.http;
2
margaretha2afb97d2017-12-07 19:18:44 +01003import java.util.EnumSet;
4
margaretha56e8e552017-12-05 16:31:21 +01005import javax.ws.rs.core.HttpHeaders;
6import javax.ws.rs.core.Response;
margaretha2afb97d2017-12-07 19:18:44 +01007import javax.ws.rs.core.Response.ResponseBuilder;
margaretha56e8e552017-12-05 16:31:21 +01008
margaretha56e8e552017-12-05 16:31:21 +01009import org.springframework.stereotype.Component;
10
margaretha0e8f4e72018-04-05 14:11:52 +020011import de.ids_mannheim.korap.constant.AuthenticationScheme;
margaretha56e8e552017-12-05 16:31:21 +010012
13/** Implementation of HTTP authentication scheme (see RFC 7253 and 7617)
14 * for server creating responses with status 401 Unauthorized and
15 * WWW-Authenticate header to unauthenticated requests.
16 *
17 * @author margaretha
18 *
19 */
20@Component
21public class HttpUnauthorizedHandler {
margaretha56e8e552017-12-05 16:31:21 +010022
23 public Response createUnauthenticatedResponse (String notification) {
margaretha2afb97d2017-12-07 19:18:44 +010024 ResponseBuilder builder = Response.status(Response.Status.UNAUTHORIZED);
25
26 for (AuthenticationScheme s : EnumSet
27 .allOf(AuthenticationScheme.class)) {
28 builder = builder.header(HttpHeaders.WWW_AUTHENTICATE,
29 s.displayName() + " realm=\"Kustvakt\"");
30 }
31
32 return builder.entity(notification).build();
margaretha56e8e552017-12-05 16:31:21 +010033 }
34}