【java-Spring Boot / Spring Security,登录表单,密码检查】教程文章相关的互联网学习教程文章

java – Spring Security request.getUserPrincipal()始终为null

在我们的应用程序中观察到一个非常奇怪的情况(具有所有默认BOM依赖性的Spring Boot 1.5.6):您可以完美地登录(使用AbstractPreAuthenticatedProcessingFilter),但这仍然会使请求中的Principal为null!即request.getUserPrincipal()为null,而SecurityContextHolder.getContext().getAuthentication()则不是! 这又会影响我们的健康端点敏感的能力:它使用Principal(参见HealthMvcEndpoint.exposeHealthDetails(HttpServletRequest,P...

java – 如何基于@Profile为spring-security添加过滤器?【代码】

我试图定义两个不同的bean(都扩展AbstractPreAuthenticatedProcessingFilter):一个用于在“开发”配置文件处于活动状态时从请求中获取头(例如USER_ID),另一个用于从请求头中获取JWT “开发”配置文件未激活. (从概念上讲,我真的只是尝试以编程方式根据bean本身的存在来注册过滤器)目前,我甚至都没有尝试使用配置文件,因为我遇到了自动获取标头的问题在适当的过滤链中注册. 该应用程序使用Spring-Boot 2.0.0.RELEASE,配置为使用嵌入...

java – 使用JPA的Spring安全性.如何配置applicationContext-security.XML文件?(使用DaoAuthenticationProvider)【代码】

我正在使用JDBC身份验证服务来保护我的安全.认证提供者代码是,<authentication-provider><jdbc-user-service id="userDetailsService" data-source-ref="dataSource" /> </authentication-provider>对于数据源,<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" ><property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localho...

java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA【代码】

最近在导入一个项目时,跑起来遇到了一个问题。 创建数据库连接时,未识别的 RSA Servlet.service() for servlet [] in context with path [/] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.lang.IllegalArgumentException: Failed to decrypt.] with root ca...

java – 使用Spring-Test-MVC进行单元测试Spring-Security – 集成FilterChain / ServletFilter【代码】

因此,我们的目标是测试我们的spring web-mvc应用程序.我们使用spring安全性来保护URL或方法,我们希望使用Spring-Web-Mvc来测试控制器.问题是:Spring安全性依赖于web.xml中定义的FilterChain:<filter><filter-name>springSecurityFilterChain</filter-name><filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping><filter-name>springSecurityFilterChain</filter-name><...

java – 在spring security中保护两个或多个/ ** url【代码】

我无法使用Springs Security保护两个URL.我想要保护/ admin / **和/ user / **.主要问题是我有ADMIN的单独表作为ADMIN& ADMIN_ROLES和USER as USER& USER_ROLES.我也有管理员和用户的单独登录页面.我在下面分享我的代码.请帮我解决这个问题. 我需要的是当一些进入/ admin URL它应该显示管理员登录页面并将我重定向到/ admin / embassy,当一些打开/ URL它应该到用户登录页面并且成功登录时应该将我重定向到/ user / embassy .spring...

java – Spring Security – 无法注销【代码】

我是Spring Framework的初学者.我和我的朋友正在波兹南理工大学写我们的工程师论文,我们遇到了Spring Security(3.1.0)的问题.我不能很好地退出.当我想再次登录时,我看到消息“用户已经登录”(我覆盖了标准的Spring Security错误消息).我试图清除SecurityContextHolder的上下文但它仍然无法正常工作. 弹簧security.xml文件<beans xmlns="http://www.springframework.org/schema/beans"xmlns:security="http://www.springframework.o...

与Spring 3.2.1.RELEASE和spring security 3.1.3.RELEASE冲突. java.lang.NoSuchFieldError:NULL【代码】

我在Spring 3.2.1.RELEASE和spring secuirity 3.1.3.RELEASE中收到如下错误org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'yyyyProperties' defined in URL [jar:file:/D:/yyyy/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/usermanagement-webservice/WEB-INF/lib/core-config.jar!/config/applicationContext-core-config.xml]: Initialization of be...

java – 从spring security中的userDetails中排除GrantedAuthority【代码】

我想将角色视为用户的属性而不是具有独立的角色类,因此我不需要在我的数据库中拥有角色表.但是通用弹簧UserDetails服务将GrantedAuthority(即Collection< GrantedAuthority> getAuthorities())作为用户详细信息参数之一传递. 我想要做的是用我的’User’类中声明的角色(String role)替换这个通用的GrantedAuthority参数,如下所示.@Entity(name="usr") public class User {@Id@Column(unique=true)private String username;private ...

java – spring security config类中的错误【代码】

在我的春季应用程序中,我使用的是Spring 4.0.4和Spring Security 3.2.3.我直接从sprin网站上的教程复制了这段代码,但我遇到了编译问题,因为无法从WebSecurityConfigurerAdapter类重写方法registerAuthentication,并且HttpSecurity类没有methode authorizeUrls.我有一个罐子吗?或者是版本?import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springf...

java – Spring启动Spring Security:如何抑制基本的auth表单【代码】

美好的一天. 我在Spring启动自动配置应用程序的上下文中使用Spring安全性.我的目标是设置基本身份验证,以便标准浏览器的基本身份验证表单不会显示在401上.从Google我发现要实现它,我需要将默认的“WWW-Authenticate”标题更改为不同于“基本xxxxx“. 为此,我宣布了一个过滤器:@Bean @Order(Integer.MAX_VALUE) public Filter customAuthFilter() {return new Filter() {@Overridepublic void init(FilterConfig fc) throws Servle...

java.lang.NoClassDefFoundError:org / springframework / security / authentication / AuthenticationMan【代码】

我试图通过引用以下链接在Spring Web服务上实现身份验证: http://docs.spring.io/spring-ws/site/reference/html/security.html 以下是我添加的配置:<beanclass="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"><property name="interceptors"><list><ref local="wsServerSecurityInterceptor" /><ref local="payloadValidatingIterceptor" /></list></property></bean><bean id=...

所有提供者之后的Spring Security java.lang.StackOverflowError异常【代码】

环境: >春季4.1.6> Spring Security 4.0.1 我有2个身份验证提供程序 – 一个访问ActiveDirectory,然后一个命中我创建的自定义数据库提供程序.以这些环境中的任何一个用户身份登录都可以完美地运行.用户已通过身份验证,应用程序仍在继续. 但是,当输入无效用户且两个提供程序都无法进行身份验证时,我在页面上收到此异常:java.lang.StackOverflowErrororg.springframework.security.config.annotation.web.configuration.WebSecurit...

java – Spring Security Rest基本身份验证【代码】

我正在使用Spring security 4基于XML的配置. 这是我的配置:<security:http use-expressions="true" authentication-manager-ref="authenticationManager" entry-point-ref="authenticationEntryPoint"><security:intercept-url pattern="/**" access="hasRole('ROLE_USER')"/><security:form-login authentication-success-handler-ref="authenticationSuccessHandler"authentication-failure-handler-ref="authenticationFailure...

java – Spring Security Logout不适用于Spring 4 CORS【代码】

最近我在Spring 4中尝试了新的内置CORS-Support.这个功能很棒,我想在Spring Boot / AngularJS应用程序中实现它.All request works fine but I can’t logout my user because the OPTIONS-Request to /logout is handled by Spring Security. 是否可以在Spring Security之前处理OPTIONS-Request或者我应该在LogoutSuccessHandler中附加CORS-Headers?解决方法:使用Spring Security时,建议使用CorsFilter.您需要确保在Spring Securi...