Tag: spring security

Spring OAuth2 – 在令牌存储中手动创建访问令牌

我有一种情况,我想自己创建一个访问令牌(所以不通过通常的过程)。 我想出了这样的事情: @Inject private DefaultTokenServices defaultTokenServices; … OAuth2Authentication auth = xxx; OAuth2AccessToken token = defaultTokenServices.createAccessToken(auth); 唯一的问题是我不知道如何创建OAuth2Authentication(在我的代码中使用xxx的部分)。 我有用户和客户信息,我知道我想授予此令牌的权限。

Spring Security不能与“hasRole(’ROLE_ADMIN’)”或ROLE_ADMIN一起使用

我使用的是Spring Security 4.1版。 如果我在安全配置中指定access=”hasRole(‘ROLE_ADMIN’)”或access=”ROLE_ADMIN” ,我可以登录,但是我无法访问我的管理页面。 以下是调试错误: DEBUG [http-bio-8080-exec-10] [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] Secure object: FilterInvocation: URL: /admin; Attributes: [hasRole(‘ROLE_ADMIN’)] 2016-06-25 10:07:53,667 [] DEBUG [http-bio-8080-exec-10] [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@cc305a73: Principal: org.springframework.security.core.userdetails.User@74b46745: Username: francatore ; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN ; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 7F702A6911A71EA5556C750B6D424FF5; Granted […]

Spring OAuth2.0:根据客户端ID获取用户角色

我有多个客户注册我的oauth2 auth服务器。 假设user1具有诸如ROLE_A , ROLE_B用于client1的角色,同一用户具有诸如ROLE_C ,用于ROLE_C ROLE_D 。 现在当用户使用client1或client2登录时,他能够看到所有四个角色,即。 ROLE_A , ROLE_B , ROLE_C和ROLE_D 。 我的要求是当user1登录到client1时,它应该只返回角色ROLE_A和ROLE_B 。 当他使用ROLE_C登录时,它应该只返回ROLE_C和ROLE_D 为实现这一目标,我计划的是在身份validationfunction中,我需要获取clientId。 所以使用clientId和用户名我可以从db(client-user-roles-mapping表)中找到分配给用户的相应角色。 但问题是我不知道如何在authenticate函数中获取clientId @Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { String userName = ((String) authentication.getPrincipal()).toLowerCase(); String password = (String) authentication.getCredentials(); if (userName != null && authentication.getCredentials() != null) { String clientId = // HERE HOW […]

Spring安全性@PreAurhorize hasRole()属性注入

假设我的spring安全性和属性配置正确,我想使用属性中的角色名称 @PreAuthorize(“hasRole(‘${role.rolename}’)”) public void method() {} 我在上面的代码示例中尝试过,但它不起作用(需要’$ {role.rolename}’字符串作为比较的角色) 如果我切换到 @PreAuthorize(“hasRole(‘ROLE_ADMIN’)”) public void method() {} 它工作得很好。 我对这种用法的动机是在各种环境下的应用程序测试中具有更好的灵

org.postgresql.util.PSQLException:列索引超出范围:3,列数:2

我决定通过使用spring security和database添加身份validation来修改我的应用程序。 在我使用XML中的user和password进行普通身份validation之前。 它工作正常。 我的authentication-manager看起来像这样 但是,当我尝试进行身份validation时,我有exception org.springframework.security.authentication.InternalAuthenticationServiceException: PreparedStatementCallback; SQL [select u sername, password from pmc.username_password where username=?;]; The column index is out of range: 3, number of columns: 2.; nested exception is org.postgresql.util.PSQLException: The column index is out of range: 3, number of columns: 2. 我在XML文件中的sql语法有什么问题?

Spring Boot 2.0.x禁用某些配置文件的安全性

在Spring Boot 1.5.x中,我已经配置了安全性,并且在某些配置文件中(例如本地),我已将security.basic.enabled=false行添加到.properties文件中以禁用该配置文件的所有安全性。 我正在尝试迁移到新的Spring Boot 2,其中删除了该配置属性。 如何在Spring Boot 2.0.x中实现相同的行为(不使用此属性)? 我已经阅读过Spring-Boot-Security-2.0和security-change-in-spring-boot-2-0-m4 ,这个属性没什么。

在Spring 3.1中通过IP地址进行身份validation:最明智的方法吗?

我使用Spring Security 3.1实现了LDAP身份validation。 我的security.xml文件发布在下面。 我需要更改我的身份validation过程,以便当用户从“白名单”(保存在数据库表中)中的IP地址进入站点时,该用户应该自动使用Spring 3.1进行身份validation,然后重定向远离登录屏幕(不是我的想法,我被告知这样)。 如果用户不是来自白名单IP地址之一,则应强制他/她在登录页面上进行LDAP身份validation。 我是Spring和Spring Security的新手,所以我参阅了Spring 3.1参考文档并阅读了第I部分的所有内容。在那里,我阅读了一些建议,如果您有任何特殊的身份validation需求,您应该阅读第II部分的体系结构和实现 。 我做到了,非常缓慢并记笔记。 但是,由于我是所有这一切的新手,我不确定我是否完全理解我需要做什么以及最聪明的方法。 更新3:我得到了骨架代码,这是我最终得到的文件 我的自定义AuthenticationProvider实现,用于通过IP地址进行身份validation // Authentication Provider To Authenticate By IP Address With Allowed IPs // Stored in a db table package acme.com.controller.security; //import acme.com.controller.security.CustomUserInfoHolder; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.WebAuthenticationDetails; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper; import org.springframework.security.core.authority.mapping.NullAuthoritiesMapper; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import […]

如何使用Spring安全性获取会话超时消息

我希望在会话到期时获得会话超时消息.Below是我的spring-security.xml 根据我的知识,当会话到期时使用上面的代码它应该重定向到/?timeout=true OR /Timeout?timeout=true 。 退出时应该转到/ 。 但在我注销的情况下,它也会重定向到invalid-session-url所以我总是在正常注销和会话超时时都获得超时。 请帮我区分一下。 UPDATE /logout请求包含 session = request.getSession(); session.invalidate(); session = null;

使用Autoproxy在AspectJ模式下无法使用@Secured注释

我正在尝试让我的Spring MVC应用程序与Spring @Secured注释和AspectJ自动代理一起使用,但它似乎不代理或识别我的@Secured注释。 我有一个像这样的控制器: @Controller @RequestMapping(“/”) public class ApplicationController { private ApplicationFactory applicationFactory; @Inject public ApplicationController(ApplicationFactory applicationFactory) { super(); this.applicationFactory = applicationFactory; } @Secured(“ROLE_USER”) @ResponseBody @RequestMapping(method = GET) public Application getApplicationInfo() { return applicationFactory.buildApplication(this); } } 一个Spring安全XML看起来像这样: 码: 以上是由no-xml Spring @Configuration组件加载的,如下所示: @Configuration @ComponentScan(basePackages = {“com.example”}) @EnableWebMvc @ImportResource(“classpath:security.xml”) public class ApplicationConfiguration extends WebMvcConfigurerAdapter { } 反过来使用Servlet […]

Spring启动 – 如何配置多个登录页面?

在我的团队中,我们使用Spring Boot编写了Spring应用程序+ SAPUI5门户。 Web应用程序分为三个不同的位置,例如: webapp: – app1 – app2 – app3 为了访问这些应用程序,我们实现了登录页面。 根据用户角色,我们将用户重定向到确切的应用。 我的spring应用程序安全性如下: @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers(“/app1/**/*.*”) .permitAll() .antMatchers(“/register.html”) .permitAll() // .antMatchers(“/app2/*.*”) .hasRole(“USER”) // // .antMatchers(“/login*”) .permitAll() .antMatchers(“/soap/*”) .permitAll() .antMatchers(“/postLogin”) .authenticated() // .antMatchers(“/app3/*”) //.permitAll() .hasRole(“ADMIN”) // .anyRequest() .authenticated() // log in .and() .formLogin() .loginPage(“/login”) .failureUrl(“/login?error=loginError”) .defaultSuccessUrl(“/postLogin”) // logout […]