簡體   English   中英

Spring3 Security使用JDBC並停止工作

[英]Spring3 Security using JDBC and stopped working

使用Spring Security的Spring 3應該很容易,但是我知道我做的事情不正確。 我正在制作一個示例Spring3 Web App,並且將Spring Security用於我的Web應用程序。 經過兩周的調試,但仍無法正常工作,我發現它在我的web.xml中存在,現在可以正常運行了。 但是我需要將用戶從XML文件移動到MySQL數據庫。 因此,我從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"
           xmlns:jdbc="http://www.springframework.org/schema/jdbc"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/jdbc
           http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.0.xsd">
        <http auto-config="true">
            <intercept-url pattern="/friends/**" access="ROLE_USER" />
            <intercept-url pattern="/articles/**" access="ROLE_USER" />
            <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
        </http>
    <authentication-manager alias="authenticationManager">
        <authentication-provider>
            <jdbc-user-service data-source-ref="dataSource"/>
        </authentication-provider>
    </authentication-manager>
</beans:beans>

我使用以下內容制作了SQL數據庫:

CREATE TABLE IF NOT EXISTS `authorities` (
  `username` varchar(50) NOT NULL,
  `authority` varchar(50) NOT NULL,
  UNIQUE KEY `authorities_idx_1` (`username`,`authority`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `authorities` (`username`, `authority`) VALUES
('admin', 'ROLE_ADMIN'),
('admin', 'ROLE_USER'),
('guest', 'ROLE_USER');


CREATE TABLE IF NOT EXISTS `users` (
  `username` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  `enabled` tinyint(1) NOT NULL,
  PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


INSERT INTO `users` (`username`, `password`, `enabled`) VALUES
('admin', 'admin', 1),
('guest', 'guest', 1),
('john', 'sabrina', 1);

有人可以告訴我為什么它不起作用! 我需要幫助

您需要通過查詢從數據庫中獲取用戶憑據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM