0 Replies Latest reply on Oct 22, 2009 7:05 PM by willie slepecki

    problem reimplementing a database connection

    willie slepecki Newbie

      6 months ago when i started this project, it wasn't supposed to have a database connection, everything is done using an xml system.  well now they changed that.  turns out i have to implement the remember me token, which needs a database connection to store the tokens.  now i can't figure out how i stripped the database stuff out and can't get it to store the tokens.  when i do i get this exception




      javax.servlet.ServletException: #{identity.login}: org.jboss.seam.security.management.IdentityManagementException: Could not create account
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.RewriteFilter.doFilter(RewriteFilter.java:63)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:42)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
              at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
              at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.faces.FacesException: #{identity.login}: org.jboss.seam.security.management.IdentityManagementException: Could not create account
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
              at javax.faces.component.UICommand.broadcast(UICommand.java:387)
              at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:318)
              at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:293)
              at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:250)
              at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:463)
              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
              ... 45 more
      Caused by: javax.faces.el.EvaluationException: org.jboss.seam.security.management.IdentityManagementException: Could not create account
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
              ... 54 more
      Caused by: org.jboss.seam.security.management.IdentityManagementException: Could not create account
              at org.jboss.seam.security.JpaTokenStore.createToken(JpaTokenStore.java:90)
              at org.jboss.seam.security.RememberMe.postAuthenticate(RememberMe.java:385)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2253)
              at org.jboss.seam.core.Events.raiseEvent(Events.java:85)
              at org.jboss.seam.security.Identity.postAuthenticate(Identity.java:397)
              at org.jboss.seam.security.Identity.authenticate(Identity.java:345)
              at org.jboss.seam.security.Identity.authenticate(Identity.java:332)
              at org.jboss.seam.security.Identity.login(Identity.java:259)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
              at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
              at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
              at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
              at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
              ... 55 more
      Caused by: java.lang.IllegalArgumentException: Unknown entity: com.show.pro.token.AuthenticationToken
              at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:223)
              at org.jboss.seam.persistence.EntityManagerProxy.persist(EntityManagerProxy.java:137)
              at org.jboss.seam.security.JpaTokenStore.createToken(JpaTokenStore.java:80)
              ... 79 more





      what am i missing?  here's the code


      package com.show.pro.token;
      
      import static javax.persistence.GenerationType.IDENTITY;
      
      import java.io.Serializable;
      
      import javax.persistence.Column;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.Table;
      
      import org.hibernate.annotations.Entity;
      import org.jboss.seam.annotations.security.TokenUsername;
      import org.jboss.seam.annotations.security.TokenValue;
      
      @Entity
      @Table(name = "tokens")
      public class AuthenticationToken implements Serializable
      {
              private static final long serialVersionUID = 1L;
              private Integer tokenId;
              private String username;
              private String value;
      
              @Id
              @GeneratedValue(strategy = IDENTITY)
              @Column(name = "tokenid", unique = true, nullable = false)
              public Integer getTokenId()
              {
                      return tokenId;
              }
      
              public void setTokenId(Integer tokenId)
              {
                      this.tokenId = tokenId;
              }
      
              @TokenUsername
              @Column(name = "userName", nullable = false, length = 45)
              public String getUsername()
              {
                      return username;
              }
      
              public void setUsername(String username)
              {
                      this.username = username;
              }
      
              @TokenValue
              @Column(name = "value", nullable = false, length = 255)
              public String getValue()
              {
                      return value;
              }
      
              public void setValue(String value)
              {
                      this.value = value;
              }
      }



      components.xml


      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
              xmlns:core="http://jboss.com/products/seam/core" xmlns:persistence="http://jboss.com/products/seam/persistence"
              xmlns:drools="http://jboss.com/products/seam/drools" xmlns:bpm="http://jboss.com/products/seam/bpm"
              xmlns:security="http://jboss.com/products/seam/security" xmlns:mail="http://jboss.com/products/seam/mail"
              xmlns:web="http://jboss.com/products/seam/web" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd"
              xmlns:async="http://jboss.com/products/seam/async">
      
              <!-- <core:init debug="@debug@" jndi-pattern="@jndiPattern@" /> -->
              <core:init debug="false" jndi-pattern="@jndiPattern@" />
      
              <core:manager concurrent-request-timeout="500"
                      conversation-timeout="120000" conversation-id-parameter="cid"
                      parent-conversation-id-parameter="pid" />
                      
              <web:hot-deploy-filter url-pattern="*.seam" />
      
              <persistence:managed-persistence-context name="entityManager" auto-create="true"
                      persistence-unit-jndi-name="java:/showproEntityManagerFactory"/>
              
              <security:jpa-token-store token-class="com.show.pro.token.AuthenticationToken"/>
              <security:remember-me mode="autoLogin"/>
              
              <drools:rule-base name="securityRules">
                      <drools:rule-files>
                              <value>/security.drl</value>
                      </drools:rule-files>
              </drools:rule-base>
      
              <security:rule-based-permission-resolver
                      security-rules="#{securityRules}" />
      
              <security:identity authenticate-method="#{authenticator.authenticate}"
                      remember-me="true" />
      
              <event type="org.jboss.seam.security.notLoggedIn">
                      <action execute="#{redirect.captureCurrentView}" />
                      <action execute="#{identity.tryLogin()}"/>
              </event>
              <event type="org.jboss.seam.security.loginSuccessful">
                      <action execute="#{redirect.returnToCapturedView}" />
              </event>
      
              <!--
                      <mail:mail-session host="localhost" port="2525" username="test"
                      password="test" />
              -->
      
              <event type="org.jboss.seam.postInitialization">
                      <action execute="#{jobController.scheduleTimer}" />
              </event>
      
              <!-- Install the QuartzDispatcher -->
              <async:quartz-dispatcher />
      
              <web:rewrite-filter />
      
              <!-- For use with jBPM pageflow or process management -->
              <bpm:jbpm>
                      <bpm:pageflow-definitions>
                              <value>/menu.jpdl.xml</value>
                              <value>/third.jpdl.xml</value>
                      </bpm:pageflow-definitions>
              </bpm:jbpm>
      
              <web:character-encoding-filter encoding="UTF-8" 
                      override-client="true" 
                      url-pattern="*.seam"/>
      </components>
      



      persistence.xml


      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
                   version="1.0">
                   
         <persistence-unit name="showpro">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>showproDatasource</jta-data-source>
            <jar-file>showpro.jar</jar-file>
            <class>com.show.pro.token.AuthenticationToken</class>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="update"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/showproEntityManagerFactory"/>
            </properties>
         </persistence-unit>
          
      </persistence>



      my ds.xml


      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE datasources
          PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
          "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
      <datasources>
         
         <local-tx-datasource>
            <jndi-name>showproDatasource</jndi-name>
            <use-java-context>false</use-java-context>
            <connection-url>jdbc:mysql://localhost/showpro</connection-url>
            <driver-class>com.mysql.jdbc.Driver</driver-class>
            <user-name>root</user-name>
            <password></password>
         </local-tx-datasource>
          
      </datasources>
      



      and lastely my web.xml


      <?xml version="1.0"?>
      <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
       <!--  custom showroom components -->
       <context-param>
        <param-name>facelets.LIBRARIES</param-name>
        <param-value>/WEB-INF/showroom-taglib.xml</param-value>
       </context-param>
       <!-- RichFaces -->
       <context-param>
        <param-name>org.richfaces.SKIN</param-name>
        <param-value>classic</param-value>
       </context-param>
       <!-- Suppress spurious stylesheets -->
       <context-param>
        <param-name>org.richfaces.CONTROL_SKINNING</param-name>
        <param-value>disable</param-value>
       </context-param>
       <context-param>
        <param-name>org.richfaces.CONTROL_SKINNING_CLASSES</param-name>
        <param-value>disable</param-value>
       </context-param>
       <!-- Change load strategy to DEFAULT to disable sending scripts/styles as packs -->
       <context-param>
        <param-name>org.richfaces.LoadStyleStrategy</param-name>
        <param-value>ALL</param-value>
       </context-param>
       <context-param>
        <param-name>org.richfaces.LoadScriptStrategy</param-name>
        <param-value>ALL</param-value>
       </context-param>
       <!-- Facelets development mode (disable in production) -->
       <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>false</param-value>
       </context-param>
       <!-- JSF -->
       <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
       </context-param>
       <filter>
        <filter-name>Seam Filter</filter-name>
        <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
       </filter>
       <filter-mapping>
        <filter-name>Seam Filter</filter-name>
        <url-pattern>/*</url-pattern>
       </filter-mapping>
       <!-- Seam -->
       <listener>
        <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
       </listener>
       <servlet>
        <servlet-name>Seam Resource Servlet</servlet-name>
        <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
       </servlet>
       <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
       </servlet>
       <servlet-mapping>
        <servlet-name>Seam Resource Servlet</servlet-name>
        <url-pattern>/seam/resource/*</url-pattern>
       </servlet-mapping>
       <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.seam</url-pattern>
       </servlet-mapping>
       <security-constraint>
        <display-name>Restrict raw XHTML Documents</display-name>
        <web-resource-collection>
         <web-resource-name>XHTML</web-resource-name>
         <url-pattern>*.xhtml</url-pattern>
        </web-resource-collection>
        <auth-constraint/>
       </security-constraint>
       <login-config>
        <auth-method>BASIC</auth-method>
       </login-config>
       <persistence-unit-ref>
            <persistence-unit-ref-name>showpro/pu</persistence-unit-ref-name>
            <persistence-unit-name>../showpro.jar#showpro</persistence-unit-name>
         </persistence-unit-ref>
      </web-app>
      



      any ideas why this is failing?