在Spring Security中,我使用DefaultJaasAuthenticationProvider Configuration進行用戶名/密碼登錄驗證。 JpamLoginModule用於認證。我成功與身份驗證,但我有授權問題(ROLE_USER,ROLE_ADMIN), 正在獲取HTTP狀態403 - 訪問被拒絕錯誤。Spring Security JAAS身份驗證授權問題
下面的配置我在彈簧security.xml文件中使用
<security:authentication-manager>
<security:authentication-provider ref="jaasAuthProvider" />
</security:authentication-manager>
<bean id="jaasAuthProvider" class="org.springframework.security.authentication.jaas.DefaultJaasAuthenticationProvider">
<property name="configuration">
<bean class="org.springframework.security.authentication.jaas.memory.InMemoryConfiguration">
<constructor-arg>
<map>
<entry key="SPRINGSECURITY">
<array>
<bean class="javax.security.auth.login.AppConfigurationEntry">
<constructor-arg value="net.sf.jpam.jaas.JpamLoginModule" />
<constructor-arg>
<util:constant static-field="javax.security.auth.login.AppConfigurationEntry$LoginModuleControlFlag.REQUIRED" />
</constructor-arg>
<constructor-arg>
<map></map>
</constructor-arg>
</bean>
</array>
</entry>
</map>
</constructor-arg>
</bean>
</property>
<property name="authorityGranters">
<list>
<bean class="it.webapps.pam.RoleGranter" />
</list>
</property>
</bean>
<bean id="userDetailsService" class="it.webapps.pam.UserDetailsServiceImpl">
</bean>
RoleGranter.java代碼
public class RoleGranter implements AuthorityGranter {
public RoleGranter() {
System.out.print("=== Creating My Authority Granter ===");
}
@Override
public Set<String> grant(Principal principal) {
return Collections.singleton("ROLE_ADMIN");
}
}
的建議是非常有幫助的
我試過這個「return Collections.singleton(」ADMIN「)」,但HTTP狀態403-訪問被拒絕。我使用的是spring-security-core-3.1.0.RC3 jar。任何其他調試方法? – shakkir3435