Spring Security는 나머지 서비스에서 인증된 사용자와 인증되지 않은 사용자에 대한 사용자 정보를 가져옵니다.
보안은 웹 애플리케이션을 개발할 때 중요한 고려 사항입니다. 사용자 데이터를 보호하고 무단 액세스를 방지하려면 신뢰할 수 있는 인증 및 권한 부여 메커니즘을 사용해야 합니다. Spring Security는 애플리케이션을 보호하기 위한 완전한 솔루션 세트를 제공하는 강력하고 널리 사용되는 보안 프레임워크입니다. 이 기사에서는 Spring Security에서 인증된 사용자와 인증되지 않은 사용자에 대한 사용자 정보를 얻는 방법을 살펴보겠습니다. PHP 편집자 Baicao는 Spring Security의 기능을 활용하여 사용자 정보를 얻고 다른 서비스 간에 사용자 정보를 공유하는 방법을 보여줍니다. 당신이 초보자이든 숙련된 개발자이든 이 글은 Spring Security에 대한 자세한 정보를 제공하고 애플리케이션의 보안을 향상시키는 데 도움이 될 것입니다.
질문내용
봄휴식 서비스가 있는데, 인증유저와 비인증유저 모두 사용하고 싶습니다. 사용자가 인증되면 securitycontextholder.getcontext().getauthentication()
에서 사용자 정보를 가져오고 싶습니다.
- 내가 사용한다면
.antmatchers("/app/rest/question/useroperation/list/**").permitall()
아래와 같이 ouath2 구성에서 사용자 정보를 얻을 수 있습니다. 인증된 사용자이지만 인증되지 않은 사용자에게는 401 오류가 발생합니다. - 만약 내가
.antmatchers("/app/rest/question/useroperation/list/**").permitall()
웹 보안에서 URL을 무시합니다.web.ignoring()..antmatchers("/app/rest/question/useroperation/list/**")
securityconfiguration
아래와 같이 모든 사용자가 전화를 걸 수 있습니다. 서비스를 제공하지만 보안 컨텍스트에서 사용자 정보를 가져올 수 없습니다.
인증된 사용자와 인증되지 않은 사용자에 대해 URL을 호출하고 사용자가 로그인할 때 보안 컨텍스트에서 사용자 정보를 가져오도록 스프링 보안을 구성하는 방법입니다.
으아악보안 구성
@configuration @enableresourceserver protected static class resourceserverconfiguration extends resourceserverconfigureradapter { @inject private http401unauthorizedentrypoint authenticationentrypoint; @inject private ajaxlogoutsuccesshandler ajaxlogoutsuccesshandler; @override public void configure(httpsecurity http) throws exception { http .exceptionhandling() .authenticationentrypoint(authenticationentrypoint) .and() .logout() .logouturl("/app/logout") .logoutsuccesshandler(ajaxlogoutsuccesshandler) .and() .csrf() .requirecsrfprotectionmatcher(new antpathrequestmatcher("/oauth/authorize")) .disable() .headers() .frameoptions().disable() .sessionmanagement() .sessioncreationpolicy(sessioncreationpolicy.stateless) .and() .authorizerequests() .antmatchers("/views/**").permitall() .antmatchers("/app/rest/authenticate").permitall() .antmatchers("/app/rest/register").permitall() .antmatchers("/app/rest/question/useroperation/list/**").permitall() .antmatchers("/app/rest/question/useroperation/comment/**").authenticated() .antmatchers("/app/rest/question/useroperation/answer/**").authenticated() .antmatchers("/app/rest/question/definition/**").hasanyauthority(authoritiesconstants.admin) .antmatchers("/app/rest/logs/**").hasanyauthority(authoritiesconstants.admin) .antmatchers("/app/**").authenticated() .antmatchers("/websocket/tracker").hasauthority(authoritiesconstants.admin) .antmatchers("/websocket/**").permitall() .antmatchers("/metrics/**").hasauthority(authoritiesconstants.admin) .antmatchers("/health/**").hasauthority(authoritiesconstants.admin) .antmatchers("/trace/**").hasauthority(authoritiesconstants.admin) .antmatchers("/dump/**").hasauthority(authoritiesconstants.admin) .antmatchers("/shutdown/**").hasauthority(authoritiesconstants.admin) .antmatchers("/beans/**").hasauthority(authoritiesconstants.admin) .antmatchers("/info/**").hasauthority(authoritiesconstants.admin) .antmatchers("/autoconfig/**").hasauthority(authoritiesconstants.admin) .antmatchers("/env/**").hasauthority(authoritiesconstants.admin) .antmatchers("/trace/**").hasauthority(authoritiesconstants.admin) .antmatchers("/api-docs/**").hasauthority(authoritiesconstants.admin) .antmatchers("/protected/**").authenticated(); } }
Solution
permitall()
仍然需要 authentication
对象出现在 securitycontext
oauth가 아닌 사용자의 경우 익명 액세스를 활성화하면 됩니다.
으아악익명 액세스는 추가 필터를 추가합니다: anonymousauthenticationfilter
到填充anonymousauthenticationtoken
作为身份验证信息的过滤器链,以防securitycontext
中没有authentication
개체
/public/authphpcnendcphp를 통해 인증 사용자를 확인하기 위한 보안 구성이 있습니다. 중국어:
위 내용은 Spring Security는 나머지 서비스에서 인증된 사용자와 인증되지 않은 사용자에 대한 사용자 정보를 가져옵니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











