You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 23 Members of 4546 |
| Forum: Seam Users |
22. May 2008, 22:38 CET | Link |
I am facing issues while authenticating user through Seam Remoting. Here is the scenario, I have a popup widget, which will obtain user/password from the user and onclick of login button it invokes SLSB and Identity.login and hence registered authenticator would be called from Seam. But it is not happening. Here is Components.xml code
<security:identity authenticate-method="#{serviceAuthenticator.authenticate}"/>
Here is web.xml
<ejb-local-ref>
<ejb-ref-name>evolve/EvolveAuthBean/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>evolve.user.ejb.EvolveAuthLocal</local>
<ejb-link>EvolveAuthBean</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>evolve/AjaxLoginBeanBean/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>evolve.user.ejb.AjaxLoginBeanLocal</local>
<ejb-link>AjaxLoginBeanBean</ejb-link>
</ejb-local-ref>
Here is the Code for serviceAuthenticator, it is taken from seam booking example,
@Stateless
@Name("serviceAuthenticator")
public class EvolveAuthBean implements EvolveAuthLocal {
@In
Identity identity;
public boolean authenticate() {
this.loggedInUser = new User(identity.getUsername(), identity.getPassword(), identity.getUsername());
return true;
}
}
One more SLSB to do remoting and authentication,
Here is the code,
@Name("AjaxLogin")
@Stateless
public class AjaxLoginBeanBean implements AjaxLoginBeanLocal {
@In (create=true)
Identity identity;
@WebRemote
public User login(String userName, String password) {
identity.setUsername(userName);
identity.setPassword(password);
String loggedIn = identity.login();
return user;
}
}
I got below errors,
15:21:57,923 ERROR [SeamLoginModule] Error invoking login method
org.jboss.seam.InstantiationException: Could not instantiate Seam component: serviceAuthenticator
at org.jboss.seam.Component.newInstance(Component.java:1970)
at org.jboss.seam.Component.getInstance(Component.java:1873)
at org.jboss.seam.Component.getInstance(Component.java:1840)
at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
.
.
.
Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/env/evolve/EvolveAuthBean/local
at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:834)
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:173)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:396)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.jboss.seam.Component.instantiateSessionBean(Component.java:1287)
at org.jboss.seam.Component.instantiate(Component.java:1273)
at org.jboss.seam.Component.newInstance(Component.java:1966)
... 130 more
15:21:57,923 DEBUG [Identity] Login failed for: function () {
var newArgs = [];
for (var x = 0; x < args.length; ++x) {
newArgs.push(args[x]);
}
for (var x = 0; x < arguments.length; ++x) {
newArgs.push(arguments[x]);
}
return fcn.apply(thisPtr, newArgs);
}
javax.security.auth.login.LoginException: Could not instantiate Seam component: serviceAuthenticator
at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:113)
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 javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
at javax.security.auth.login.LoginContext$5.run(LoginContext.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokeCreatorPriv(LoginContext.java:703)
at javax.security.auth.login.LoginContext.login(LoginContext.java:575)
at org.jboss.seam.security.Identity.authenticate(Identity.java:259)
at org.jboss.seam.security.Identity.authenticate(Identity.java:248)
at org.jboss.seam.security.Identity.login(Identity.java:205)
at evolve.user.ejb.AjaxLoginBeanBean.login(AjaxLoginBeanBean.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
But when I invoke login through JSF page, it is working without any issue. Here is JSF working code,
<h:panelGrid columns="2" border="0" >
<h:outputLabel for="name" value="Username"/>
<h:inputText id="name" value="#{identity.username}"/>
<h:outputLabel for="password" value="Password"/>
<h:inputSecret id="password" value="#{identity.password}"/>
</h:panelGrid>
<div align="center">
<h:commandButton value="Login" action="#{identity.login}"/>
</div>
Please help me how to invoke login or authentication through seam remoting.
Just guessing:
or
could help.
Personally I think the problem could be if EvolveAuthLocal doesn't have the @Local annotation present.
Once more: I'm just guessing.
Blog 'coding line-by-line'
without @Local OR @Remote you can't deploy ejbs, so I do have @Local.
I tried @AutoCreate on both the beans but it is not working.
One more guess: By default Authenticator comes without @Stateless annotation. I am not sure it changes something.
Additional inf is needed
Blog 'coding line-by-line'
You are wrong - about stateless. You can look at any seam example (jee5), you can see @Stateless. #indetity - Please refer any seam example (jee5) it has same example. I said with JSF it is working, but with remoting it is not working. I don't know what code you are refering but all i have is posted above.
It fairly straigt forward as I pick it from Seam tutorial and it is working except for Authentication.
<script type="text/javascript" src="seam/resource/remoting/resource/remote.js"></script> <script type="text/javascript" src="seam/resource/remoting/interface.js?AjaxLogin"></script>var AjaxLogin = Seam.Component.getInstance("AjaxLogin"); AjaxLogin.login (usr,pwd, function (){alert()});I also tried with No param method as below(AjaxLoginBeanBean also has loginTest and its local interface also has this method)
AjaxLogin.loginTest (function (){alert()});The call to AjaxLoginBeanBean is working but it is failing in Authentication.
When we use Seam Remoting without JSF, I doubt all the lifecycle call and context is not initialized. Is my assumption is correct? If so what should I do to initialize properly?