[JBoss Portal] - Problems with Custom DatabaseServerLoginModule Roles
by Bruno Santos
Bruno Santos [http://community.jboss.org/people/bmsantos] created the discussion
"Problems with Custom DatabaseServerLoginModule Roles"
To view the discussion, visit: http://community.jboss.org/message/621524#621524
--------------------------------------------------------------
OK! My bad... forget about it!
Something rather strange is happening to my custom database login module and I'm sure I'm missing something.
I have a class that inherits from DatabaseServerLoginModule. The login method is overwritten and in here, the parent login method is always called. If the login failed then the class tries to login using LDAP. If LDAP succeeds to validate the user credentials then it sets the loginOk flag to true.
Now, if the user is successfully validated against the parent login DB method the getRoleSets method gets called and the roles returned. If the user fails to be validated against DB but it is successfully validated against the LDAP server, the same roles are returned but somehow I'm never able to get receive it at the other end of the application.
protected Group[] getRoleSets() throws LoginException {
String name = getUsername();
Group[] groups = {new SimpleGroup("Roles")};
try {
Principal principal;
principal = this.createIdentity("ADMIN");
groups[0].addMember(principal);
principal = this.createIdentity("USER");
groups[0].addMember(principal);
} catch(Exception ee) {}
return groups;
}
So, basically the difference is that if in the login method the super.login() succeeds, then everything ends up working and the necessary credentials are received as expected. If it fails I never get the credentials even though the loginOk flag is set and the getRolesSet method is called. Through the debugger I've noticed that the Identity gets created as expected. Still, I'm missing something...
I've looked for the base source code (DatabaseServerLoginModule and up) but I could not find it for JBoss AS 6 and I'm stuck right now. I did find older versions and from it I could not really understand why this is not working.
Thanks
--- Update: Just override the commit() method in order to find what the subject.getPrincipals() gets set with and it happens that in both cases the subject does contain the necessary info to proceed:
@Override
public boolean commit() throws LoginException {
boolean b = super.commit();
Set<Principal> pList = subject.getPrincipals(); // Returns [admin, Roles(members:ADMIN,USER)] for DB login and [bsantos, Roles(members:ADMIN,USER)] for LDAP login.
return b;
}
This confirms that the issue is somewhere in a failed login method.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/621524#621524]
Start a new discussion in JBoss Portal at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 8 months
[EJB3] - Field 'record_EMP_ID' doesn't have a default value
by Joseph Hwang
Joseph Hwang [http://community.jboss.org/people/aupres] created the discussion
"Field 'record_EMP_ID' doesn't have a default value"
To view the discussion, visit: http://community.jboss.org/message/621434#621434
--------------------------------------------------------------
I solved org.hibernate.TransientObjectException (http://community.jboss.org/thread/171019?tstart=0) by adding "@OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL)"
But this time values can't be inserted to DB.
OS : Windows 7
JDK : JDK 1.6
JBoss : JBoss 5.1.0.GA
DB : MySQL 5.5
Error is "Field 'record_EMP_ID' doesn't have a default value"
*- Members.java*
@Entity
@Table(name = "family")
public class Members implements Serializable {
@Id
@Column(name = "EMP_ID")
private String id ;
@Column(name = "EMP_Passwd")
private String passwd ;
@Column(name = "EMP_Name")
private String name ;
@OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
@JoinTable(name="info", joinColumns = {@JoinColumn(name (http://community.jboss.org/mailto:%7B@JoinColumn(name) = "EMP_Name")})
private Collection<Records> record = new ArrayList();
....getter and setter
}
*- Records.java*
@Entity
@Table(name = "info")
public class Records implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "EMP_ID")
private int i;
@Column(name = "EMP_Name")
private String name;
@Column(name = "EMP_Bank_Account")
private String account;
@Column(name = "EMP_Hobby")
private String hobby;
@Column(name = "EMP_Phone")
private int phone;
...getter and setter method
}
in jsp file I invoke EntityManager.persist
Context ctx = new InitialContext();
IMappingTestPort port = (IMappingTestPort) ctx.lookup("MappingTestBean/remote");
Records r = new Records();
r.setName("aaa");
r.setAccount("111-2222");
r.setHobby("bbb");
r.setPhone(021112222);
Members m = new Members();
m.setId("aupres");
m.setPasswd("aaa");
m.setName("ccc");
m.getRecord().add(r);
port.setFamilyMember(m); // This EntityManager.persist method
But it failed.
In console
20:21:29,233 INFO [STDOUT] Hibernate: insert into family (EMP_Name, EMP_Passwd, EMP_ID) values (?, ?, ?)
20:21:29,268 INFO [STDOUT] Hibernate: insert into info (EMP_Bank_Account, EMP_Hobby, EMP_Name, EMP_Phone) values (?, ?, ?, ?)
20:21:29,288 WARN [JDBCExceptionReporter] SQL Error: 1364, SQLState: HY000
20:21:29,288 ERROR [JDBCExceptionReporter] Field 'record_EMP_ID' doesn't have a default value
record_EMP_ID is automatically generated by hibernate
Pls help!
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/621434#621434]
Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 8 months
[EJB3] - org.hibernate.TransientObjectException?
by Joseph Hwang
Joseph Hwang [http://community.jboss.org/people/aupres] created the discussion
"org.hibernate.TransientObjectException?"
To view the discussion, visit: http://community.jboss.org/message/621364#621364
--------------------------------------------------------------
Pls, Check my codes. I made two Entity Beans.
-Members.java
package com.aaa.ejb3;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name = "family")
public class Members implements Serializable {
@Id
@Column(name = "EMP_ID")
private String id ;
@Column(name = "EMP_Passwd")
private String passwd ;
@Column(name = "EMP_Name")
private String name ;
@OneToMany(fetch=FetchType.EAGER)
@JoinTable(name="info", joinColumns = {@JoinColumn(name = "EMP_Name")})
private Collection<Records> record = new ArrayList();
....
}
- Records.java
package com.aaa.ejb3;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "info")
public class Records implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
@Column(name = "EMP_ID")
private int i;
@Column(name = "EMP_Name")
private String name;
....
}
and I added EntityManager in EJB Bean like below
-MappingTestBean.java
package com.aaa.ejb3;
import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class MappingTestBean implements IMappingTestPort {
@PersistenceContext(unitName="MyFamily")
EntityManager em;
public Collection<Records> getFamilyMember(String name) {
// TODO Auto-generated method stub
Members m = (Members)em.find(Members.class, name);
Collection<Records> records = m.getRecord();
return records;
}
public void setFamilyMember(Members m){
em.persist(m);
}
}
Deployment of EJB3 Beans are successfull.
In JSP I invoke the method
try {
Context ctx = new InitialContext();
IMappingTestPort port = (IMappingTestPort) ctx.lookup("MappingTestBean/remote");
Records r = new Records();
r.setName("aaa");
r.setAccount("111-2222");
r.setHobby("bbb");
r.setPhone(021112222);
Members m = new Members();
m.setId("aupres");
m.setPasswd("aaa");
m.setName("vvv");
m.getRecord().add(r);
port.setFamilyMember(m);
But Exception Occurs. The Exception is
20:02:43,005 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.aaa.ejb3.Records
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:242)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:430)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:101)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:777)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1165)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:504)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:269)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:89)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1423)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:137)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:170)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:421)
at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:85)
at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
at $Proxy310.invoke(Unknown Source)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
at $Proxy309.setFamilyMember(Unknown Source)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:92)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
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.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:662)
I need your advice! Thanks in advance.
Best Regards.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/621364#621364]
Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 8 months