Commit aee95e8d authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

throw exception when user not found

parent ddd46401
package com.telephoners.krakyournet.ctf.exceptions;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
public class UserNotFoundException extends WebApplicationException
{
public UserNotFoundException() {
super(Response.status(Response.Status.NOT_FOUND)
.entity("User not found.").type("text/plain").build());
}
}
......@@ -3,6 +3,7 @@ package com.telephoners.krakyournet.ctf.repositories;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.exceptions.UserNotFoundException;
import com.telephoners.krakyournet.ctf.providers.MessageDigestProvider;
import io.dropwizard.auth.basic.BasicCredentials;
import org.apache.commons.codec.binary.Hex;
......@@ -24,7 +25,10 @@ public class UsersRepository extends Repository<User>
{
return datastore.createQuery(User.class)
.field("name").equal(username)
.get();
.asList()
.stream()
.findFirst()
.orElseThrow(UserNotFoundException::new);
}
public User authenticateUser(BasicCredentials basicCredentials)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment