applicationContext.xml + Postgresql

0 respostas
juniorsatanas

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 :

<security:authentication-provider> <security:user-service properties="classpath:users.properties"> </security:user-service> </security:authentication-provider>
PARA:
<authentication-provider> <jdbc-user-service data-source-ref="securityDataSource"/> </authentication-provider>

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:

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


Segue o meu arquivo:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;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"&gt;

	&lt;context:property-placeholder location="classpath:application.properties"/&gt;
	
	&lt;context:component-scan base-package="org.primefaces.examples.moviecollector" /&gt;
	
	&lt;tx:annotation-driven transaction-manager="txManager"/&gt;
	
	&lt;bean id="entityManagerFactory"  
	      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;  
         &lt;property name="persistenceUnitName" value="prime-moviecollector"/&gt;  
         &lt;property name="dataSource" ref="dataSource" /&gt;  
         &lt;property name="jpaVendorAdapter"&gt;  
             &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;  
                 &lt;property name="databasePlatform" value="${database.target}"/&gt;  
                 &lt;property name="showSql" value="${database.showSql}" /&gt;  
                 &lt;property name="generateDdl" value="${database.generateDdl}" /&gt;  
             &lt;/bean&gt;  
         &lt;/property&gt;  
    &lt;/bean&gt;  
	
	&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close"&gt;
        &lt;property name="driverClassName" value="org.postgresql.Driver"/&gt;
        &lt;property name="url" value="jdbc:postgresql://localhost:5432/nutec"/&gt;
        &lt;property name="username" value="root"/&gt;
        &lt;property name="password" value="debian23"/&gt;
    &lt;/bean&gt;

	&lt;bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
		&lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
	&lt;/bean&gt;
	
	&lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/&gt;
	
	&lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;

	&lt;security:http auto-config='true'&gt;
    	&lt;security:intercept-url pattern="/**" access="ROLE_USER" /&gt;
    	&lt;security:concurrent-session-control max-sessions="1"/&gt;
    	&lt;security:logout logout-url="/logout" logout-success-url="/"/&gt;
  	&lt;/security:http&gt;
  	
  	&lt;security:authentication-provider&gt;
    	&lt;security:user-service properties="classpath:users.properties"&gt;
      	&lt;/security:user-service&gt;
  	&lt;/security:authentication-provider&gt;
&lt;/beans&gt;
Criado 16 de agosto de 2010
Respostas 0
Participantes 1