Skip to content
Snippets Groups Projects
Verified Commit 36cfdfc3 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Handle logout

parent d4cdc595
Branches
Tags
2 merge requests!58REL: prepare release 0.7.2,!45F grpc f acm
Pipeline #16253 passed
...@@ -50,6 +50,12 @@ public class AuthInterceptor implements ServerInterceptor { ...@@ -50,6 +50,12 @@ public class AuthInterceptor implements ServerInterceptor {
Pattern.compile("^\\s*" + AuthenticationUtils.SESSION_TOKEN_COOKIE + "\\s*=\\s*"); Pattern.compile("^\\s*" + AuthenticationUtils.SESSION_TOKEN_COOKIE + "\\s*=\\s*");
public static final Predicate<String> SESSION_TOKEN_COOKIE_PREFIX_PREDICATE = public static final Predicate<String> SESSION_TOKEN_COOKIE_PREFIX_PREDICATE =
SESSION_TOKEN_COOKIE_PREFIX_PATTERN.asPredicate(); SESSION_TOKEN_COOKIE_PREFIX_PATTERN.asPredicate();
public final Metadata expiredSessionMetadata() {
Metadata metadata = new Metadata();
metadata.put(CookieSetter.SET_COOKIE, CookieSetter.EXPIRED_SESSION_COOKIE);
return metadata;
}
/** /**
* A no-op listener. This class is used for failed authentications. We couldn't return a null * A no-op listener. This class is used for failed authentications. We couldn't return a null
* instead because the documentation of the {@link ServerInterceptor} explicitely forbids it. * instead because the documentation of the {@link ServerInterceptor} explicitely forbids it.
...@@ -107,7 +113,7 @@ public class AuthInterceptor implements ServerInterceptor { ...@@ -107,7 +113,7 @@ public class AuthInterceptor implements ServerInterceptor {
} else { } else {
status = Status.UNAUTHENTICATED.withDescription("Unsupported authentication scheme."); status = Status.UNAUTHENTICATED.withDescription("Unsupported authentication scheme.");
} }
call.close(status, new Metadata()); call.close(status, expiredSessionMetadata());
return new NoOpListener<ReqT>(); return new NoOpListener<ReqT>();
} }
...@@ -130,7 +136,7 @@ public class AuthInterceptor implements ServerInterceptor { ...@@ -130,7 +136,7 @@ public class AuthInterceptor implements ServerInterceptor {
final Status status = final Status status =
Status.UNAUTHENTICATED.withDescription( Status.UNAUTHENTICATED.withDescription(
"Authentication failed. SessionToken was invalid."); "Authentication failed. SessionToken was invalid.");
call.close(status, new Metadata()); call.close(status, expiredSessionMetadata());
return new NoOpListener<ReqT>(); return new NoOpListener<ReqT>();
} }
} }
...@@ -160,7 +166,7 @@ public class AuthInterceptor implements ServerInterceptor { ...@@ -160,7 +166,7 @@ public class AuthInterceptor implements ServerInterceptor {
final Status status = final Status status =
Status.UNAUTHENTICATED.withDescription( Status.UNAUTHENTICATED.withDescription(
"Authentication failed. Username or password wrong."); "Authentication failed. Username or password wrong.");
call.close(status, new Metadata()); call.close(status, expiredSessionMetadata());
return new NoOpListener<ReqT>(); return new NoOpListener<ReqT>();
} }
} }
...@@ -203,7 +209,10 @@ public class AuthInterceptor implements ServerInterceptor { ...@@ -203,7 +209,10 @@ public class AuthInterceptor implements ServerInterceptor {
final class CookieSetter<ReqT, RespT> final class CookieSetter<ReqT, RespT>
extends ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT> { extends ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT> {
private static final Key<String> SET_COOKIE = public static final String EXPIRED_SESSION_COOKIE =
AuthenticationUtils.SESSION_TOKEN_COOKIE
+ "=expired; Path=/; HttpOnly; SameSite=Strict; Max-Age=0";
public static final Key<String> SET_COOKIE =
Key.of("Set-Cookie", Metadata.ASCII_STRING_MARSHALLER); Key.of("Set-Cookie", Metadata.ASCII_STRING_MARSHALLER);
protected CookieSetter(ServerCall<ReqT, RespT> delegate) { protected CookieSetter(ServerCall<ReqT, RespT> delegate) {
...@@ -244,6 +253,8 @@ final class CookieSetter<ReqT, RespT> ...@@ -244,6 +253,8 @@ final class CookieSetter<ReqT, RespT>
+ getSessionTimeoutSeconds()); + getSessionTimeoutSeconds());
} }
} }
} else {
headers.put(SET_COOKIE, EXPIRED_SESSION_COOKIE);
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment