SpringSecurity 권한 제어 실현 원리 분석


이 사용자 가 이런 캐릭터 가 있 는 지 없 는 지 판단 할 수 있 습 니 다.없 으 면 보 여주 지 않 습 니 다.


데이터 제어:
데 이 터 는 모두 백 엔 드 에서 찾 았 기 때문에 백 엔 드 에서 권한 을 제어 하면 됩 니 다.
<!--
jsr250-annotations="enabled" jsr250-api , jsr250-api jar
pre-post-annotations="enabled" spring
secured-annotations="enabled" SpringSecurity
-->
<security:global-method-security jsr250-annotations="enabled"
pre-post-annotations="enabled"
secured-annotations="enabled"/>
주:이것 은 뮤 직 비디오 c 용기 에 넣 어야 합 니 다.하위 용 기 는 주 용기 에 접근 할 수 있 기 때문에 주 용기 가 하위 용기 에 접근 할 수 없습니다.
/ ROLE_ADMIN ROLE_PRODUCT
@Controller
@RequestMapping("/product")
@RolesAllowed({"ROLE_ADMIN","ROLE_PRODUCT"})//JSR-250
public class ProductController {
@RequestMapping("/findAll")
public String findAll(){
return "product-list";
}
}
// findAll ROLE_ADMIN ROLE_PRODUCT
@Controller
@RequestMapping("/product")
public class ProductController {
@RequestMapping("/findAll")
@PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_PRODUCT')")//spring
public String findAll(){
return "product-list";
}
}
// ROLE_ADMIN ROLE_PRODUCT
@Controller
@RequestMapping("/product")
@Secured({"ROLE_ADMIN","ROLE_PRODUCT"})//SpringSecurity
public class ProductController {
@RequestMapping("/findAll")
public String findAll(){
return "product-list";
}
}
근 데 403 번 보고 할 거 예요.방문 이 안 돼 요.방식 1:spring-security.xml 설정 파일 에서 처리
<!-- spring el Spring Security ( )-->
<security:http auto-config="true" use-expressions="true">
<!-- -->
<!--403 -->
<security:access-denied-handler error-page="/403.jsp"/>
</security:http>
방식 2:웹.xml 에서 처리
<error-page>
<error-code>403</error-code>
<location>/403.jsp</location>
</error-page>
방식 3:이상 프로세서 작성
/**
* @author WGR
* @create 2020/3/2 -- 17:33
*/
@ControllerAdvice
public class ControllerExceptionAdvice {
// AccessDeniedException 403.jsp
@ExceptionHandler(AccessDeniedException.class)
public String exceptionAdvice(){
System.out.println("1234");
return "forward:/403.jsp";
}
}
주:spring 프로젝트 라면 이것 도 스 캔 해 야 합 니 다.

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[MeU] Hashtag 기능 개발➡️ 기존 Tag 테이블에 존재하지 않는 해시태그라면 Tag , tagPostMapping 테이블에 모두 추가 ➡️ 기존에 존재하는 해시태그라면, tagPostMapping 테이블에만 추가 이후에 개발할 태그 기반 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.