나는 아래에 있는 혁신적인 대안: publicSecurityFilterChainsecurityFilterChain(HttpSecurityhttp)throwsException{returnhttp.httpBasic().disable().cors().and().csrf().disable().authorizeHttpRequests().requestMatchers("

Java를 사용하여 SpringSecuritySAML 기반 싱글 사인온 시스템을 개발하는 방법 소개: 인터넷의 급속한 발전으로 점점 더 많은 애플리케이션이 개발됩니다. 이러한 애플리케이션에서 사용자 로그인은 가장 일반적인 기능 중 하나입니다. 그러나 엔터프라이즈 수준 애플리케이션의 경우 사용자는 여러 시스템에 로그인해야 하므로 사용자 로그인 경험이 매우 저하됩니다. 이러한 문제를 해결하기 위해 싱글 사인온(SingleSign-On, SSO라고도 함) 시스템이 등장했습니다. 단순한

GO를 사용하여 액세스 토큰 유효성 검사를 구현하려고 합니다. 하지만 온라인에서 본 예에서는 TOKEN_SECRET을 사용하여 유효성을 검사하는 것 같습니다. 하지만 저는 Javaspring 프로그래밍에 익숙하므로 TOKEN_SECRET을 사용할 필요가 없습니다. jwk-set-uri를 제공하면 유효성(자동 보안 필터 등)이 확인되고 oauth 서버와 통신하여 유효성 검사를 수행한다는 것을 알고 있습니다. oauth 서버에 요청하여 토큰이 유효한지 확인하는 라이브러리가 Go에 없나요? oauth 서버의 userinfo 엔드포인트(http://localh)에 요청하여 이 작업을 수동으로 수행할 수 있다는 것을 알고 있습니다.

백엔드 관리 시스템에서는 일반적으로 다양한 사용자의 인터페이스 액세스 기능을 제한하기 위해 액세스 권한 제어가 필요합니다. 사용자에게 특정 권한이 없으면 특정 인터페이스에 액세스할 수 없습니다. 이 기사에서는 waynboot-mall 프로젝트를 예로 들어 일반적인 백엔드 관리 시스템이 권한 제어 프레임워크 SpringSecurity를 도입하는 방법을 소개합니다. 개요는 다음과 같습니다. waynboot-mall 프로젝트 주소: https://github.com/wayn111/waynboot-mall 1. SpringSecurity란? SpringSecurity는 강력하고 유연한 보안을 목표로 하는 Spring 프레임워크 기반의 오픈 소스 프로젝트입니다. Java 애플리케이션용.

Java를 사용하여 SpringSecurityOAuth2 기반 싱글 사인온 시스템을 개발하는 방법 소개: 인터넷의 급속한 발전으로 인해 점점 더 많은 웹사이트와 애플리케이션에서 사용자가 로그인해야 하지만 사용자는 각 웹사이트나 애플리케이션을 기억하고 싶어하지 않습니다. 계좌번호와 비밀번호입니다. Single Sign-On 시스템(SingleSign-On, SSO라고도 함)은 이 문제를 해결하여 사용자가 한 번 로그인한 후 반복적인 인증 없이 여러 웹 사이트와 애플리케이션에 액세스할 수 있도록 합니다. 이 글에서 소개할

나는 springrest 서비스를 가지고 있으며 인증된 사용자와 인증되지 않은 사용자 모두에게 이를 사용하고 싶습니다. 사용자가 인증되면 securitycontextholder.getcontext().getauthentication()에서 사용자 정보를 가져오고 싶습니다. 아래와 같이 ouath2 구성에서 .antmatchers("/app/rest/question/usereration/list/**").permitall()을 사용하면 인증된 사용자에 대한 사용자 정보를 얻을 수 있지만 인증된 사용자에 대한 정보는 얻을 수 없습니다. 40이 나타날 것이다

소개 오늘날의 상호 연결된 세계에서 RESTful API는 애플리케이션 간 통신을 위한 핵심 메커니즘이 되었습니다. 강력한 프로그래밍 언어인 Java를 사용하면 효율적이고 확장 가능하며 잘 관리되는 RESTful API를 구축할 수 있습니다. 1장: RESTfulAPI 기본 RESTful 아키텍처의 원리 및 모범 사례 HTTP 메소드, 상태 코드 및 응답 헤더 JSON 및 XML과 같은 데이터 형식 2장: RESTfulAPI 설계 및 모델링 RESTfulAPI 디자인 원리 리소스 모델링 및 URI 설계 버전 제어 및 HATEOAS 3장: 사용 RESTful API를 구축하기 위한 SpringBoot SpringBoot 소개 및 구축 시작하기

Vue.js와 Spring Boot는 다음을 통해 상호 작용합니다. RESTful API: Vue.js는 Axios를 사용하여 비동기 HTTP 요청을 보내고 Spring Boot는 RESTful API 구현을 제공합니다. 데이터 전달: 데이터는 요청 본문이나 쿼리 매개변수와 같은 요청 및 응답을 통해 전달됩니다. 요청 방법: GET, POST, PUT, DELETE 등의 HTTP 요청 방법을 사용하여 작업을 지정합니다. 라우팅: Spring Boot @RequestMapping 주석은 컨트롤러 라우팅을 정의하고 Vue.js는 Vue Router를 사용하여 인터페이스 라우팅을 정의합니다. 상태 관리: Vu