spring-security 相关问题

Spring Security是Spring Framework的应用程序安全解决方案。 Spring安全性可用于保护URL和方法调用。它广泛用于保护独立的Web应用程序,portlet和越来越多的REST应用程序。

Spring Security 在每次请求时都需要登录

我觉得Spring Security中持久登录成功的默认行为已经改变了。 我的安全配置: @豆 公共SecurityFilterChain过滤器链(HttpSecurity httpSecurity)

回答 1 投票 0

如何更改 Spring OAuth2 中的默认签名算法?

我需要在我的应用程序中实现 JWT 身份验证。所以我通过 Spring 网站上的 OAuth2 指南编写了这段代码。它运行良好,但默认情况下使用 SHA256 签名算法。 你能告诉我...

回答 1 投票 0

在Spring Security中使用其他bean和方法@PreAuthorize

我想在Spring Security中将@PreAuthorize与SpEL一起使用,就像http://forum.spring.io/forum/spring-projects/security/100708-spel-and-spring-security-3-accessing-中的示例一样bean-引用-in-

回答 1 投票 0

跨源请求(从 Angular 前端到 Java 后端)被阻止

我正在编写一个具有 Java Spring 后端(提供 API)和 有角度的前端。 据我所知,Java API 通过 Postman 工作得很好。 但是当我尝试连接后端时...

回答 2 投票 0

Spring boot 3 和 Spring security 预授权

我通常会尽量避免使用 spring auth,因为它通常会注入许多极难禁用的默认值。但现在我需要使用 JWT 令牌。所以我创建了一个安全c...

回答 1 投票 0

在 WebSocket 控制器中获取登录用户的主体

我有一个 Spring Boot 应用程序,它使用 Spring Security 来使用 JWT 保护端点,这对于标准 REST 控制器来说都可以正常工作。 该应用程序还具有 WebSocket 连接,我有

回答 2 投票 0

在启用CSRF保护的情况下,在primefaces + spring网站中使Primefaces文件上传按钮正常工作,而无需避免保护

我有一个演示应用程序,由一个表单(dashboard.xhtml)组成,它允许用户选择一个文件,然后向表中添加一行。为此,它有两个 Primefaces 文件上传按钮,第一个......

回答 1 投票 0

在Spring Security中认证成功后重定向到原始URL

我在 Spring Cloud Gateway 应用程序中有以下安全配置类。该网关充当处理用户身份验证的 OAuth2 客户端。身份验证成功后,我会

回答 3 投票 0

Webflux - Spring Boot - 支持 http 代理的 oAuth2 客户端

我正在努力在代理后面使用 oauth2 正确设置 webflux-weblient 。 看来, ServerOAuth2AuthorizedClientExchangeFilterFunction 使用了 webclient 的新实例,

回答 2 投票 0

使用自定义过滤器时,Spring Security maxSessions 不起作用

环境: 春季启动:3.2.2。 春季安全:6.2.1 我目前正在使用自定义过滤器来支持请求中的 JSON 格式数据。我还想使用 MaximumSessions 来限制用户只能

回答 1 投票 0

Angular 未设置 X-XSRF-TOKEN

我正在使用 Angular 17 和 Spring Boot 以及 Spring Security 6。 正如 Angular 文档中所述,执行 HTTP 请求时,拦截器会从 cookie 中读取令牌,默认情况下为 XSRF-TOKEN...

回答 1 投票 0

anyExchange().authenticated() 到底有什么区别?

