Search This Blog

Wednesday, 8 June 2011

Using Spring Security with JDBC

First we need two tables.We will execute the following queries to create the tables.
create table users (username varchar(50) not null primary key,password varchar(50) not null,enabled boolean not null);

create table authorities (
    username varchar(50) not null,
    authority varchar(50) not null,
    foreign key (username) references users (username),
    unique index ix_auth_username (username, authority)
);
Then, we will insert some data into the tables.
INSERT INTO users VALUES ('sandeep', '00f1de4e151ccfc1fc9ff735a5efc479', true);
INSERT INTO users VALUES ('vijay',   'e555f863fb09593119fe2f3459e9783a', true);
INSERT INTO authorities VALUES ('sandeep', 'ROLE_ADMIN');
INSERT INTO authorities VALUES ('sandeep', 'ROLE_USER');
INSERT INTO authorities VALUES ('vijay',   'ROLE_USER');
Now we will change the applicationContext-security.xml of our login example, to configure JDBC.

    
        
         
         
    
Finally,we need the 'datasource.xml'. This is based on MySQL.


    
        
            com.mysql.jdbc.Driver
        
        
            jdbc:mysql://localhost:3306/test
        
        
            root
        
        
            sandeep
        
    

No comments:

Post a Comment