Tag: spring security

在第一次请求中,Spring安全’记住我’的cookie不可用

我无法在登录请求后检索Spring记住我的cookie,但它在下一个对受保护页面的请求中工作正常。 谁能告诉我如何立即掌握它? 我在登录请求中设置了记住我的cookie,但是在Spring重定向回原始(受保护的)URL之后无法对其进行检索。 一步步: 浏览器转到example.com/protected Spring重定向到登录表单页面 成功登录后,SPRING_SECURITY_REMEMBER_ME_COOKIE设置在一个非常薄的自定义子类org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices中 看起来Spring重定向回example.com/protected,没有往返浏览器,并且登录“servlet”和受保护页面都由Tomcat 6中的同一个线程处理。 我们的org.springframework.security.web.access.expression.WebSecurityExpressionRoot的子类具有从调用的方法 在我们的method()中,request.getCookies()不会在第一个请求中给出记住我的cookie,而是在之后的所有请求中。 我们的应用程序存在一些问题,因为缺少cookie … 到目前为止,我的理论是我不理解SavedRequest。 压缩配置在这里: 我尝试添加以下内容,唯一的结果是用户没有被重定向到原始页面。 <http …

Spring安全打开弹出窗口

当用户执行需要进行身份validation但未执行身份validation的操作时,有人知道如何打开弹出窗口进行身份validation(使用spring security)。 例如:假设页面有一个“立即购买”按钮,将产品添加到购物车并执行结帐(立即购买页面),如果用户已经过身份validation,或者打开弹出窗口供用户执行身份validation。 如果validation成功,则弹簧重定向到“立即购买”页面,或者在打开弹出窗口时停留在该页面中(错误消息“错误登录”)。 我已经在谷歌搜索了一种解决方案,但没有运气。 有人可以指出我正确的方向吗? 谢谢

如何禁用tomcat 7控制台调试信息

