Commit 37e4655a authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

proxy pass user header

parent 8b9ef287
package api; package api;
import io.dropwizard.auth.Auth;
import objects.User;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
...@@ -19,8 +21,8 @@ import java.io.InputStream; ...@@ -19,8 +21,8 @@ import java.io.InputStream;
*/ */
@Path(value = "/proxy/task") @Path(value = "/proxy/task")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class ProxyResource public class ProxyResource {
{ /*
@GET @GET
@Path("{task_id}/{path: .*}") @Path("{task_id}/{path: .*}")
@Produces("text/html; charset=UTF-8") @Produces("text/html; charset=UTF-8")
...@@ -32,4 +34,19 @@ public class ProxyResource ...@@ -32,4 +34,19 @@ public class ProxyResource
HttpEntity entity = execute.getEntity(); HttpEntity entity = execute.getEntity();
return entity.getContent(); return entity.getContent();
} }
*/
@GET
@Path("{task_id}/{path: .*}")
@Produces("text/html; charset=UTF-8")
public InputStream task1(@Auth User user,
final @PathParam("task_id") String taskId,
final @PathParam("path") String path) throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://192.168.56.101/");
// HttpGet httpget = new HttpGet("http://http://192.168.56.101/" + taskId + "/" + path);
httpget.setHeader("CTF-User", user.getName());
CloseableHttpResponse execute = httpClient.execute(httpget);
HttpEntity entity = execute.getEntity();
return entity.getContent();
}
} }
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