-
1. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
manica Aug 4, 2005 10:42 AM (in response to gdellelce)You can inject the context like so:
@Resource javax.ejb.SessionContext ctx;
Darin -
2. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
milx Sep 2, 2005 1:03 PM (in response to gdellelce)I'm unable to inject the SessionContext either in the entity itself or in a separate class, it is null at the @PrePersist callback. Does security have to be configured in order to inject the SessionContext?
I can access the EJBContext from the javax.ejb.InvocationContext in an @AroundInvoke interceptor method. -
3. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
epbernard Sep 8, 2005 12:09 PM (in response to gdellelce)There is no context for an entity bean.
Only for Session and MDB -
4. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
gdellelce Sep 12, 2005 3:32 AM (in response to gdellelce)So the question is: What is the best way to know the caller principal in an Entity Bean in EJB3.0?
-
5. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
bill.burke Sep 12, 2005 2:31 PM (in response to gdellelce)"gdellelce" wrote:
So the question is: What is the best way to know the caller principal in an Entity Bean in EJB3.0?
Wrap your EntityBean access from within a @Stateless bean and get it from the SessionContext.
Or, get it from your ServletContext if you're invoking on a servlet. -
6. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
gdellelce Sep 13, 2005 5:20 AM (in response to gdellelce)I've a table like this:
create table theEntity(
id integer primary key not null,
....
// Audit fields
createdBy varchar(....) not null,
createDate timestamp not null,
modifiedBy varchar(...) not null,
modifyDate timestamp not null
);
so I would like to have an Entity with a @PrePersist and a @PreUpdate
like this
@PrePersist
public void prePersist() {
if (getCreateDate() == null)
setCreateDate(new java.util.Date());
if (getCreatedBy() == null)
setCreatedBy(ctx.getCallerPrincipal().getName());
preUpdate();
}
@PreUpdate
public void preUpdate() {
setModifyDate(new java.util.Date());
setModifiedBy(ctx.getCallerPrincipal().getName());
}
like a database trigger so I don't have to take care of this fields in the code.
Gianfranco -
7. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
bigm25 Sep 13, 2005 5:25 AM (in response to gdellelce)So it looks like it's not possible to have some "audit"-fields in EJB3.
But JBoss 3 had some "proprietary" extensions for such audit-fields.
Any chance that such extension will be available with JBoss3 AND EJB3 ??
Rgds. -
8. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
epbernard Sep 13, 2005 6:59 AM (in response to gdellelce)"bigm25" wrote:
So it looks like it's not possible to have some "audit"-fields in EJB3.
What are you talking about? -
9. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
bigm25 Sep 13, 2005 7:11 AM (in response to gdellelce)In Jboss 3.2 we were using the following stuff in "jbosscmp-jdb.xml":
<entity> ...... ..... <audit> <created-by> <column-name>createdby</column-name> </created-by> <created-time> <column-name>createdtime</column-name> </created-time> <updated-by> <column-name>updatedby</column-name> </updated-by> <updated-time> <column-name>updatedtime</column-name> </updated-time> </audit> </entity>
and JBoss happily stored the time/principial of any changes or creations, no matter which code actually triggerd the update/store.
So the question is, how to achieve the same effect with JBoss4 AND EJB3, since there is neither a "jbosscmp-jdbc.xml", nor can we get the callerPrincipal from within an entity.
Did i miss something or wouldn't this be a nice "extension" to implement? -
10. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
michael_c_small Sep 23, 2005 12:07 PM (in response to gdellelce)Did you get an answer on this question? I'm trying to perform the same functionality. My only thought was to create a utility session bean that not only injects the session context through a setter method, but also provides a getter method.
-
11. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
gdellelce Sep 26, 2005 3:53 AM (in response to gdellelce)No answer until now. But I think that a session bean isn't the solution to every situation because you could have cascade persistence and in this case can
miss some modifyBy updates. -
12. Re: EJB 3.0: getCallerPrincipal in Entity Bean?
bill.burke Sep 26, 2005 10:51 AM (in response to gdellelce)You have to use a session bean in front or you can use
org.jboss.aspects.security.SecurityContext
which is proprietary
We also have JACC integration with CRUD operations but really haven't documented it well yet.