实际上,我已经有这个问题很长一段时间了,我使用SpringMVC + Hibernate3 + Spring Security作为框架,tomcat 7作为容器,但是在web.xml中添加filter和拦截器之后,就有了sooooo许多调试信息打印到控制台,无论我如何更改配置文件,那些调试信息始终保持在那里,请帮忙。 web.xml中 iCubeHRS springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /* contextConfigLocation /WEB-INF/dispatcher-servlet.xml /WEB-INF/spring-security.xml org.springframework.web.context.ContextLoaderListener dispatcher org.springframework.web.servlet.DispatcherServlet 1 dispatcher / log4j的 # Root logger option log4j.rootLogger=WARN, file log4j.category.org.springframework = OFF log4j.logger.org.springframework.aop.framework.autoproxy=OFF log4j.logger.org.apache=OFF,R # Direct log messages to a log file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=c\:\\test\\logging.log log4j.appender.file.MaxFileSize=1MB log4j.appender.file.MaxBackupIndex=1 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L – %m%n 控制台中那些血腥的调试信息(远远超过我在这里粘贴的信息): 14:16:21.617 […]

通过java代码配置弹簧安全性的自定义403错误页面

任何人都知道如何在spring security中配置自定义的403页面? 在Web上看,我得到的所有结果都是XML配置,我正在使用Java配置。 那是我的SecurityConfig: @Configuration @ComponentScan(value=”com”) @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean @Override public AuthenticationManager authenticationManagerBean() throws Exception { return new CustomAuthenticationManager(); } protected void configure(HttpSecurity http) throws Exception { http .csrf() .disable() .authorizeRequests() .antMatchers(“/resources/**”, “/publico/**”).permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage(“/acesso/login”).permitAll() .loginProcessingUrl(“/login”).permitAll() .usernameParameter(“login”) .passwordParameter(“senha”) .successHandler(new CustomAuthenticationSuccessHandler()) .failureHandler(new CustomAuthenticationFailureHandler()) .and() .logout() .logoutUrl(“/logout”) […]

如何在不配置策略显式的情况下获取对SessionAuthenticationStrategy的引用?

在基于Spring Security 3.2的应用程序中,我有一个显式配置的UsernamePasswordAuthenticationFilter ,它需要对sessionAuthenticationStrategy的引用(以便调用.onAuthentication )。* sessionAuthenticationStrategy是 ( HttpSecurityBeanDefinitionParser )创建的默认值。 我的问题: 如何在不配置完整的SessionAuthenticationStrategy explicite的情况下获得对SessionAuthenticationStrategy的引用,以便我可以在XML配置中注入此引用? … … …

使用Spring Security在运行时切换身份validation方法?

通常,当您为应用程序声明不同的“”(在我的情况下为webapp)时,Spring Security将负责一个接一个地调用提供程序,以防止失败。 因此,假设我在配置文件中首先声明了DatabaseAuthenticationProvider和LDAPAuthenticationProvider,并且在运行时首先调用DatabaseAuthenticationProvider,如果身份validation失败,则尝试LDAPAuthentication。 这很酷 – 但是,我需要的是运行时切换。 我想有一个选择在这两种方法之间选择(基于数据库的身份validation/基于ldap的身份validation),并以某种方式基于这个全局设置来实现实现。 我该怎么做? 是否可以使用Spring-Security?

SecurityContextHolder.getContext()。getAuthentication()返回null

我想使用以下代码从spring Security手动绕过用户: User localeUser = new User(); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(localeUser ,null, localeUser .getAuthorities()); SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(auth); // Create a new session and add the security context. HttpSession session = request.getSession(true); session.setAttribute(“SPRING_SECURITY_CONTEXT”, securityContext); return “dummyLogin”; 虚拟登录页面(由磁贴处理)在内部调用同一个控制器中的不同请求映射,我试图获得这样的身份validation。 SecurityContextHolder.getContext().getAuthentication() 我在哪里无效! 请帮忙!

如何使Spring Security应用程序在代理后面运行?

我们有一个基于Spring 1.6.3的Java 1.6上的应用程序,它使用Spring Security 3.0.5并使用Spring Web和RestEasy 2.1.0实现REST API。 我需要将此应用程序(服务器)置于代理之后,该代理将HTTPS请求流量从REST API客户端应用程序转换为HTTP流量。 此更改为登录请求创建“跨域”方案:客户端发送HTTPS登录请求,服务器使用HTTP的重定向URL进行应答。 目前它回复: ”http://192.168.0.10:8090/index.html;jsessionid=64FD79…86D” , 我需要的是: ”/index.html;jsessionid=64FD79…86D” 我们提供了解决方案,使服务器响应“相对”URL而不是“绝对”URL。 所以我尝试在这里实现与描述情况类似的东西: forum.spring.io上的主题 我已经使用contextRelative =“true”设置RedirectStrategy bean并从LoginSuccessHandler扩展类中的AbstractAuthenticationTargetUrlRequestHandler覆盖redirectStrategy setter,我看到HttpServletResponse对象的redirectStrategy属性按预期设置为true。 仍然没有解决问题。 此外,当使用encodeRedirectURL(“otherLogin”)更改HttpServletResponse对象的redirectURLCC属性时,设置类似于 ”http://192.168.0.10:8090/otherLogin” 而这不是我需要的。 我需要删除URL的整个协议+ ipaddress部分。 响应对象的URL属性无法进行更改,因为它由Filter和FilterChain接口实现包装。 请提出任何想法。 我想这种事情应该在web.xml或auth-AplicationContext.xml文件中解决,而不是在代码中。 最好的祝福。

AbstractSecurityWebApplicationInitializer与AbstractAnnotationConfigDispatcherServletInitializer

我正在尝试为基于Spring 3.2.8的纯Java配置应用程序添加安全性。 我按照说明http://docs.spring.io/spring-security/site/docs/3.2.2.RELEASE/reference/htmlsingle/#jc 我已经完成了3.1节,文档说这时每个URL都应该要求身份validation,但没有一个(至少我可以加载每个URL)。 它说它创建了一个Servletfilter等。 很明显,WebSecurityConfigurerAdapter子类本身是不够的。 所以我看一下3.1.1节,它说下一步是将springSecurityFilterChain注册到WAR,然后继续说明在Servlet 3+环境中,我需要inheritanceAbstractSecurityWebApplicationInitializer。 但我已经在inheritanceAbstractAnnotationConfigDispatcherServletInitializer。 我应该有一个吗? 在AbstractSecurityWebApplicationInitializer JavaDoc中有一些关于排序的讨论,暗示我应该有多个初始化类。 在所有这些中,它还说要将WebSecurityConfigurerAdapter子类添加到getRootConfigClasses()(尽管该示例没有显示其他Spring启动文档的“AppConfig”;而且,仅此一项还不够)。 所以我尝试添加另一个初始化类。 我的所有其他类都是我的AbstractAnnotationConfigDispatcherServletInitializer子类的公共静态内部类,所以我把另一个放在那里作为AbstractSecurityWebApplicationInitializer子类(而不是创建一个单独的.java文件)。 WARNING com.caucho.server.webapp.WebApp setConfigException: java.lang.UnsupportedOperationException: unimplemented at com.caucho.server.webapp.ServletContextImpl.setSessionTrackingModes(ServletContextImpl.java:552) at org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer.onStartup(AbstractSecurityWebApplicationInitializer.java:120) at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174) at com.caucho.server.webapp.WebApp.callInitializer(WebApp.java:3471) at com.caucho.server.webapp.WebApp.callInitializers(WebApp.java:3439) at com.caucho.server.webapp.WebApp.startImpl(WebApp.java:3661) at com.caucho.server.webapp.WebApp$StartupTask.run(WebApp.java:5196) at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173) at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118) 我尝试添加订购无济于事。 我的整个配置: package com.latencyzero.satdb.web; // // Java Imports // import java.util.Properties; import java.util.ResourceBundle; import javax.naming.InitialContext; import javax.servlet.ServletContext; […]

无法让UserDetailsManager注入Spring Boot和基于Java的配置

我有spring boot webapp,它使用基于Java的配置来配置JdbcUserDetailsManager: @Configuration @EnableWebMvcSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired protected DataSource dataSource; @Autowired public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception { auth.jdbcAuthentication() .dataSource(dataSource) .usersByUsernameQuery(“select username as principal, password as credentials, true from users where username = ?”) .authoritiesByUsernameQuery(“select username as principal, authority as role from authorities where username = ?”) .rolePrefix(“ROLE_”); } @Override […]