From 66825c9a0e873ec055d9104d0c0cad580cb590d1 Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 1 Oct 2021 18:52:32 +0200 Subject: [PATCH] Created the ResponderAuthentication to authenticate a specific request --- .../ResponderAuthentication.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/de/gnmyt/autoresponder/authentication/ResponderAuthentication.java diff --git a/src/main/java/de/gnmyt/autoresponder/authentication/ResponderAuthentication.java b/src/main/java/de/gnmyt/autoresponder/authentication/ResponderAuthentication.java new file mode 100644 index 0000000..05a7c14 --- /dev/null +++ b/src/main/java/de/gnmyt/autoresponder/authentication/ResponderAuthentication.java @@ -0,0 +1,30 @@ +package de.gnmyt.autoresponder.authentication; + +import com.sun.net.httpserver.BasicAuthenticator; + +public class ResponderAuthentication extends BasicAuthenticator { + + private final AuthenticationDetails details; + + /** + * Constructor of the {@link ResponderAuthentication} + * + * @param details Your authentication details from the {@link de.gnmyt.autoresponder.SimpleAutoResponder} + */ + public ResponderAuthentication(AuthenticationDetails details) { + super("/"); + this.details = details; + } + + /** + * Checks the credentials of the request + * + * @param username The name of the user from the request + * @param password The password of the user from the request + * @return true if the provided credentials are correct, otherwise false + */ + @Override + public boolean checkCredentials(String username, String password) { + return details.getUsername().equals(username) && details.getPassword().equals(password); + } +}