2016-07-15 1 views
1

안녕하세요. 봄부터 액세스가 거부되었습니다. 누군가가 내가 봄 4.3스프링 보안이 올바른 자격 증명 403을 제공합니다.

당신은 사용자가 두 개의 기관을 가지고 있음을 알 수 아래 로그에서와 마찬가지로 내 컨트롤러

@RestController 
@RequestMapping (value = "/api/secured/resource/school") 
@Secured ({ ApplicationConstants.Role.SYSTEM_ADMIN, ApplicationConstants.Role.SCHOOL_ADMIN }) 
public class SchoolController 
{ 

    @Autowired 
    private SchoolService schoolService; 

    @PostMapping (consumes = "application/json") 
    @Secured ({ ApplicationConstants.Role.SYSTEM_ADMIN }) 
    public @ResponseBody ResponsePayload createSchool (HttpServletRequest request, @RequestBody School school) 
      throws ServiceException 
{ 
} 

interface Role 
    { 

     String SYSTEM_ADMIN = "SYSTEM_ADMIN"; 

     String SCHOOL_ADMIN = "SCHOOL_ADMIN"; 
    } 

를 사용하고이


좀 도와 주시겠습니까

SYSTEM_USER, SYSTEM_ADMIN 여전히 나에게 접근 거부를 제공합니다.

Sprin g 구성

<http pattern="/static/**" security="none" /> 
    <http use-expressions="true"> 
     <intercept-url pattern="/app/**" access="isAuthenticated()" /> 
     <form-login login-page="/loginPage" 
      authentication-success-handler-ref="mySuccessHandler" 
      authentication-failure-handler-ref="myFailureHandler" /> 
     <logout logout-success-url="/loginPage" /> 
     <custom-filter ref="loginFilter" after="FIRST" /> 
     <csrf disabled="true" /> 
    </http> 

2016년 7월 15일 16 : 03 : 12,525 디버그의 MethodSecurityInterceptor : 348 - 이전에 인증 : org.springframew[email protected]7670236f : 주 : SystemUser [userId를 = 1, = 관리자 이름 , email = [email protected], mobilePhone = 9999999999, status = ACTIVE]; 자격증 명 : [PROTECTED]; 인증 됨 : true; 세부 사항 : org.sprin[email protected]0 : RemoteIpAddress : 0 : 0 : 0 : 0 : 0 : 0 : 0 : 1; SessionId : 1h5x6yxtd1m0y1ogs4h5vfo1yl; 수여 기관 : SYSTEM_USER, 시스템 _ 2016년 7월 15일 16 : 03 : 12,525 DEBUG는 AffirmativeBased : 66 - 유권자 : [email protected]를 반환 : 0 2016년 7월 15일 (16) : 03 : 12,527 DEBUG AffirmativeBased : 66 - 유권자 : [email protected]4efc, 반환 된 : 0 2016-07-15 16 : 03 : 12,529 DEBUG ExceptionHandlerExceptionResolver : 133 - 핸들러에서 예외 처리 중 [public com.tepachi.web.response.ResponsePayload com.tepachi.web.controller.SchoolController.createSchool (javax.servlet.http.HttpServletRequest, com.tepachi.db.entities.user.School) throws com.tepachi.exception.ServiceException] : org.springframework.security.access.AccessDeniedException : 액세스가 거부되었습니다.

답변

0

문제는 봄 4 이후에 부여 된 권한에 ROLE_ 앞에 붙습니다.

hasRole ([역할]) : 현재 주체가 지정된 역할이있는 경우 true를 반환합니다. 기본적으로 제공된 역할이 'ROLE_'로 시작하지 않으면 추가됩니다. 이것은 DefaultWebSecurityExpressionHandler에서 defaultRolePrefix를 수정하여 사용자 정의 할 수 있습니다.

더 많은 정보는 여기에서 찾을 수 있습니다 Spring Doc