mitre / mitre/HTTP-Proxy-Servlet
Basic Auth support
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.5k
- Forks
- 557
- PR merge metrics
- No merged PRs in 30d
Description
Just sharing solution which I implemented for basic auth.
package com.kegs.v4.custom;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.mitre.dsmiley.httpproxy.ProxyServlet;
import javax.servlet.ServletException;
public class HttpBasicAuthProxyServlet extends ProxyServlet {
protected static final String P_AUTH_BASIC_USERNAME = "authBasicUsername";
protected static final String P_AUTH_BASIC_PASSWORD = "authBasicPassword";
private String authBasicPassword;
private String authBasicUsername;
@Override
public void init() throws ServletException {
String doLogStr = getServletConfig().getInitParameter(P_LOG);
if (doLogStr != null) {
this.doLog = Boolean.parseBoolean(doLogStr);
}
String doForwardIPString = getServletConfig().getInitParameter(P_FORWARDEDFOR);
if (doForwardIPString != null) {
this.doForwardIP = Boolean.parseBoolean(doForwardIPString);
}
initAuthBasic();
initTarget();
proxyClient = createHttpClient();
}
private void initAuthBasic() throws ServletException{
authBasicPassword = getServletConfig().getInitParameter(P_AUTH_BASIC_PASSWORD);
authBasicUsername = getServletConfig().getInitParameter(P_AUTH_BASIC_USERNAME);
if (authBasicPassword == null) {
throw new ServletException(P_AUTH_BASIC_PASSWORD+" is required.");
}
if (authBasicUsername == null) {
throw new ServletException(P_AUTH_BASIC_USERNAME+" is required.");
}
}
protected HttpClient createHttpClient() {
BasicCredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(authBasicUsername, authBasicPassword);
provider.setCredentials(AuthScope.ANY, credentials);
RequestConfig requestConfig = RequestConfig.custom().setRedirectsEnabled(true).build();
HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).setDefaultCredentialsProvider(provider).build();
return client;
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is named. Start by reading the existing ProxyServlet initialization and HTTP-client creation entry points, then compare them with the supplied HttpBasicAuthProxyServlet example. The issue does not state a test or explicit completion criterion, so the expected integration and verification still need clarification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100