use of jakarta.servlet.http.HttpServletResponse in project atmosphere by Atmosphere.
the class MeteorTest method testMeteor.
@Test
public void testMeteor() throws IOException, ServletException {
final AtomicReference<Meteor> meteor = new AtomicReference<Meteor>();
final Servlet s = new HttpServlet() {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
meteor.set(Meteor.lookup(req));
}
};
framework.addAtmosphereHandler("/a", new ReflectorServletProcessor(s));
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
framework.interceptor(new AtmosphereInterceptorAdapter() {
@Override
public Action inspect(AtmosphereResource r) {
Meteor m = Meteor.build(r.getRequest());
return Action.CONTINUE;
}
});
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertNotNull(meteor.get());
}
use of jakarta.servlet.http.HttpServletResponse in project atmosphere by Atmosphere.
the class MeteorTest method testMeteorNull.
@Test
public void testMeteorNull() throws IOException, ServletException {
final AtomicReference<Meteor> meteor = new AtomicReference<Meteor>();
final Servlet s = new HttpServlet() {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
meteor.set(Meteor.lookup(req));
}
};
framework.addAtmosphereHandler("/a", new ReflectorServletProcessor(s));
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
framework.interceptor(new AtmosphereInterceptorAdapter() {
@Override
public Action inspect(AtmosphereResource r) {
return Action.CONTINUE;
}
});
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertNull(meteor.get());
}
use of jakarta.servlet.http.HttpServletResponse in project spring-security by spring-projects.
the class Saml2WebSsoAuthenticationRequestFilterTests method setup.
@BeforeEach
public void setup() {
this.filter = new Saml2WebSsoAuthenticationRequestFilter(this.resolver, this.factory);
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
this.request.setPathInfo("/saml2/authenticate/registration-id");
this.filterChain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) {
((HttpServletResponse) response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
};
this.rpBuilder = RelyingPartyRegistration.withRegistrationId("registration-id").providerDetails((c) -> c.entityId("idp-entity-id")).providerDetails((c) -> c.webSsoUrl(IDP_SSO_URL)).assertionConsumerServiceUrlTemplate("template").credentials((c) -> c.add(TestSaml2X509Credentials.assertingPartyPrivateCredential()));
this.filter.setAuthenticationRequestRepository(this.authenticationRequestRepository);
}
use of jakarta.servlet.http.HttpServletResponse in project spring-security by spring-projects.
the class Saml2LogoutRequestFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
if (!this.logoutRequestMatcher.matches(request)) {
chain.doFilter(request, response);
return;
}
if (request.getParameter(Saml2ParameterNames.SAML_REQUEST) == null) {
chain.doFilter(request, response);
return;
}
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
RelyingPartyRegistration registration = this.relyingPartyRegistrationResolver.resolve(request, getRegistrationId(authentication));
if (registration == null) {
this.logger.trace("Did not process logout request since failed to find associated RelyingPartyRegistration");
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
if (registration.getSingleLogoutServiceLocation() == null) {
this.logger.trace("Did not process logout request since RelyingPartyRegistration has not been configured with a logout request endpoint");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
if (!isCorrectBinding(request, registration)) {
this.logger.trace("Did not process logout request since used incorrect binding");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
String serialized = request.getParameter(Saml2ParameterNames.SAML_REQUEST);
Saml2LogoutRequest logoutRequest = Saml2LogoutRequest.withRelyingPartyRegistration(registration).samlRequest(serialized).relayState(request.getParameter(Saml2ParameterNames.RELAY_STATE)).binding(registration.getSingleLogoutServiceBinding()).location(registration.getSingleLogoutServiceLocation()).parameters((params) -> params.put(Saml2ParameterNames.SIG_ALG, request.getParameter(Saml2ParameterNames.SIG_ALG))).parameters((params) -> params.put(Saml2ParameterNames.SIGNATURE, request.getParameter(Saml2ParameterNames.SIGNATURE))).build();
Saml2LogoutRequestValidatorParameters parameters = new Saml2LogoutRequestValidatorParameters(logoutRequest, registration, authentication);
Saml2LogoutValidatorResult result = this.logoutRequestValidator.validate(parameters);
if (result.hasErrors()) {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, result.getErrors().iterator().next().toString());
this.logger.debug(LogMessage.format("Failed to validate LogoutRequest: %s", result.getErrors()));
return;
}
this.handler.logout(request, response, authentication);
Saml2LogoutResponse logoutResponse = this.logoutResponseResolver.resolve(request, authentication);
if (logoutResponse == null) {
this.logger.trace("Returning 401 since no logout response generated");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
if (logoutResponse.getBinding() == Saml2MessageBinding.REDIRECT) {
doRedirect(request, response, logoutResponse);
} else {
doPost(response, logoutResponse);
}
}
use of jakarta.servlet.http.HttpServletResponse in project spring-security by spring-projects.
the class MiscHttpConfigTests method getWhenUsingCustomHttpFirewallThenFirewallIsInvoked.
@Test
public void getWhenUsingCustomHttpFirewallThenFirewallIsInvoked() throws Exception {
this.spring.configLocations(xml("HttpFirewall")).autowire();
FirewalledRequest request = new FirewalledRequest(new MockHttpServletRequest()) {
@Override
public void reset() {
}
};
HttpServletResponse response = new MockHttpServletResponse();
HttpFirewall firewall = this.spring.getContext().getBean(HttpFirewall.class);
given(firewall.getFirewalledRequest(any(HttpServletRequest.class))).willReturn(request);
given(firewall.getFirewalledResponse(any(HttpServletResponse.class))).willReturn(response);
this.mvc.perform(get("/unprotected"));
verify(firewall).getFirewalledRequest(any(HttpServletRequest.class));
verify(firewall).getFirewalledResponse(any(HttpServletResponse.class));
}
Aggregations