RE: Two problems: Struts2 + https + file load and Struts2 + file load + java.lang.IllegalStateException: getOutputStream()
Thanx a lot. After I insert return null the exception about 16:52:20,832 ERROR [UIBean] error when rendering java.lang.IllegalStateException: getOutputStream() has already been called for this response stopped. But I've still got the problem with IE6 - instead of file name I have the name of my action - as I understand IE6 takes the last part of my url because it looks like filename (dot) extension (FileContent.action?fileId=5067). And it is strange because it happens only when I use https and IE6. When it is http and IE6 it seems to be fine. Could anyone help with this stuff? Thank you very much! Sincerely yours. -Original Message- From: news [mailto:[EMAIL PROTECTED] On Behalf Of Laurie Harper Sent: Tuesday, April 22, 2008 9:23 PM To: user@struts.apache.org Subject: Re: Two problems: Struts2 + https + file load and Struts2 + file load + java.lang.IllegalStateException: getOutputStream() Filippov, Andrey wrote: Hello everybody! I am trying to load file from DB. I use https. In Mozilla I get only one exception but everything finally works. Here is my code and stack trace: public String execute() throws Exception { super.execute(); byte[] file = null; PolicyFileVO policyFile = polInfoInstance.getPolicyFileById(fileId); file = policyFile.getFile(); String fileType = polInfoInstance.getFileTypeById(policyFile.getType()) .getContentType(); if (file != null) { this.response.setCharacterEncoding(utf-8); String fileName = policyFile.getFile_name(); if (!fileType.startsWith(image)) { this.response.addHeader(Content-Disposition, attachment; filename= + fileName); } //final ServletContext sc = ServletActionContext.getServletContext(); this.response.setContentType(fileType); this.response.setContentLength(file.length); OutputStream o = null; try { o = response.getOutputStream(); o.write(file); o.flush(); } catch (java.lang.IllegalStateException ex) { log.error(IllegalStateException in FileContent.execute() method + ex); }catch (java.io.IOException ex) { log.error(IOException in FileContent.execute() method + ex); }catch (java.lang.Exception ex) { log.error(Exception in FileContent.execute() method + ex); }finally{ if (o != null){ response.flushBuffer(); o.close(); } } } There's no return statement in there, which shouldn't even compile... 16:52:20,832 ERROR [UIBean] error when rendering java.lang.IllegalStateException: getOutputStream() has already been called for this response at org.apache.catalina.connector.Response.getWriter(Response.java:604) 16:52:21,004 ERROR [[default]] Servlet.service() for servlet default threw exception java.io.IOException: Error including path '/layouts/four_rows_layout.jsp'. java.lang.IllegalStateException: getOutputStream() has already been called for this response at org.apache.tiles.servlet.context.ServletTilesRequestContext.include(ServletTilesRequestContext.java:214) at org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:183) at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:417) at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:368) This suggests Struts is trying to forward to a JSP after your action completes, which won't work since you've already sent a file back to the browser. You execute() method should be returning 'null' to tell Struts not to do this. And the second part of my problem happens only in IE6 - when dialog of opening/saving file instead of normal file name like myTest.pdf reflect the action name - something like this: FileContent_action?fileId=5046 (only when I use https - in http it looks fine - myTest.pdf). The file name to save to is specified by the Content-Disposition header, which you are not setting consistently. Sending a correct header every time should fix this problem. L. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED
Two problems: Struts2 + https + file load and Struts2 + file load + java.lang.IllegalStateException: getOutputStream()
Hello everybody! I am trying to load file from DB. I use https. In Mozilla I get only one exception but everything finally works. Here is my code and stack trace: public String execute() throws Exception { super.execute(); byte[] file = null; PolicyFileVO policyFile = polInfoInstance.getPolicyFileById(fileId); file = policyFile.getFile(); String fileType = polInfoInstance.getFileTypeById(policyFile.getType()) .getContentType(); if (file != null) { this.response.setCharacterEncoding(utf-8); String fileName = policyFile.getFile_name(); if (!fileType.startsWith(image)) { this.response.addHeader(Content-Disposition, attachment; filename= + fileName); } //final ServletContext sc = ServletActionContext.getServletContext(); this.response.setContentType(fileType); this.response.setContentLength(file.length); OutputStream o = null; try { o = response.getOutputStream(); o.write(file); o.flush(); } catch (java.lang.IllegalStateException ex) { log.error(IllegalStateException in FileContent.execute() method + ex); }catch (java.io.IOException ex) { log.error(IOException in FileContent.execute() method + ex); }catch (java.lang.Exception ex) { log.error(Exception in FileContent.execute() method + ex); }finally{ if (o != null){ response.flushBuffer(); o.close(); } } } 16:52:20,832 ERROR [UIBean] error when rendering java.lang.IllegalStateException: getOutputStream() has already been called for this response at org.apache.catalina.connector.Response.getWriter(Response.java:604) .. 16:52:21,004 ERROR [[default]] Servlet.service() for servlet default threw exception java.io.IOException: Error including path '/layouts/four_rows_layout.jsp'. java.lang.IllegalStateException: getOutputStream() has already been called for this response at org.apache.tiles.servlet.context.ServletTilesRequestContext.include(ServletTilesRequestContext.java:214) at org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:183) at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:417) at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:368) And the second part of my problem happens only in IE6 - when dialog of opening/saving file instead of normal file name like myTest.pdf reflect the action name - something like this: FileContent_action?fileId=5046 (only when I use https - in http it looks fine - myTest.pdf). Could someone help me? I appreciate in advance...
RE: Struts2 and JavaScript localization
Thanx a lot! It works.. -Original Message- From: Chris Pratt [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 01, 2008 8:04 PM To: Struts Users Mailing List Subject: Re: Struts2 and JavaScript localization You'd have to put that expression in a tag that can process it. Try something like: wds : new Array('s:property value=%{getText('bscal_day1')}/',tue,wen,thu,fri,sat,sun) , (*Chris*) On Tue, Apr 1, 2008 at 6:40 AM, Filippov, Andrey [EMAIL PROTECTED] wrote: Hello everybody, I have a javascript dropdown calendar on one of my struts2 jsp. I have bi-lingual application. So I need to read bundle files to switch language. Please, does someone know how to use these files in javascript. Here is my js snippet: script language=JavaScript type=text/JavaScript window.onload = function(){bscal.init()} var bscal = { left : 0, top : 0, width: 0, height: 0, format: %d.%m.%Y, wds : new Array(%{getText('bscal_day1')},tue,wen,thu,fri,sat,sun), ... The way like this %{getText('bscal_day1')} (like on jsp) does not work. I appreciate your help. Best regards, Filippov Andrey - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Struts2 and JavaScript localization
Hello everybody, I have a javascript dropdown calendar on one of my struts2 jsp. I have bi-lingual application. So I need to read bundle files to switch language. Please, does someone know how to use these files in javascript. Here is my js snippet: script language=JavaScript type=text/JavaScript window.onload = function(){bscal.init()} var bscal = { left : 0, top : 0, width: 0, height: 0, format: %d.%m.%Y, wds : new Array(%{getText('bscal_day1')},tue,wen,thu,fri,sat,sun), ... The way like this %{getText('bscal_day1')} (like on jsp) does not work. I appreciate your help. Best regards, Filippov Andrey
Custom validation with Struts2
Hello everybody, I need to validate only 1 field on the jsp. It value should be between 1 and 99. Initially I started to implement through int validation but it seemed to go wrong - it works with some limitation - maximum value should not exceed 1000 or something like that. I am trying to implement validation through overriding validate() method. I use tiles together with Struts 2.0.11. I could not tune it to work correctly. Could someone help, please? Here are my snippets: Struts.xml: action name=EmployeeCard class=com.tsystems.tintra4.actions.EmployeeCard interceptor-ref name=i18n / interceptor-ref name=roles param name=allowedRolesWTT_CARDS_EDITOR/param /interceptor-ref !-- interceptor-ref name=workflow/-- interceptor-ref name=workflow/ result type=tiles name=SUCCESSdef_page_employee_card/result result type=tiles name=input def_page_employee_card /result /action Jsp: %@ page language=java contentType=text/html; charset=UTF-8 pageEncoding=UTF-8% %@ taglib prefix=s uri=/struts-tags % !--Reference to the Employee profile-- div s:url id=url_fio action=GetEmployee includeParams=none s:param name=employeeIds:property value=%{EmpNo}//s:param /s:url s:a href=%{url_fio} s:property value=%{fio}/ /s:a /div br/ !--Adding new card-- s:if test=addCard == true s:text name=card_adding_proccess/s:text s:fielderror/ s:form method=GET validate=true s:textfield name=cardNo label=%{getText('card_add_edit_field')}/s:textfield s:textfield name=EmpNo value=%{EmpNo}/s:textfield s:hidden name=editCard value=%{true}/s:hidden s:hidden name=addCardFinal value=%{true}/s:hidden s:submit value=%{getText('button_submit')}/ /s:form /s:if !--Editing new card-- s:if test=editCard == true s:text name=card_editing_proccess/s:text s:fielderror/ s:form method=GET validate=true s:textfield name=cardNo label=%{getText('card_add_edit_field')}/s:textfield s:hidden name=EmpNo value=%{EmpNo}/s:hidden s:hidden name=editCard value=%{true}/s:hidden s:hidden name=editCardFinal value=%{true}/s:hidden s:submit value=%{getText('button_submit')}/ /s:form /s:if JAVA Action: public void validate() { request = ServletActionContext.getRequest(); String tmp = ; try { tmp = request.getParameter(cardNo); Integer i = this.getCardNo(); if (tmp != null tmp.length() 0) { int tmpInt = Integer.parseInt(tmp); this.setCardNo(tmpInt); System.out.println(Card no (validation) = + cardNo); if (cardNo 1 || cardNo 99) { addFieldError(cardNo, Must be int); System.out.println(INPUT...); } } } catch (Exception e) { e.printStackTrace(); } } Thanx a lot. Best regards, Filippov Andrey
RE: Custom validation with Struts2
Thanks a lot for your answer. Concerning request = ServletActionContext.getRequest(); and tmp = request.getParameter(cardNo); - I am doing it cause I did not manage to use getCardNo() method - it always return 0 in the case of int. Here is my action class - probably you will help me again..)) JAVA class: package com.my.intra4.actions; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import org.apache.struts2.interceptor.ServletRequestAware; import org.hsqldb.lib.Set; import com.opensymphony.xwork2.ActionSupport; import com.my.intra4.ejb.cf.session.PersonalInfoInterface; import com. my.intra4.ejb.cf.session.UserManagerInterface; import com. my.intra4.ejb.wtt.CardsVO; import com. my.intra4.ejb.wtt.WTT; import com. my.intra4.util.Functions; import com. my.intra4.util.GetPropsSingle; import com. my.intra4.util.Menu; public class EmployeeCard extends ActionSupport implements ServletRequestAware { private static final long serialVersionUID = 564633345679L; private HttpServletRequest request; private HttpServletResponse response; private ArrayListMenu menu_items = null; private ArrayListMenu page_menu_items = null; private ArrayListMenu page_menu_manager_items = null; private String actionName; private PersonalInfoInterface pInfoInterface = null; private String fio; private String EmpNo; private CardsVO card; private Integer cardNo; private String cardN; boolean addCard = false; boolean editCard = false; private String UserId; private int fieldName; private UserManagerInterface uManagerInterface = null; public String getUserId() { return UserId; } public void setUserId(String userId) { UserId = userId; } public UserManagerInterface getUManagerInterface() { return uManagerInterface; } public void setUManagerInterface(UserManagerInterface managerInterface) { uManagerInterface = managerInterface; } public boolean isAddCard() { return addCard; } public void setAddCard(boolean addCard) { this.addCard = addCard; } public boolean isEditCard() { return editCard; } public void setEditCard(boolean editCard) { this.editCard = editCard; } public Integer getCardNo() { return this.cardNo; } public void setCardNo(Integer cardNo) { this.cardNo = cardNo; } public void validate() { // request = ServletActionContext.getRequest(); // String tmp = ; try { // tmp = request.getParameter(cardNo); // Integer i = this.getCardNo(); // System.out.println(Card no from get = + i); // if (tmp != null tmp.length() 0) { // int tmpInt = Integer.parseInt(tmp); // this.setCardNo(tmpInt); // System.out.println(Card no (validation) = + cardNo); // if (cardNo 1 || cardNo ) { // // addFieldError(cardNo, Must be int); // // Map map = request.getParameterMap(); // Set set = (Set) map.keySet(); // Iterator it = (Iterator) set.iterator(); // // while (it.hasNext()) { // String elem = (String) it.next(); // // System.out.println(Param + i + = + map.get(elem)); // // } // // // System.out.println(INPUT...); // } // } System.out.println(Card no (validation) = + getCardNo()); if (getCardNo() != null (getCardNo() 0 || getCardNo() 99)) { addFieldError(cardNo, Must be int); System.out.println(INPUT...); } } catch (Exception e) { e.printStackTrace(); } } public String execute()
struts2 i18n...
Hi everybody! I am developing WEBApp now and there is a problem... Well actually - 2 problems... My application should be bilingual. So I have 2 bundle files - locale_ru_Ru.properties and locale_en_Us.properties. As I understand struts2 tag s:i18n/ automatically detect the user locale setting and choose the right bundle for it. So I have the following: s:i18n name=com.fil.struts2.actions.locale table tr bgColor=#bcc2c8 height=7 tds:text name = body1//td tds:text name = body2//td tds:text name = body3//td tds:text name = body4//td tds:text name = body5//td /tr /table /s:i18n 1. But finally I have to implement the possibility of changing language manually by means of href (ru | eng). What is the best way to do it? 2. Could I anywhere set the default locale - I mean if someone accesses my application from another locale I would want to set en_Us as a default for this case. Thanks a lot! Best regards.
using iterator in struts2..
Hi everybody! I have the following question - I have several String[] objects of the same size. I have to render them on the jsp. First I thought that this way is correct: s:iterator status=stat value=secondName tr td s:property value=#stat.index / /td td s:property/, s:property value=firstName/ /td td s:property value=position/ /td td s:property value=project/ /td td s:property value=room/ /td /tr /s:iterator But it's wrong. Are there any opportunities to do it? Appreciate. Best regards.
RE: using iterator in struts2..
That's great!! Thanx a lot!!! -Original Message- From: Dave Newton [mailto:[EMAIL PROTECTED] Sent: Thursday, November 22, 2007 6:18 PM To: Struts Users Mailing List Subject: Re: using iterator in struts2.. Well, s:iterator... only iterates over a single array--it has no idea about any other arrays you're dealing with. If your action has, say, three arrays of equal length... public String[] getArr1() {... public String[] getArr2() {... public String[] getArr3() {... ... then... s:iterator value=arr1 status=stat id=arr1Val s:property value=#arr1Val/ s:property value=arr2[#stat.index]/ s:property value=arr3[#stat.index]/ /s:iterator ... will iterate over a single array and use the current iteration index to retrieve values from the other arrays. d. --- Filippov, Andrey [EMAIL PROTECTED] wrote: Hi everybody! I have the following question - I have several String[] objects of the same size. I have to render them on the jsp. First I thought that this way is correct: s:iterator status=stat value=secondName tr td s:property value=#stat.index / /td td s:property/, s:property value=firstName/ /td td s:property value=position/ /td td s:property value=project/ /td td s:property value=room/ /td /tr /s:iterator But it's wrong. Are there any opportunities to do it? Appreciate. Best regards. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
isUserInRole on JSP page...
Hello Everybody! I need to check roles of a user in my app to decide whether to render some elements on JSP or not. Does someone happen to know how could I do it (I mean the syntax of s:if tag together with request.isUserInRole(role) on the JSP page)? Thanks a lot.
RolesInterceptor. How to..?
Hi everybody! I need to configure the login and authorization system in my application. I have struts2 together with jboss and mysql. I found the following information about it: interceptor name=roles class=org.apache.struts2.interceptor.RolesInterceptor / (http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/interceptor/RolesInterceptor.html, http://struts.apache.org/2.0.11/docs/interceptors.html), http://www.vitarara.org/cms/struts_2_cookbook/creating_a_login_interceptor. As I understand the logic should be like this: from login.jsp get username and password, then get information about the user from mysql db (I mean confirming information about existence of the user and additional information about roles of the user), then put this information into session, then use RolesInterceptor to define access to the certain action. Am I right? But I have not caught yet how could I put user object (see ref#3 - vitarara...) with information about login, password and roles (which are in the mysql db) into session? RolesInterceptor class has the setAllowedRoles method. Could I use it to define a set of roles for user? How could I Do it? I appreciate any kind of help! Thanx a lot!!! Sincerely yours, Andrey V. Filippov
RE: struts2 + jaas on jboss...
here -- /package !-- Add packages here -- /struts Sincerely yours, Andrey V. Filippov -Original Message- From: Martin Gainty [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 07, 2000 6:01 PM To: Struts Users Mailing List Cc: [EMAIL 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 [EMAIL PROTECTED] To: user@struts.apache.org Cc: [EMAIL 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=2Number=2500page= 0 And I have the following: jboss-web.xml ?xml version=1.0 encoding=UTF-8? jboss-web security-domainjava:/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 = dsJndiNamejava:/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 = debugtrue/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-methodHEAD/http-method http-methodGET/http-method http-methodPOST/http-method http-methodPUT/http-method http-methodDELETE/http-method /web-resource-collection auth-constraint role-nameaccess/role-name /auth-constraint user-data-constraint description noo /description transport-guarantee NONE /transport-guarantee /user-data-constraint /security-constraint login-config auth-methodFORM/auth-method realm-namestruts_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-nameaccess/role-name /security-role security-role description/ role-namerejection/role-name /security-role security-role description/ role-namemisc/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=SUCCESSsuccess/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=25/br input type=password name=j_password SIZE=25/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
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=2Number=2500page=0 And I have the following: jboss-web.xml ?xml version=1.0 encoding=UTF-8? jboss-web security-domainjava:/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 = dsJndiNamejava:/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 = debugtrue/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-methodHEAD/http-method http-methodGET/http-method http-methodPOST/http-method http-methodPUT/http-method http-methodDELETE/http-method /web-resource-collection auth-constraint role-nameaccess/role-name /auth-constraint user-data-constraint description noo /description transport-guarantee NONE /transport-guarantee /user-data-constraint /security-constraint login-config auth-methodFORM/auth-method realm-namestruts_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-nameaccess/role-name /security-role security-role description/ role-namerejection/role-name /security-role security-role description/ role-namemisc/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=SUCCESSsuccess/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=25/br input type=password name=j_password SIZE=25/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
RE: Keep Objects over request
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=2Number=2500page=0 And I have the following: jboss-web.xml ?xml version=1.0 encoding=UTF-8? jboss-web security-domainjava:/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 = dsJndiNamejava:/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 = debugtrue/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-methodHEAD/http-method http-methodGET/http-method http-methodPOST/http-method http-methodPUT/http-method http-methodDELETE/http-method /web-resource-collection auth-constraint role-nameaccess/role-name /auth-constraint user-data-constraint description noo /description transport-guarantee NONE /transport-guarantee /user-data-constraint /security-constraint login-config auth-methodFORM/auth-method realm-namestruts_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-nameaccess/role-name /security-role security-role description/ role-namerejection/role-name /security-role security-role description/ role-namemisc/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=SUCCESSsuccess/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=25/br input type=password name=j_password SIZE=25/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
FW: struts2 + jaas on jboss...
-Original Message- From: Filippov, Andrey Sent: Wednesday, November 07, 2007 6:17 PM To: Struts Users Mailing List Subject: RE: struts2 + jaas on jboss... 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 ? !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.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=SUCCESSsuccess/result /action action name=Admin class=com.fil.struts.login.AdminPage result name=ERROR/jsp/Login.jsp/result result name