anyExchange().authenticated() 到底有什么区别?考虑这个 MRE: anyExchange().authenticated() 到底有什么区别?考虑这个 MRE: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.2.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>security-mre</artifactId> <version>0.0.1-SNAPSHOT</version> <name>security-mre</name> <description>security-mre</description> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project> package com.example.securitymre.controller; import com.example.securitymre.data.Hello; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/hello") public Hello getHello() { return new Hello(); } } package com.example.securitymre.data; import lombok.Getter; import lombok.NoArgsConstructor; @NoArgsConstructor @Getter public class Hello { private final String message = "Hello!"; } 我几乎没有写任何代码,没有安全配置,但是 curl -i localhost:8080/hello HTTP/1.1 401 Unauthorized WWW-Authenticate: Basic realm="Realm" Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 0 Referrer-Policy: no-referrer content-length: 0 我已被禁止在未经身份验证的情况下使用我的应用程序 实验#2 package com.example.securitymre.data; import lombok.Getter; import lombok.NoArgsConstructor; @NoArgsConstructor @Getter public class Hello { private String message = "Hello!"; public Hello(String message) { this.message = message; } } package com.example.securitymre.controller; import com.example.securitymre.data.Hello; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/hello") public Hello getHello() { return new Hello(); } @GetMapping("/secured-hello") public Hello getSecuredHello() { return new Hello("Secured hello!"); } } package com.example.securitymre.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.web.server.SecurityWebFilterChain; @Configuration @EnableWebFluxSecurity public class SecurityConfig { @Bean public SecurityWebFilterChain securityFilterChain(ServerHttpSecurity security) { return security .authorizeExchange(authorizeExchangeSpec -> authorizeExchangeSpec .pathMatchers("/hello").permitAll() .anyExchange()/* by "any" we mean GET /secured-hello */.authenticated() ) .build(); } } curl -i localhost:8080/hello HTTP/1.1 200 OK Content-Type: application/json Content-Length: 20 Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 0 Referrer-Policy: no-referrer {"message":"Hello!"} curl -i localhost:8080/secured-hello HTTP/1.1 401 Unauthorized WWW-Authenticate: Basic realm="Realm" Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 0 Referrer-Policy: no-referrer content-length: 0 或没有anyExchange().authenticated(): package com.example.securitymre.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.web.server.SecurityWebFilterChain; @Configuration @EnableWebFluxSecurity public class SecurityConfig { @Bean public SecurityWebFilterChain securityFilterChain(ServerHttpSecurity security) { return security .authorizeExchange(authorizeExchangeSpec -> authorizeExchangeSpec .pathMatchers("/hello").permitAll() ) .build(); } } curl -i localhost:8080/hello HTTP/1.1 200 OK Content-Type: application/json Content-Length: 20 Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 0 Referrer-Policy: no-referrer {"message":"Hello!"} curl -i localhost:8080/secured-hello HTTP/1.1 401 Unauthorized WWW-Authenticate: Basic realm="Realm" Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 0 Referrer-Policy: no-referrer content-length: 0 字面意思,零差异 我并不声称拥有很多经验,但在我从事的每个项目中,都有那条anyRequest().authenticated()线。现在看来这是一些默认的,并且没有任何实际用途 我错过了什么吗?那条线到底有什么作用? 如果您要阅读有关它的文档。 您将能够理解,anyExchange().authenticated()通常意味着对应用程序任何端点的每个请求都应该经过身份验证。另一方面,如果您没有指定这个,默认情况下它会以这种方式工作,就像您在第二个配置中一样,这就是您看不到任何差异的原因。

回答 1 投票 0

Spring Security 与 Angular - OAuth 2.0 登录 REST 风格

我的 Angular 应用程序部署到 localhost:4200,Spring 应用程序部署到 localhost:8080。我正在尝试以纯粹的 REST 风格实现 OAuth2 安全性,所以完全是@RestController。所有考试...

回答 1 投票 0

grails /登录/模拟页面未找到

我正在使用 grails spring-security-core 和 spring-security-ui 插件,但无论我做什么,我都无法让切换用户工作,我总是得到: 错误:找不到页面 (404) 路径:/login/impersonate ...

回答 2 投票 0

Spring Security 在发布请求时收到 401

嗨,我正在学习 Spring,但是当我觉得开始使用它很方便时,当然我又遇到了问题......但是这次即使经过几个小时的搜索我也找不到任何解释。 问题...

回答 1 投票 0

Spring 方法安全性 SpEL 注释在将 Spring-boot 升级到 3.2.2 后总是给出 401

从 spring-boot 3.2.1 升级到 3.2.2 时,以下 SPEL 安全注释停止工作。现在,它总是给出 401。显然,Spring 安全版本在 t 之间没有升级...

回答 1 投票 0

如何区分 UserDetails 的两个实体?

我有两个实体 - 用户和管理员。 经理 公共类 Manager 扩展 BaseEntity 实现 UserDetails { 私人字符串电子邮件; 私有字符串密码; 私有字符串firstNa...

回答 1 投票 0

Keycloak - Spring Security - CODE_TO_TOKEN_ERROR

我正在使用keycloak(v.10)对现有的spring(无启动库)应用程序进行身份验证。我正在使用 keycloak 文档中的 java 适配器,我在我的

回答 1 投票 0

无法向 ExecutorSubscribableChannel[clientInboundChannel] 发送消息

我使用 Spring Boot、Spring Security、Spring websockets、stomp 和 sockjs 开发了一个移动聊天应用程序。服务器运行在 8082 端口,客户端运行在 8100 端口。 我正在使用 Angular 和 Soc...

回答 2 投票 0

如何在Postman中设置CSRF令牌

我使用 Spring Boot 2 和 Spring 5 来创建一个保存两个实体的应用程序:User 和 UserProfile。这是我的控制器类: @RestController @RequestMapping(“用户配置文件”) 公共...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.