문제

인사말!

기존 DB에 대해 인증을 시도 할 때 인증을 받고 있지만 403 페이지를 얻습니다. 방금 잘못된 비밀번호를 시도한 경우 예상대로 '잘못된 자격 증명'메시지를 얻습니다. Springsecurity에 포함 된 샘플 앱 당 인증을 시도했는데 잘 작동했습니다.

Security-Context.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
    xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-2.0.1.xsd">

    <global-method-security secured-annotations="enabled"></global-method-security>

    <http auto-config="true" >
        <intercept-url pattern="/admin/**" access="ROLE_TEST" />
        <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />

        <form-login
            login-page="/login/index.jsp"
            default-target-url="/admin/test.jsp"
            authentication-failure-url="/login/index.jsp?login_error=1" />  
    </http>

    <authentication-provider user-service-ref="jdbcUserService">      
        <password-encoder ref="passwordEncoder">
                <salt-source system-wide="n103df"/>
        </password-encoder>        
    </authentication-provider>


    <beans:bean id="jdbcUserService"  class="org.springframework.security.userdetails.jdbc.JdbcDaoImpl">
        <beans:property name="rolePrefix" value="" />
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="enableAuthorities" value="true"/>
        <beans:property name="enableGroups" value="false"/>
        <beans:property name="authoritiesByUsernameQuery" value="SELECT username,authority FROM authorities WHERE username = ?" />
        <beans:property name="usersByUsernameQuery" value="SELECT username,password,enabled as enabled FROM users WHERE username = ?" />
        <beans:property name="groupAuthoritiesByUsernameQuery" value="" />

    </beans:bean>

<beans:bean id="passwordEncoder" class="org.springframework.security.providers.encoding.Md5PasswordEncoder"/>

도움이 될 것입니다 :-) 미리 감사드립니다!

도움이 되었습니까?

해결책

403 코드를받는 경우 사용자에게 필요한 역할이 없음을 의미합니다. 따라서, 아테이신은 문제가 아니며 승인입니다.
무슨 일이 일어나고 있는지 알 수있는 유일한 방법은 로깅 레벨을 디버그에 넣는 것입니다. 더 많은 정보가 있어야합니다. 여기에 게시하십시오.
당신의 역할에는 'role_'접두사가 있습니까?

다른 팁

... 그것을 알아 냈습니다. Config 파일에 Role_test가 지정되고 DB의 '권한'열에 동일하게 지정 되었음에도 불구하고 Spring-Sec은 role_supervisor를 기대하고있었습니다.

[DEBUG,AbstractSecurityInterceptor,http-8084-7] Secure object: FilterInvocation: URL: /admin/test.jsp; ConfigAttributes: [ROLE_TEST]
[DEBUG,AbstractSecurityInterceptor,http-8084-7] Previously Authenticated: org.springframework.security.providers.UsernamePasswordAuthenticationToken@af840ed7: Principal: org.springframework.security.userdetails.User@3ec100: Username: testUser; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_SUPERVISOR; Password: [PROTECTED]; Authenticated: true; Details: org.springframework.security.ui.WebAuthenticationDetails@1c07a: RemoteIpAddress: 127.0.0.1; SessionId: 350B260FAFDDBF04D5CB4AAAB7B8A441; Granted Authorities: ROLE_SUPERVISOR
[DEBUG,ExceptionTranslationFilter,http-8084-7] Access is denied (user is not anonymous); delegating to AccessDeniedHandler
org.springframework.security.AccessDeniedException: Access is denied
        at org.springframework.security.vote.AffirmativeBased.decide(AffirmativeBased.java:68)

... 이제 궁금합니다. 어떻게 오세요? 따라서 구성 파일에서 role_test를 role_supervisor로 변경 한 후에는 모두 예상대로 작동했습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top