Commit 6ca9e4de authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

redeisgned auth

parent 8765dfc9
...@@ -121,11 +121,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> { ...@@ -121,11 +121,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
@Override @Override
public com.google.common.base.Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException { public com.google.common.base.Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException {
java.util.Optional<User> user = usersRepository.authenticateUser(credentials); User user = usersRepository.authenticateUser(credentials);
if (user.isPresent()) { return Optional.of(user);
return Optional.of(user.get());
}
return Optional.absent();
} }
} }
......
...@@ -2,12 +2,12 @@ package repositories; ...@@ -2,12 +2,12 @@ package repositories;
import io.dropwizard.auth.basic.BasicCredentials; import io.dropwizard.auth.basic.BasicCredentials;
import objects.User; import objects.User;
import org.apache.commons.codec.binary.Hex;
import org.mongodb.morphia.Datastore; import org.mongodb.morphia.Datastore;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* Created by gpietrus on 20.02.2016. * Created by gpietrus on 20.02.2016.
...@@ -39,23 +39,12 @@ public class UsersRepository implements Repository { ...@@ -39,23 +39,12 @@ public class UsersRepository implements Repository {
// return userOptional; // return userOptional;
// } // }
public Optional<User> authenticateUser(BasicCredentials basicCredentials) { public User authenticateUser(BasicCredentials basicCredentials) {
return datastore.createQuery(User.class)
.field("name").equal(basicCredentials.getUsername())
return null; .field("password").equal(Hex.encodeHexString(messageDigest.digest(basicCredentials.getPassword().getBytes())))
/* .get();
Optional<User> userOptional = teamsRepository.getAll()
.stream()
.map(Team::getMembers)
.flatMap(Collection::stream)
.filter(user -> {
return user.getName().equals(basicCredentials.getUsername()) &&
user.getPassword().equals(
Hex.encodeHexString(messageDigest.digest(basicCredentials.getPassword().getBytes()))); //todo
})
.findFirst();
return userOptional;*/
} }
@Override @Override
......
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