如何使用postgresql运行jsfsecure示例?

时间:2014-12-11 15:15:34

标签: postgresql spring-security glassfish-4

我想使用postgresql数据库运行此示例https://github.com/jlombardo/jsfsecure。但是我得到了这个错误:

  

信息:2014-12-11 14:41:25,801 WARN [http-listener-2(4)]   o.s.s.a.e.LoggerListener [LoggerListener.java:60]认证事件   AuthenticationFailureServiceExceptionEvent:bob@isp.com;细节:   org.springframework.security.web.authentication.WebAuthenticationDetails@2cd90:   RemoteIpAddress:0:0:0:0:0:0:0:1; SESSIONID:   995186d15b1b7f691d28834daa2d; exception:PreparedStatementCallback;   糟糕的SQL语法[选择用户名,密码,从用户所在位置启用   username =?];嵌套异常是org.postgresql.util.PSQLException:   FEHLER:Spalte“用户名”existsiert nicht

以下是日志中的内容:

Information:   2014-12-11 14:41:25,409 DEBUG [http-listener-2(4)] e.w.m.g.j.j.LoginBean [LoginBean.java:47] **** Executing doLogin method of LoginBean...
Information:   2014-12-11 14:41:25,415 DEBUG [http-listener-2(4)] o.s.s.w.FilterChainProxy [FilterChainProxy.java:337] /j_spring_security_check?j_username=bob@isp.com&j_password=password1 at position 1 of 12 in additional filter chain; firing Filter: 'ChannelProcessingFilter'
Information:   2014-12-11 14:41:25,415 DEBUG [http-listener-2(4)] o.s.s.w.u.m.AntPathRequestMatcher [AntPathRequestMatcher.java:145] Checking match of request : '/j_spring_security_check'; against '/faces/admin/**'
Information:   2014-12-11 14:41:25,415 DEBUG [http-listener-2(4)] o.s.s.w.u.m.AntPathRequestMatcher [AntPathRequestMatcher.java:145] Checking match of request : '/j_spring_security_check'; against '/faces/users/**'
Information:   2014-12-11 14:41:25,416 DEBUG [http-listener-2(4)] o.s.s.w.FilterChainProxy [FilterChainProxy.java:337] /j_spring_security_check?j_username=bob@isp.com&j_password=password1 at position 2 of 12 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
Information:   2014-12-11 14:41:25,416 DEBUG [http-listener-2(4)] o.s.s.w.FilterChainProxy [FilterChainProxy.java:337] /j_spring_security_check?j_username=bob@isp.com&j_password=password1 at position 3 of 12 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
Information:   2014-12-11 14:41:25,416 DEBUG [http-listener-2(4)] o.s.s.w.FilterChainProxy [FilterChainProxy.java:337] /j_spring_security_check?j_username=bob@isp.com&j_password=password1 at position 4 of 12 in additional filter chain; firing Filter: 'LogoutFilter'
Information:   2014-12-11 14:41:25,416 DEBUG [http-listener-2(4)] o.s.s.w.FilterChainProxy [FilterChainProxy.java:337] /j_spring_security_check?j_username=bob@isp.com&j_password=password1 at position 5 of 12 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
Information:   2014-12-11 14:41:25,417 DEBUG [http-listener-2(4)] o.s.s.w.a.UsernamePasswordAuthenticationFilter [AbstractAuthenticationProcessingFilter.java:205] Request is to process authentication
Information:   2014-12-11 14:41:25,418 DEBUG [http-listener-2(4)] o.s.s.a.ProviderManager [ProviderManager.java:152] Authentication attempt using org.springframework.security.authentication.dao.DaoAuthenticationProvider
Information:   2014-12-11 14:41:25,431 DEBUG [http-listener-2(4)] o.s.j.c.JdbcTemplate [JdbcTemplate.java:693] Executing prepared SQL query
Information:   2014-12-11 14:41:25,433 DEBUG [http-listener-2(4)] o.s.j.c.JdbcTemplate [JdbcTemplate.java:627] Executing prepared SQL statement [select username,password,enabled from users where username = ?]
Information:   2014-12-11 14:41:25,450 DEBUG [http-listener-2(4)] o.s.j.d.DataSourceUtils [DataSourceUtils.java:110] Fetching JDBC Connection from DataSource
Information:   2014-12-11 14:41:25,705 DEBUG [http-listener-2(4)] o.s.j.d.DataSourceUtils [DataSourceUtils.java:327] Returning JDBC Connection to DataSource
Information:   2014-12-11 14:41:25,741 DEBUG [http-listener-2(4)] o.s.c.e.StandardEnvironment [MutablePropertySources.java:110] Adding [systemProperties] PropertySource with lowest search precedence
Information:   2014-12-11 14:41:25,742 DEBUG [http-listener-2(4)] o.s.c.e.StandardEnvironment [MutablePropertySources.java:110] Adding [systemEnvironment] PropertySource with lowest search precedence
Information:   2014-12-11 14:41:25,742 DEBUG [http-listener-2(4)] o.s.c.e.StandardEnvironment [AbstractEnvironment.java:126] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
Information:   2014-12-11 14:41:25,744 INFO [http-listener-2(4)] o.s.b.f.x.XmlBeanDefinitionReader [XmlBeanDefinitionReader.java:316] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
Information:   2014-12-11 14:41:25,744 DEBUG [http-listener-2(4)] o.s.b.f.x.DefaultDocumentLoader [DefaultDocumentLoader.java:73] Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
Information:   2014-12-11 14:41:25,747 DEBUG [http-listener-2(4)] o.s.b.f.x.BeansDtdResolver [BeansDtdResolver.java:74] Found beans DTD [http://www.springframework.org/dtd/spring-beans-2.0.dtd] in classpath: spring-beans-2.0.dtd
Information:   2014-12-11 14:41:25,754 DEBUG [http-listener-2(4)] o.s.b.f.x.DefaultBeanDefinitionDocumentReader [DefaultBeanDefinitionDocumentReader.java:108] Loading bean definitions

[...]

Information:   2014-12-11 14:41:25,800 DEBUG [http-listener-2(4)] o.s.j.s.SQLErrorCodeSQLExceptionTranslator [SQLErrorCodeSQLExceptionTranslator.java:281] Unable to translate SQLException with SQL state '42703', error code '0, will now try the fallback translator
Information:   2014-12-11 14:41:25,800 DEBUG [http-listener-2(4)] o.s.j.s.SQLStateSQLExceptionTranslator [SQLStateSQLExceptionTranslator.java:94] Extracted SQL state class '42' from value '42703'
Information:   2014-12-11 14:41:25,801 DEBUG [http-listener-2(4)] o.s.b.f.s.DefaultListableBeanFactory [AbstractBeanFactory.java:249] Returning cached instance of singleton bean 'loggerListener'
Information:   2014-12-11 14:41:25,801 WARN [http-listener-2(4)] o.s.s.a.e.LoggerListener [LoggerListener.java:60] Authentication event AuthenticationFailureServiceExceptionEvent: bob@isp.com; details: org.springframework.security.web.authentication.WebAuthenticationDetails@2cd90: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 995186d15b1b7f691d28834daa2d; exception: PreparedStatementCallback; bad SQL grammar [select username,password,enabled from users where username = ?]; nested exception is org.postgresql.util.PSQLException: FEHLER: Spalte „username“ existiert nicht  Position: 8
Information:   2014-12-11 14:41:25,801 DEBUG [http-listener-2(4)] o.s.s.w.a.UsernamePasswordAuthenticationFilter [AbstractAuthenticationProcessingFilter.java:348] Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: PreparedStatementCallback; bad SQL grammar [select username,password,enabled from users where username = ?]; nested exception is org.postgresql.util.PSQLException: FEHLER: Spalte „username“ existiert nicht  Position: 8

我的createdb.sql脚本:

DROP TABLE IF EXISTS users CASCADE;
CREATE TABLE users
 (
      username varchar(255) NOT NULL,
      password varchar(255) DEFAULT NULL,
      enabled boolean DEFAULT false,
      PRIMARY KEY(username)
 );

DROP TABLE IF EXISTS authorities;
CREATE TABLE authorities
 (
     username varchar(50) NOT NULL,
     authority varchar(50) NOT NULL DEFAULT 'ROLE_USER',
     authorities_id serial PRIMARY KEY,
     CONSTRAINT ix_auth_username UNIQUE (username, authority),
     CONSTRAINT fk_authorities_users FOREIGN KEY (username) REFERENCES users (username)
 );

INSERT INTO users VALUES('bob@isp.com','bfff7a2fd68c19738012752f9d023712fd2d7201c6f771da910946f41171e4df8d2921c5bdd4d9189c0a6f162e61aec570c0d228df5ddfd4fb0634e32f0320d5','1');
INSERT INTO users VALUES('sally@isp.com','f7a09271901560af708fc65bba63c5ad592eed33e520fc8d73b4c112e27a50adee6e201c45e9532d1667233555d97d6e60b8ec134f04fd5145a5e3fee0fcdaa3','1');
INSERT INTO users VALUES('tom@isp.com','1dca67581a5f684be074b6f130c405e57d85278dae9c32104e35b078f6385cae275a8feab21f401f8732239a2785dba9e3f340181811509f1858d56e249a5443','1');

INSERT INTO authorities VALUES('bob@isp.com','ROLE_ADMIN',1);
INSERT INTO authorities VALUES('sally@isp.com','ROLE_USER',2);
INSERT INTO authorities VALUES('tom@isp.com','ROLE_USER',3);

(以上是password1,password2和password3的哈希值。)

的glassfish-resources.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
  <jdbc-resource enabled="true" jndi-name="jdbc/springSecurityDatasource" object-type="user" pool-name="springJdbcPool">
    <description/>
  </jdbc-resource>
  <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="table" datasource-classname="org.postgresql.ds.PGSimpleDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="springJdbcPool" non-transactional-connections="false" ping="false" pool-resize-quantity="2" pooling="true" res-type="javax.sql.DataSource" statement-cache-size="0" statement-leak-reclaim="false" statement-leak-timeout-in-seconds="0" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="true">
    <property name="URL" value="jdbc:postgresql://localhost:5432/springjdbc"/>
    <property name="User" value="postgres"/>
    <property name="Password" value="***"/>
  </jdbc-connection-pool>
</resources>

我的glassfish 4.1配置:

asadmin > create-jdbc-connection-pool --restype=javax.sql.DataSource --datasourceclassname=org.postgresql.ds.PGSimpleDataSource --property=user=postgres:password=***:serverName=localhost:portNumber=5432:databaseName=springjdbc springJdbcPool
asadmin > create-jdbc-resource --connectionpoolid postgreSQLJDBCPool jdbc/springSecurityDatasource

的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="jsfsecurePU" transaction-type="JTA">
    <jta-data-source>jdbc/springSecurityDatasource</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

1 个答案:

答案 0 :(得分:0)

错误在这里:

asadmin > create-jdbc-resource --connectionpoolid postgreSQLJDBCPool jdbc/springSecurityDatasource

当然必须是 springJdbcPool ! 只是一个愚蠢的复制和粘贴错误。

感谢来自## friendlyjava的脉冲星和aditsu!