  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | struts2 + jaas on jboss... | struts2 + jaas on jboss... 2007-11-07 - By Filippov, Andrey
Back Hi Martin! Thanx for Your answer! Here is my SessionLogin.java file:
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
package com.fil.struts.login;
import java.io.ByteArrayInputStream; import java.rmi.RemoteException; import java.util.*;
import javax.ejb.CreateException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; import javax.security.auth.Subject; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException;
import org.jboss.security.SimplePrincipal; import org.jboss.security.auth.callback.SecurityAssociationHandler;
import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.tsystems.struts.ejb.test.*;
public class SessionLogin extends ActionSupport {
/** * */ private static final long serialVersionUID = 2452642373778L;
private String userId;
private String password;
public byte[] foto;
PersonaHome personaHome = null;
Persona personaObject = null;
public String execute() throws Exception {
Properties prop = new Properties(); String j_username = null; String j_password = null; try { SecurityAssociationHandler handler = new SecurityAssociationHandler();
SimplePrincipal user = new SimplePrincipal(j_username); handler.setSecurityInfo(user, j_password.toCharArray()); LoginContext loginContext = new LoginContext("dbStrutsRealm", (CallbackHandler) handler); loginContext.login(); Subject subject = loginContext.getSubject(); Set principals = subject.getPrincipals(); principals.add(user); } catch (LoginException e) { e.printStackTrace();
}
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); prop.put(Context.PROVIDER_URL, "localhost:1099");
try { Context ctx = new InitialContext(prop); Object tsRef = ctx.lookup("FilStruts2"); personaHome = (PersonaHome) PortableRemoteObject.narrow(tsRef, PersonaHome.class); personaObject = personaHome.create(); } catch (NamingException e) { e.printStackTrace(); System.out.println("NamingException"); }
if (personaObject.getPersonaFirstName(userId) && personaObject.getPersonaPassword(password)) {
foto = personaObject.getPersonaPhoto(userId); System.out.println(foto.toString());
Map session = ActionContext.getContext().getSession(); session.put("logged-in", "true"); return "SUCCESS"; } else { return "ERROR"; }
}
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
public String getUserId() { return userId; }
public void setUserId(String userId) { this.userId = userId; }
public byte[] getFoto() {
return foto; }
public void setFoto(byte[] foto) { this.foto = foto; }
}
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
here is my struts.xml:
<?xml version="1.0" encoding="UTF-8 (See http://UTF-8.ora-code.com)" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2 (See http://uts-2.ora-code.com).0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" />
<package name="login" namespace="/login" extends="struts-default" >
<result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/> </result-types>
<action name="Login"> <result>/jsp/Login.jsp</result> </action>
<action name="Login1" class="com.fil.struts.login.SessionLogin"> <result name="ERROR">/jsp/Login.jsp</result> <result type="tiles" name="SUCCESS">success</result> </action>
<action name="Admin" class="com.fil.struts.login.AdminPage"> <result name="ERROR">/jsp/Login.jsp</result> <result name="SUCCESS">/jsp/AdminPage.jsp</result> </action>
<action name="Logout" class="com.fil.struts.login.SessionLogout"> <result name="SUCCESS">/jsp/Login.jsp</result> </action>
<!-- Add actions here --> </package>
<!-- Add packages here -->
</struts>
Sincerely yours, Andrey V. Filippov
-- --Original Message-- -- From: Martin Gainty [mailto:mgainty@(protected)] Sent: Tuesday, November 07, 2000 6:01 PM To: Struts Users Mailing List Cc: andreessen@(protected) Subject: Re: struts2 + jaas on jboss...
Andrey-
Cursory look saysthat the result was either not defined and or the exepected result was not returned for SessionLogin Class Can we see the code for SessionLogin.java ? also show us how the result is configured for SessionLogin in struts.xml e.g. <action name="date" class="org.apache.struts2.showcase.DateAction" method="browse"> <result name="success">/date.jsp</result> </action>
Martin -- -- Original Message -- -- From: "Filippov, Andrey" <andrey.filippov@(protected)> To: <user@(protected)> Cc: <andreessen@(protected)> Sent: Wednesday, November 07, 2007 8:50 AM Subject: struts2 + jaas on jboss...
Hi everybody!
I have this problem - I could not manage to configure it to work together. Does someone happen to know how to do it? I appriciate any kind of information!! Initially I used the following source: http://www.javaworld.com/javaforums/showthreaded.php?Cat=2&Number%00&page0 And I have the following:
jboss-web.xml <?xml version="1.0" encoding="UTF-8 (See http://UTF-8.ora-code.com)"?> <jboss-web> <security-domain>java:/jaas/dbStrutsRealm</security-domain> </jboss-web> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ------ snippet from login-config.xml
<application-policy name = "dbStrutsRealm"> <authentication> <login-module code "org.jboss.security.auth.spi.DatabaseServerLoginModule" flag = "required"> <module-option name "dsJndiName">java:/FilStrutsDS</module-option> <module-option name = "principalsQuery"> select password from test_login where login_name=? </module-option> <module-option name = "rolesQuery"> SELECT role_name, 'Roles' FROM user_in_roles INNER JOIN roles ON user_in_roles.role=roles.id where user_in_roles.user=? </module-option> <module-option name = "debug">true</module-option> </login-module> </authentication> </application-policy> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ------ snippet from web.xml <security-constraint> <web-resource-collection> <web-resource-name> action </web-resource-name> <description> Struts security test </description> <url-pattern>/Logout.action</url-pattern> <http-method>HEAD</http-method> <http-method>GET</http-method> <http-method>POST</http-method> <http-method>PUT</http-method> <http-method>DELETE</http-method> </web-resource-collection> <auth-constraint> <role-name>access</role-name> </auth-constraint> <user-data-constraint> <description> noo </description> <transport-guarantee> NONE </transport-guarantee> </user-data-constraint> </security-constraint>
<login-config> <auth-method>FORM</auth-method> <realm-name>struts_test</realm-name> <form-login-config> <form-login-page>/Login.action</form-login-page> <form-error-page>/jsp/Login_error.jsp</form-error-page> </form-login-config> </login-config>
<security-role> <description/> <role-name>access</role-name> </security-role> <security-role> <description/> <role-name>rejection</role-name> </security-role> <security-role> <description/> <role-name>misc</role-name> </security-role> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ------ snippet from struts.xml
<package name="login" namespace="/login" extends="struts-default" > <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/> </result-types> <action name="Login"> <result>/jsp/Login.jsp</result> </action> <action name="Login1" class="com.fil.struts.login.SessionLogin"> <result name="ERROR">/jsp/Login.jsp</result> <result type="tiles" name="SUCCESS">success</result> </action> <action name="Logout" class="com.fil.struts.login.SessionLogout"> <result name="SUCCESS">/jsp/Login.jsp</result> </action> <!-- Add actions here --> </package> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ------ snippet from login.jsp <form name="logonForm" action="Login1.action" method="POST"> <table> <tr> <td colspan="2"> Login </td>
</tr>
<tr> <td colspan="2"> <input type="text" name="j_username" SIZE%/><br> <input type="password" name="j_password" SIZE%/><br> <input type="submit" onclick="javascript:submitForm();" value="Login"/> </td> </tr> </table> </form> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ---- ------ Finally, when I submit the mentioned in the login.jsp form I get the following message:
Struts Problem Report Struts has detected an unhandled exception: Messages: No result defined for action com.fil.struts.login.SessionLogin and result input File: file:/C:/jboss-4 (See http://oss-4.ora-code.com).0.5.GA/server/default/./tmp/deploy/tmp15883StrutsSessionLog In-exp.war/WEB-INF/classes/struts.xml Line number: 25 Column number: 65
<action name="Login1" class="com.fil.struts.login.SessionLogin"> <result name="ERROR">/jsp/Login.jsp</result> <result type="tiles" name="SUCCESS">success</result>
Stacktraces No result defined for action com.fil.struts.login.SessionLogin and result input - action - file:/C:/jboss-4 (See http://oss-4.ora-code.com).0.5.GA/server/default/./tmp/deploy/tmp15883StrutsSessionLog In-exp.war/WEB-INF/classes/struts.xml:25:65
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionI nvocation.java:350)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:253)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(Validati onInterceptor.java:150)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.do Intercept(AnnotationValidationInterceptor.java:48)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:86)
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionI nvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionI nvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack java:455)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:221)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(Con versionErrorInterceptor.java:123)
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionI nvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionI nvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack java:455)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:221)
What I am doing wrong? Please correct me!! Thanx a lot.
Sincerely yours, Andrey V. Filippov
Sincerely yours, Andrey V. Filippov
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ To unsubscribe, e-mail: user-unsubscribe@(protected) For additional commands, e-mail: user-help@(protected)
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ To unsubscribe, e-mail: user-unsubscribe@(protected) For additional commands, e-mail: user-help@(protected)
|
|
 |