Implement Authentication Filter (2.1.3.3)

This commit is contained in:
2021-04-29 17:37:23 +02:00
parent 1e96417a3f
commit 1363e83aa3
7 changed files with 161 additions and 8 deletions
@@ -7,7 +7,6 @@ import dst.ass2.service.auth.client.AuthenticationClientProperties;
import dst.ass2.service.auth.client.IAuthenticationClient;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;
public class GrpcAuthenticationClient implements IAuthenticationClient {
private final ManagedChannel channel;
@@ -23,10 +22,10 @@ public class GrpcAuthenticationClient implements IAuthenticationClient {
AuthenticationRequest request = AuthenticationRequest.newBuilder().setEmail(email).setPassword(password).build();
AuthenticationResponse response = blockingStub.authenticate(request);
if(response.getStatus().startsWith("NoSuchUserException"))
if(response.getStatus().contains("NoSuchUserException"))
throw new NoSuchUserException("User with email " + email + " could not be found");
if(response.getStatus().startsWith("AuthenticationException"))
if(response.getStatus().contains("AuthenticationException"))
throw new AuthenticationException("Password for user with email " + email + " was incorrect");
return response.getToken();