use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class WebSecurity method getRequestMatcherPrivilegeEvaluatorsEntry.
private RequestMatcherEntry<List<WebInvocationPrivilegeEvaluator>> getRequestMatcherPrivilegeEvaluatorsEntry(SecurityFilterChain securityFilterChain) {
List<WebInvocationPrivilegeEvaluator> privilegeEvaluators = new ArrayList<>();
for (Filter filter : securityFilterChain.getFilters()) {
if (filter instanceof FilterSecurityInterceptor) {
DefaultWebInvocationPrivilegeEvaluator defaultWebInvocationPrivilegeEvaluator = new DefaultWebInvocationPrivilegeEvaluator((FilterSecurityInterceptor) filter);
defaultWebInvocationPrivilegeEvaluator.setServletContext(this.servletContext);
privilegeEvaluators.add(defaultWebInvocationPrivilegeEvaluator);
continue;
}
if (filter instanceof AuthorizationFilter) {
AuthorizationManager<HttpServletRequest> authorizationManager = ((AuthorizationFilter) filter).getAuthorizationManager();
privilegeEvaluators.add(new AuthorizationManagerWebInvocationPrivilegeEvaluator(authorizationManager));
}
}
return new RequestMatcherEntry<>(securityFilterChain::matches, privilegeEvaluators);
}
use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class AuthorizeHttpRequestsConfigurer method configure.
@Override
public void configure(H http) {
AuthorizationManager<HttpServletRequest> authorizationManager = this.registry.createAuthorizationManager();
AuthorizationFilter authorizationFilter = new AuthorizationFilter(authorizationManager);
http.addFilter(postProcess(authorizationFilter));
}
use of jakarta.servlet.http.HttpServletRequest in project atmosphere by Atmosphere.
the class AtmosphereRequestImpl method cloneRequest.
/**
* Copy the HttpServletRequest content inside an AtmosphereRequest. By default the returned AtmosphereRequest
* is not destroyable.
*
* @param request {@link HttpServletRequest}
* @return an {@link AtmosphereRequest}
*/
public static final AtmosphereRequest cloneRequest(HttpServletRequest request, boolean loadInMemory, boolean copySession, boolean isDestroyable, boolean createSession) {
Builder b;
HttpServletRequest r;
Cookie[] cs = request.getCookies();
Set<Cookie> hs = Collections.synchronizedSet(new HashSet<>());
if (cs != null) {
Collections.addAll(hs, cs);
}
boolean isWrapped = false;
if (AtmosphereRequestImpl.class.isAssignableFrom(request.getClass())) {
b = ((AtmosphereRequestImpl) request).b;
isWrapped = true;
} else {
b = new Builder();
b.request(request);
}
HttpSession session = request.getSession(false);
if (copySession) {
session = request.getSession(createSession);
if (session != null) {
session = new FakeHttpSession(session);
} else {
session = new FakeHttpSession("", null, System.currentTimeMillis(), -1);
}
}
b.servletPath(request.getServletPath()).pathInfo(request.getPathInfo()).contextPath(request.getContextPath()).requestURI(request.getRequestURI()).requestURL(request.getRequestURL().toString()).method(request.getMethod()).serverName(request.getServerName()).serverPort(request.getServerPort()).remoteAddr(request.getRemoteAddr()).remoteHost(request.getRemoteHost()).remotePort(request.getRemotePort()).destroyable(isDestroyable).cookies(hs).session(session).principal(request.getUserPrincipal()).authType(request.getAuthType()).isSSecure(request.isSecure());
if (loadInMemory) {
String s = (String) attributeWithoutException(request, FrameworkConfig.THROW_EXCEPTION_ON_CLONED_REQUEST);
boolean throwException = Boolean.parseBoolean(s);
r = new NoOpsRequest(throwException);
if (isWrapped) {
load(b.request, b);
} else {
load(request, b);
}
b.request(r);
}
return isWrapped ? (AtmosphereRequestImpl) request : b.build();
}
use of jakarta.servlet.http.HttpServletRequest in project atmosphere by Atmosphere.
the class AtmosphereRequestImpl method getHeader.
@Override
public String getHeader(String s, boolean checkCase) {
if ("content-type".equalsIgnoreCase(s)) {
return getContentType();
}
String name = b.request.getHeader(s);
if (name == null) {
if (b.headers.get(s) != null) {
return b.headers.get(s);
}
if (s.startsWith(X_ATMOSPHERE) && isNotNoOps()) {
// Craziness with Struts 2 who wraps String attribute as BigDecimal
// https://github.com/Atmosphere/atmosphere/issues/1367
Object o = attributeWithoutException(b.request, s);
if (o == null || String.class.isAssignableFrom(o.getClass())) {
name = (String) o;
} else {
try {
if (HttpServletRequestWrapper.class.isAssignableFrom(b.request.getClass())) {
HttpServletRequest hsr = b.request;
while (hsr instanceof HttpServletRequestWrapper) {
hsr = (HttpServletRequest) ((HttpServletRequestWrapper) hsr).getRequest();
o = attributeWithoutException(hsr, s);
if (o == null || String.class.isAssignableFrom(o.getClass())) {
name = (String) o;
break;
}
}
}
} catch (Exception ex) {
logger.warn("", ex);
}
}
}
}
if (name == null && checkCase) {
return getHeader(s.toLowerCase(), false);
}
if (name == null && "connection".equalsIgnoreCase(s)) {
return "keep-alive";
}
return name;
}
use of jakarta.servlet.http.HttpServletRequest in project atmosphere by Atmosphere.
the class ContainerInitializer method onStartup.
@Override
public void onStartup(Set<Class<?>> classes, final ServletContext c) {
c.log("Initializing AtmosphereFramework");
for (Map.Entry<String, ? extends ServletRegistration> reg : c.getServletRegistrations().entrySet()) {
String disableSwitchValue = reg.getValue().getInitParameter(ApplicationConfig.DISABLE_ATMOSPHERE_INITIALIZER);
// check if AtmosphereInitializer is disabled via web.xml see: https://github.com/Atmosphere/atmosphere/issues/1695
if (Boolean.parseBoolean(disableSwitchValue)) {
c.log("Container managed initialization disabled for servlet: " + reg.getValue().getName());
continue;
}
if (c.getAttribute(reg.getKey()) == null && IOUtils.isAtmosphere(reg.getValue().getClassName())) {
final AtmosphereFramework framework = AtmosphereFrameworkInitializer.newAtmosphereFramework(c, false, true);
// Hack to make jsr356 works. Pretty ugly.
DefaultAsyncSupportResolver resolver = new DefaultAsyncSupportResolver(framework.getAtmosphereConfig());
List<Class<? extends AsyncSupport>> l = resolver.detectWebSocketPresent(false, true);
// Don't use WebLogic Native WebSocket support if JSR356 is available
int size = c.getServerInfo().toLowerCase().contains("weblogic") ? 1 : 0;
String s = reg.getValue().getInitParameter(ApplicationConfig.PROPERTY_COMET_SUPPORT);
boolean force = c.getServerInfo().toLowerCase().contains("glassfish") || c.getServerInfo().toLowerCase().contains("payara");
if (s != null && s.equals(JSR356AsyncSupport.class.getName())) {
force = true;
} else if (s != null) {
force = false;
}
if (force || l.size() == size && resolver.testClassExists(DefaultAsyncSupportResolver.JSR356_WEBSOCKET)) {
try {
framework.setAsyncSupport(new JSR356AsyncSupport(framework.getAtmosphereConfig(), c));
} catch (IllegalStateException ex) {
framework.initializationError(ex);
}
}
try {
c.addListener(new ServletRequestListener() {
@Override
public void requestDestroyed(ServletRequestEvent sre) {
}
@Override
public void requestInitialized(ServletRequestEvent sre) {
HttpServletRequest r = HttpServletRequest.class.cast(sre.getServletRequest());
AtmosphereConfig config = framework.getAtmosphereConfig();
if (config.isSupportSession() && Utils.webSocketEnabled(r)) {
r.getSession(config.getInitParameter(ApplicationConfig.PROPERTY_SESSION_CREATE, true));
}
}
});
} catch (Throwable t) {
c.log("AtmosphereFramework : Unable to install WebSocket Session Creator", t);
}
try {
s = c.getInitParameter(PROPERTY_SESSION_SUPPORT);
if (s != null) {
boolean sessionSupport = Boolean.valueOf(s);
if (sessionSupport && c.getMajorVersion() > 2) {
c.addListener(SessionSupport.class);
c.log("AtmosphereFramework : Installed " + SessionSupport.class);
}
}
} catch (Throwable t) {
c.log("AtmosphereFramework : SessionSupport error. Make sure you also define {} as a listener in web.xml, see https://github.com/Atmosphere/atmosphere/wiki/Enabling-HttpSession-Support", t);
}
c.setAttribute(reg.getKey(), framework);
}
}
}
Aggregations