3 Replies Latest reply on Sep 3, 2004 5:06 PM by danl_thompson

    Storing lastUpdatedBy for database update history

    danl_thompson

      Faced with a requirement to store the who added / updated a record and when, I can only come up with two ideas. See if these make sense or if there is another, more standard way to handle it.

      The requirement is that whenever a user takes an action that results in the addition of, or update to a database record, we timestamp the record and update a lastModifiedBy column with his userID.

      The first way of doing this would be, I suppose, to explicitly pass the userID in to all transactions that update the database, to explicity have setters for these columns in the entity beans, and religiously force all the business logic to set the lastModifiedBy property appropriately.

      The second way would be to get the UserPrincipal, possibly in the EJBstore method of each entity bean, and set the lastModifiedBy column there. This seems to place no burden on the business logic but I suppose would require some JAAS security stuff to be enabled on the EntityBeans.

      Other thoughts? Suggestions?
      dt

        • 1. Re: Storing lastUpdatedBy for database update history
          schmidts

          Check out the "audit" element in http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd and see if "updated-by" and "updated-time" is what you are looking for.

          As you stated, Entity Beans need to be put in a JAAS security domain to make this make - otherwise you cannot retrieve the principal.

          • 2. Re: Storing lastUpdatedBy for database update history
            danl_thompson

            It looks like the "audit" element would certainly work, but I've been at it all day, and I can't seem to figure out the right combination of xdoclet tags to get it to run without throwing exceptions.

            My web container is already running under java:/jaas/myLogin

            Because of this and because I know that the EJB container runs in the same JVM, the EJB container SHOULD automatically use the same domain as the web container. But even so, I must add a securitydomain attribute to my ejbdoclet 's <jboss tag. which then ends up in the jboss.xml. This in order to get clean deployment.

            Next I've added the audit tags to my EJB as follows:
            * @jboss.audit-created-by
            * field-name="createdBy"
            * column-name="CREATED_BY"
            * @jboss.audit-created-time
            * field-name="createdTime"
            * column-name="CREATED_TIME"
            * @jboss.audit-updated-by

            Clean deployment, but accessing the bean by an authenticated web user results in:

            No method permissions assigned to method=create, interface=HOME

            So next I've added an @ejb.permissions unchecked="true" in some vague and hopeless attempt to get some permissions assigned... but this seems to have no effect on the ejb-jar.xml

            So I'm lost as to what the next steps should be.

            Any help, anyone can provide would be appreciated.

            dt






            • 3. Re: Storing lastUpdatedBy for database update history
              danl_thompson

              I'm sorry it is @ejb:permission not permissions

              and while it does add a method-permission area as follows:

              <method-permission >
              <![CDATA[description not supported yet by ejbdoclet]]>


              <![CDATA[description not supported yet by ejbdoclet]]>
              <ejb-name>MyTest</ejb-name>
              <method-name>*</method-name>

              </method-permission>


              the same error shows up...

              javax.ejb.EJBException: checkSecurityAssociation; CausedByException is:
              No method permissions assigned to method=create, interface=HOME

              so... I still need some help.
              dt