Tag: spring security

如何使用Spring Security 3.1更改当前用户的登录名?

我要求每个用户在登录时都可以更改自己的用户名。问题是如何在Spring Security的身份validation令牌中更新用户名( Principal )? ( 我必须更新它,因为我使用身份validation令牌中的原始名称来识别某些业务用例中的用户。 ) 我使用基于表单和cookie记忆我的登录,所以我的身份validation令牌是UsernamePaswordAuthenticationToken和RememberMeAuthenticationToken 。 两者都有一个存储登录名的字段principal 。 不幸的是这个变量是final ,所以我不能改变它的价值。 有没有人知道Spring Security如何推荐更改身份validation令牌中的Principal ? 我当前的工作原理是我将UsernamePaswordAuthenticationToken和RememberMeAuthenticationToken替换为具有附加非最终主要字段的子类,并覆盖getPrincipal()方法以返回此附加主体而不是原始主体。 然后我还将生成此标记的两个类子类化,以创建我的标记而不是原始标记。 —但我觉得这是一个很大的黑客。

如何集成Spring Security和GWT?

我正在尝试集成Spring Security和GWT。 我也在使用gwt-incubator-security。 我按照wiki页面上的描述配置了所有内容。 我设法通过使用intercept-url来获得安全性,但我无法使用注释使其工作。 关于问题是什么的任何想法? PS我使用的是Spring 2.5.6,Spring Security 2.0.5和gwt-incubator-security 1.0.1。 欢迎任何有用的链接和评论。 这是我的配置文件 applicationContext.xml中 <!– –> web.xml中 Spring_test.html org.springframework.web.context.ContextLoaderListener spring org.springframework.web.servlet.DispatcherServlet 1 spring /spring_test/greet.rpc <!– /org.example.gwtwisdom.GwtWisdom/services/* –> greetServlet com.ct.test.server.GreetingServiceImpl greetServlet /spring_test/greet.rpc springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /* 为spring-servlet.xml 这是我尝试与Spring Security集成的示例项目: http : //www.filedropper.com/springtest_1

如何在spring security taglib中不提及hasRole(’ROLE_ADMIN’)

如何使用spring security taglib编写以下条件? show these for only non admins

antMatchers Spring Security模式,具有可更改的URL用户ID

我很长一段时间都在寻找答案但却找不到任何有效的方法 在我的rest服务中,我保留了一些function:/ account / {id} / download我想在SecurityConfig java文件中设置access ROLE,只有ROLE_TOKENSAVED用户可以访问这个url 当{id}可更改时,模式应该如何? 我尝试了一些正则表达式模式,但没有任何工作,我想要的,这是我的一些尝试: 1. antMatchers(“account/**/download”).access(somerolehere) 2. antMatchers(“account/\\d/download”).access(somerolehere) 3. antMatchers(“account/[\\d]/download”).access(somerolehere) 在此先感谢您的服务:) 编辑: @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers(“/admin**”).access(“hasRole(‘ROLE_ADMIN’)”) .antMatchers(“/account*//**”).access(“hasRole(‘ROLE_USER’) or hasRole(‘ROLE_ADMIN’)”) .antMatchers(“/account/\\d+/download”).access(“hasRole(‘ROLE_TOKENSAVED’)”) .antMatchers(“/user**”).permitAll() //othercode… }

Spring Security,Method Security annotation(@Secured)无效(java config)

我正在尝试使用@Secured(“ADMIN”)设置方法安全注释(没有任何XML,只有java配置,Spring Boot)。 但是通过角色访问不起作用。 安全配置: @Configuration @EnableWebSecurity public class AppSecurityConfiguration extends WebSecurityConfigurerAdapter{ ….. @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers(“/api/**”).fullyAuthenticated().and() .addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); } ….. } 我想限制访问控制器的方法: @RestController @RequestMapping(“/api/groups”) public class GroupController { @Autowired private GroupService groupService; @Secured(“ADMIN”) @RequestMapping public List list() { return groupService.findAll(); } } 通过url限制访问是有效的,具有: .antMatchers(“/api/**”).hasAuthority(“ADMIN”) 也许我忘了指定我想要按角色限制? UPD:根据规则,在Controller层或Service层中哪一层必须是@PreAuthorize(“hasRole(‘ADMIN’)”) ?

spring security从DB获取用户ID

我使用spring security进行身份validation,并成功地在任何需要的地方获取User对象( org.springframework.security.core.userdetails.User )。 但我也想要UserId ,这在spring的User对象中不存在。 所以我创建了自己的对象( com.app.site.pojo.User )。 它有很少的额外变量,如userId , 用户出生日期等。现在我希望spring security使用我的user对象而不是spring User对象。 它应该包含有关该用户的所有详细信息。 我试图将用户对象的类型转换为我的对象,它抛出exception(很明显)。 我不想再次调用DB来再次从DB获取userId。 我怎样才能实现它?

Spring中的自定义身份validation

我有个问题。 在Struts中,我有一个处理用户身份validation的Action,即我获取了用户的凭据并使用DAO来validation用户凭据。 我想在Spring中保持相同的设置。 我正在使用Spring 3.0.3 RELEASE。 我的问题是,我已经阅读了Spring Security,并在那里指定了JDBC后端“Validation”提供程序。 我想知道,如果用户单击“登录”它将提交凭据提交给我的控制器以检查有效身份validation怎么办? 我想这样做的原因是我有一个处理用户身份validation和授权的服务。 提前致谢。 PS如何在Spring中使某些控制器安全? PPS我是Spring的新手

显然Spring Boot竞争条件导致重复的springSecurityFilterChain注册

我有一个REST-full Web服务,使用Spring Boot 1.2.0-RELEASE实现,偶尔会在启动时抛出以下exception。 03-Feb-2015 11:42:23.697 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) … Caused by: java.lang.IllegalStateException: Duplicate Filter registration for ‘springSecurityFilterChain’. Check to ensure the Filter is only configured once. at org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer.registerFilter(AbstractSecurityWebApplicationInitializer.java:215) at org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer.insertSpringSecurityFilterChain(AbstractSecurityWebApplicationInitializer.java:147) … 当我说“偶尔”时,我的意思是简单地重新启动Tomcat服务器(版本8.0.17)将产生此exception或将成功加载而不会出现问题。 这是一个基于Spring Boot构建的Servlet 3.0应用程序,因此我们没有传统的web.xml文件。 相反,我们使用Java初始化我们的servlet。 package com.v.dw.webservice; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.SpringBootServletInitializer; […]

将Spring Security与SiteMinder集成

如何将Spring Security与SiteMinder集成以接收用户和角色? 我有一个Spring Security’in-memory’的项目设置,我想用它来转换它以接受带有User和Roles的SiteMinder标题。 如果SiteMinder将发送用户角色(ROLE_READ,ROLE_WRITE)并具有服务层授予访问权限。 如何转换内存以使用SiteMinder? 内存中用户角色 内存中的用户和角色列表 服务层保护 这里的服务方法受特定角色的保护 此源( 用于Siteminder的Spring Security Java Config )看起来很有前景,但它始终分配了角色RoleEmployee。

Spring Security:Java Config不起作用

我正在尝试建立一个包含spring security的java可配置spring环境。 应用程序启动没有任何错误,但我无法成功登录。 WebAppInitializer import javax.servlet.ServletContext; import javax.servlet.ServletException; import org.springframework.core.annotation.Order; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @Order(value = 1) public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); } @Override protected Class[] getRootConfigClasses() { return new Class[] { HibernateConfig.class, SecurityConfig.class }; } @Override protected Class[] getServletConfigClasses() { return new Class[] { WebAppConfig.class }; […]