开发者

Spring3 Security using JDBC and stopped working

开发者 https://www.devze.com 2023-02-19 22:49 出处:网络
Spring 3 using Spring Security should be easy but I know I am doing something not right.I am making a sample Spring3 Web App and I used Spring Security for my web app. After two weeks of debug and not

Spring 3 using Spring Security should be easy but I know I am doing something not right. I am making a sample Spring3 Web App and I used Spring Security for my web app. After two weeks of debug and not getting it working I found out it was something in my web.xml and now it works great. But I need to move the users from the XML file to a MySQL database. So I remove the users from the XML file and change my file to look like the following:

<?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="/**" acce开发者_开发百科ss="IS_AUTHENTICATED_ANONYMOUSLY" />
        </http>
    <authentication-manager alias="authenticationManager">
        <authentication-provider>
            <jdbc-user-service data-source-ref="dataSource"/>
        </authentication-provider>
    </authentication-manager>
</beans:beans>

I made my SQL database with the following:

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);

Can someone please tell me why it is not working! I need help


you need to get the user credentials from the data base through a query.

0

精彩评论

暂无评论...
验证码 换一张
取 消