Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass request into ProxyAuthenticator #361

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/main/java/org/littleshoot/proxy/ProxyAuthenticator.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package org.littleshoot.proxy;

import io.netty.handler.codec.http.HttpRequest;

/**
* Interface for objects that can authenticate someone for using our Proxy on
* the basis of a username and password.
*/
public interface ProxyAuthenticator {
/**
* Authenticates the user using the specified userName and password.
*
*
* @param userName
* The user name.
* @param password
* The password.
* @return <code>true</code> if the credentials are acceptable, otherwise
* <code>false</code>.
*/
boolean authenticate(String userName, String password);
boolean authenticate(String userName, String password, HttpRequest httpRequest);

/**
* The realm value to be used in the request for proxy authentication
* The realm value to be used in the request for proxy authentication
* ("Proxy-Authenticate" header). Returning null will cause the string
* "Restricted Files" to be used by default.
*
*
* @return
*/
String getRealm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ private boolean authenticationRequired(HttpRequest request) {

String userName = StringUtils.substringBefore(decodedString, ":");
String password = StringUtils.substringAfter(decodedString, ":");
if (!authenticator.authenticate(userName, password)) {
if (!authenticator.authenticate(userName, password, request)) {
writeAuthenticationRequired(authenticator.getRealm());
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.littleshoot.proxy;

import io.netty.handler.codec.http.HttpRequest;

/**
* Tests a single proxy that requires username/password authentication.
*/
Expand All @@ -24,7 +26,7 @@ protected String getPassword() {
}

@Override
public boolean authenticate(String userName, String password) {
public boolean authenticate(String userName, String password, HttpRequest httpRequest) {
return getUsername().equals(userName) && getPassword().equals(password);
}

Expand Down