use of javax.servlet.ServletRequest in project lucene-solr by apache.
the class PKIAuthenticationIntegrationTest method testPkiAuth.
@Test
public void testPkiAuth() throws Exception {
CollectionAdminRequest.createCollection("collection", "conf", 2, 1).process(cluster.getSolrClient());
// TODO make a SolrJ helper class for this
byte[] bytes = Utils.toJSON(makeMap("authorization", singletonMap("class", MockAuthorizationPlugin.class.getName()), "authentication", singletonMap("class", MockAuthenticationPlugin.class.getName())));
zkClient().setData(ZkStateReader.SOLR_SECURITY_CONF_PATH, bytes, true);
HttpClient httpClient = cluster.getSolrClient().getHttpClient();
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
String baseUrl = jetty.getBaseUrl().toString();
verifySecurityStatus(httpClient, baseUrl + "/admin/authorization", "authorization/class", MockAuthorizationPlugin.class.getName(), 20);
verifySecurityStatus(httpClient, baseUrl + "/admin/authentication", "authentication.enabled", "true", 20);
}
log.info("Starting test");
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("q", "*:*");
params.add("__user", "solr");
params.add("__pwd", "SolrRocks");
// This should work fine.
final AtomicInteger count = new AtomicInteger();
MockAuthorizationPlugin.predicate = new Predicate<AuthorizationContext>() {
@Override
public boolean test(AuthorizationContext context) {
if ("/select".equals(context.getResource())) {
Principal principal = context.getUserPrincipal();
log.info("principalIs : {}", principal);
if (principal != null && principal.getName().equals("solr")) {
count.incrementAndGet();
}
}
return true;
}
};
MockAuthenticationPlugin.predicate = new Predicate<ServletRequest>() {
@Override
public boolean test(ServletRequest servletRequest) {
String s = ((HttpServletRequest) servletRequest).getQueryString();
if (s != null && s.contains("__user=solr") && s.contains("__pwd=SolrRocks")) {
servletRequest.setAttribute(Principal.class.getName(), "solr");
}
return true;
}
};
QueryRequest query = new QueryRequest(params);
query.process(cluster.getSolrClient(), "collection");
assertTrue("all nodes must get the user solr , no:of nodes got solr : " + count.get(), count.get() > 2);
}
use of javax.servlet.ServletRequest in project lucene-solr by apache.
the class MockAuthenticationPlugin method doAuthenticate.
@Override
public boolean doAuthenticate(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
String user = null;
if (predicate != null) {
if (predicate.test(request)) {
user = (String) request.getAttribute(Principal.class.getName());
request.removeAttribute(Principal.class.getName());
}
}
final FilterChain ffc = filterChain;
final AtomicBoolean requestContinues = new AtomicBoolean(false);
forward(user, request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException {
ffc.doFilter(req, res);
requestContinues.set(true);
}
});
return requestContinues.get();
}
use of javax.servlet.ServletRequest in project sling by apache.
the class ExternalServletContextWrapperTest method testUnwrappingWrappedSlingRequest.
/**
* Unwrapping a wrapped sling request should return the first-level request
* wrapped by the sling request.
*/
@Test
public void testUnwrappingWrappedSlingRequest() {
final HttpServletRequest req = context.mock(HttpServletRequest.class);
context.checking(new Expectations() {
{
allowing(req).getServletPath();
will(returnValue("/"));
allowing(req).getPathInfo();
will(returnValue("/test"));
}
});
final HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(req);
final HttpServletRequestWrapper wrapper2 = new HttpServletRequestWrapper(wrapper);
final SlingHttpServletRequestImpl slingRequest = new SlingHttpServletRequestImpl(null, wrapper2);
final HttpServletRequestWrapper slingWrapper = new HttpServletRequestWrapper(slingRequest);
ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(slingWrapper);
assertEquals(wrapper2, unwrapped);
}
use of javax.servlet.ServletRequest in project sling by apache.
the class ExternalServletContextWrapperTest method testUnwrappingWrappedRequest.
/**
* Unwrapping a wrapper request should return in the request.
*/
@Test
public void testUnwrappingWrappedRequest() {
final ServletRequest req = context.mock(ServletRequest.class);
final ServletRequestWrapper wrapper = new ServletRequestWrapper(req);
ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(wrapper);
assertEquals(req, unwrapped);
}
use of javax.servlet.ServletRequest in project sling by apache.
the class ExternalServletContextWrapperTest method testUnwrappingDoubleWrappedRequest.
@Test
public void testUnwrappingDoubleWrappedRequest() {
final ServletRequest req = context.mock(ServletRequest.class);
final ServletRequestWrapper wrapper = new ServletRequestWrapper(req);
final ServletRequestWrapper wrapper2 = new ServletRequestWrapper(wrapper);
ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(wrapper2);
assertEquals(req, unwrapped);
}
Aggregations