Pessoal, Bom Dia
Estou estudando spring security, consigo pega usuario e senha e roler de um arquivo "users.properties" e controlar as páginas <security:intercept-url pattern="/**" access="ROLE_USER" />
Funciona perfeitamente, eu estou achando maravilhoso isso ! Estou usando :spring-security-core-2.0.0.jar
Só que eu gostaria de pegar estes valores "prime=faces,ROLE_USER,enabled" não de um arquivo "users.properties" , mas sim de um banco de dados Postgresql.
Não consigo configurar :
[quote] <security:authentication-provider>
<security:user-service properties=“classpath:users.properties”>
</security:user-service>
</security:authentication-provider>[/quote]
PARA:
[quote] <authentication-provider>
<jdbc-user-service data-source-ref=“securityDataSource”/>
</authentication-provider>
[/quote]
Dei uma lida na :http://static.springsource.org/spring-security/site/docs/2.0.x/reference/ns-config.html#ns-auth-providers mas não ajudou !
Estou usando este esquema de banco:
[quote]create table users(
username varchar_ignorecase(50) not null primary key,
password varchar_ignorecase(50) not null,
enabled boolean not null);
create table authorities (
username varchar_ignorecase(50) not null,
authority varchar_ignorecase(50) not null,
constraint fk_authorities_users foreign key(username) references users(username));
create unique index ix_auth_username on authorities (username,authority);
[/quote]
Segue o meu arquivo:
[code]<?xml version=“1.0” encoding=“UTF-8”?>
<beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns:context=“http://www.springframework.org/schema/context”
xmlns:tx=“http://www.springframework.org/schema/tx”
xmlns:security=“http://www.springframework.org/schema/security”
xmlns:lang=“http://www.springframework.org/schema/lang”
xsi:schemaLocation=“http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang-2.5.xsd”>
<context:property-placeholder location="classpath:application.properties"/>
<context:component-scan base-package="org.primefaces.examples.moviecollector" />
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="prime-moviecollector"/>
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="${database.target}"/>
<property name="showSql" value="${database.showSql}" />
<property name="generateDdl" value="${database.generateDdl}" />
</bean>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/nutec"/>
<property name="username" value="root"/>
<property name="password" value="debian23"/>
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<security:http auto-config='true'>
<security:intercept-url pattern="/**" access="ROLE_USER" />
<security:concurrent-session-control max-sessions="1"/>
<security:logout logout-url="/logout" logout-success-url="/"/>
</security:http>
<security:authentication-provider>
<security:user-service properties="classpath:users.properties">
</security:user-service>
</security:authentication-provider>
</beans>[/code]