Slide 58
Slide 58 text
l
63
JJUG CCC 2019 Spring #ccc_a1
public class AuthenticateInterceptor implements ServerInterceptor {
@Override
public Listener interceptCall(ServerCall call, Metadata headers,
ServerCallHandler next) {
var cred = headers.keys().stream().filter(k -> k.equals(“cred”)).findFirst().get(); // Metadata &
boolean ok = cred.equals(“password”); // '(,
return new ForwardingServerCallListener
.SimpleForwardingServerCallListener(next.startCall(call, headers)) {
@Override // %$ ,
)
public void onMessage(ReqT message) {
if (ok) { // '(OK,#
super.onMessage(message);
} else { // '(NG
"+/
Status status = Status.UNAUTHENTICATED; // '(NG
var metadata = new Metadata();
metadata.put( // 0.
-
Metadata.Key.of(“error_detail”, Metadata.ASCII_STRING_MARSHALLER), “cred invalid”);
call.close(status, metadata); // close RPC+/*! Status, Metadata
"
}
}