Author: vbriand Date: 2011-02-03 15:26:21 +0100 (Thu, 03 Feb 2011) New Revision: 181 Url: http://chorem.org/repositories/revision/bow/181 Log: The search engine works with the token authentication Added: trunk/src/main/java/org/chorem/bow/interceptor/ trunk/src/main/java/org/chorem/bow/interceptor/LoginInterceptor.java Modified: trunk/src/main/java/org/chorem/bow/BowInit.java trunk/src/main/java/org/chorem/bow/BowUtils.java trunk/src/main/java/org/chorem/bow/action/BowBaseAction.java trunk/src/main/resources/struts.xml trunk/src/main/webapp/WEB-INF/decorators/main.jsp trunk/src/main/webapp/jsp/permanentXml.jsp trunk/src/main/webapp/jsp/temporaryXml.jsp Modified: trunk/src/main/java/org/chorem/bow/BowInit.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BowInit.java 2011-02-03 09:59:36 UTC (rev 180) +++ trunk/src/main/java/org/chorem/bow/BowInit.java 2011-02-03 14:26:21 UTC (rev 181) @@ -50,15 +50,18 @@ static public void initSession(Map<String, Object> session, User user) throws NoSuchAlgorithmException { WikittyProxy proxy = BowProxy.getInstance(); - Preference preference = proxy.restore(Preference.class, user.getWikittyId()); - BowConfig config = BowConfig.getInstance(); - session.put("user", user); - session.put("preference", preference); - session.put("version", config.getVersion()); - session.put("bowUrl", config.getBowUrl()); - initializeToken(session, user); - checkAdmin(session, user.getEmail()); + if (user != null) { + Preference preference = proxy.restore(Preference.class, user.getWikittyId()); + BowConfig config = BowConfig.getInstance(); + + session.put("user", user); + session.put("preference", preference); + session.put("version", config.getVersion()); + session.put("bowUrl", config.getBowUrl()); + initializeToken(session, user); + checkAdmin(session, user.getEmail()); + } } static public void initHomePage(HttpServletRequest request, User user) { Modified: trunk/src/main/java/org/chorem/bow/BowUtils.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BowUtils.java 2011-02-03 09:59:36 UTC (rev 180) +++ trunk/src/main/java/org/chorem/bow/BowUtils.java 2011-02-03 14:26:21 UTC (rev 181) @@ -1,5 +1,7 @@ package org.chorem.bow; +import java.util.Map; + import javax.servlet.http.HttpSession; import org.nuiton.wikitty.Criteria; @@ -27,6 +29,13 @@ } return checkPermanentToken(token); } + + static public User checkToken(String token, Map<String, Object> session) { + if (checkTemporaryToken(token, session)) { + return (User) session.get("user"); + } + return checkPermanentToken(token); + } /* @param token String which contains the MD5 encoding token * @return null the token doesn't exist @@ -53,6 +62,7 @@ */ protected static boolean checkTemporaryToken(String token, HttpSession session) { TokenActions tokenActions = (TokenActions) session.getAttribute("tokenActions"); + if (tokenActions != null) { String temporaryToken = tokenActions.getTemporaryToken(); if (temporaryToken != null) { @@ -63,4 +73,19 @@ } return false; } + + protected static boolean checkTemporaryToken(String token, Map<String, Object> session) { + TokenActions tokenActions = (TokenActions) session.get("tokenActions"); + + if (tokenActions != null) { + String temporaryToken = tokenActions.getTemporaryToken(); + + if (temporaryToken != null) { + if (temporaryToken.equals(token)) { + return true; + } + } + } + return false; + } } Modified: trunk/src/main/java/org/chorem/bow/action/BowBaseAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/BowBaseAction.java 2011-02-03 09:59:36 UTC (rev 180) +++ trunk/src/main/java/org/chorem/bow/action/BowBaseAction.java 2011-02-03 14:26:21 UTC (rev 181) @@ -11,7 +11,7 @@ private static final long serialVersionUID = 1L; public static final String UNTRANSLATED_MARKER = "???"; protected static final Log log = LogFactory.getLog(BowBaseAction.class); - + @Override public String getText(String aTextName) { String value = super.getText(aTextName); Added: trunk/src/main/java/org/chorem/bow/interceptor/LoginInterceptor.java =================================================================== --- trunk/src/main/java/org/chorem/bow/interceptor/LoginInterceptor.java (rev 0) +++ trunk/src/main/java/org/chorem/bow/interceptor/LoginInterceptor.java 2011-02-03 14:26:21 UTC (rev 181) @@ -0,0 +1,30 @@ +package org.chorem.bow.interceptor; + +import java.util.Map; + +import org.chorem.bow.BowInit; +import org.chorem.bow.BowUtils; +import org.chorem.bow.User; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.interceptor.AbstractInterceptor; + +public class LoginInterceptor extends AbstractInterceptor { + private static final long serialVersionUID = -7520186185205372272L; + + @Override + public String intercept(ActionInvocation invocation) throws Exception { + Map<String, Object> session = ActionContext.getContext().getSession(); + + if ((User)session.get("user") == null) { + Map<String, Object> toto = ActionContext.getContext().getParameters(); + String[] token = (String[])toto.get("token"); + + if (token != null && !token[0].isEmpty()) { + BowInit.initSession(session, BowUtils.checkToken(token[0], session)); + } + } + return invocation.invoke(); + } +} Property changes on: trunk/src/main/java/org/chorem/bow/interceptor/LoginInterceptor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-02-03 09:59:36 UTC (rev 180) +++ trunk/src/main/resources/struts.xml 2011-02-03 14:26:21 UTC (rev 181) @@ -3,27 +3,27 @@ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> - <constant name="struts.devMode" value="true" /> - <constant name="struts.ognl.allowStaticMethodAccess" value="true" /> + <constant name="struts.devMode" value="true" /> + <constant name="struts.ognl.allowStaticMethodAccess" value="true" /> - <!-- <default-action-ref name="" />--><!-- TODO: action à lancer quand une action n'existe pas --> - <package name="login" extends="struts-default"> - <action name="register_*" method="{1}" class="org.chorem.bow.action.RegisterAction"> - <result name="input">/jsp/register.jsp</result> - <result type="redirectAction">home</result> - </action> - <action name="forgotPassword_*" method="{1}" class="org.chorem.bow.action.ForgotPasswordAction"> - <result name="input">/jsp/forgotPassword.jsp</result> - <result>/home.action</result> - </action> - <action name="login_*" method="{1}" class="org.chorem.bow.action.LoginAction"> - <result name="input">/jsp/login.jsp</result> - <result type="redirectAction">home</result> - </action> - <action name="logout" class="org.chorem.bow.action.LogoutAction"> - <result type="redirectAction">login_input</result> - </action> - </package> + <!-- <default-action-ref name="" />--><!-- TODO: action à lancer quand une action n'existe pas --> + <package name="login" extends="struts-default"> + <action name="register_*" method="{1}" class="org.chorem.bow.action.RegisterAction"> + <result name="input">/jsp/register.jsp</result> + <result type="redirectAction">home</result> + </action> + <action name="forgotPassword_*" method="{1}" class="org.chorem.bow.action.ForgotPasswordAction"> + <result name="input">/jsp/forgotPassword.jsp</result> + <result>/home.action</result> + </action> + <action name="login_*" method="{1}" class="org.chorem.bow.action.LoginAction"> + <result name="input">/jsp/login.jsp</result> + <result type="redirectAction">home</result> + </action> + <action name="logout" class="org.chorem.bow.action.LogoutAction"> + <result type="redirectAction">login_input</result> + </action> + </package> <package name="bookmark" extends="struts-default"> <action name="importBookmarks" class="org.chorem.bow.action.ImportBookmarksAction"> @@ -51,6 +51,13 @@ </package> <package name="search" extends="struts-default"> + <interceptors> + <interceptor name="login" class="org.chorem.bow.interceptor.LoginInterceptor" /> + <interceptor-stack name="loginStack"> + <interceptor-ref name="login" /> + <interceptor-ref name="defaultStack" /> + </interceptor-stack> + </interceptors> <action name="search" class="org.chorem.bow.action.SearchAction"> <result>/jsp/search.jsp</result> </action> @@ -61,7 +68,8 @@ <result>/jsp/search.jsp</result> </action> <action name="openSearchResult" class="org.chorem.bow.action.OpenSearchResultAction"> - <result type="redirect">${redirectTo}</result> + <interceptor-ref name="loginStack" /> + <result type="redirect">${redirectTo}</result> </action> <action name="openSearchSuggestion" class="org.chorem.bow.action.OpenSearchSuggestionAction"> <result>/jsp/suggestions.jsp</result> @@ -90,12 +98,9 @@ <result name="error" type="redirectAction">home</result> <result type="redirect">${link}</result> </action> - <action name="temporaryXml"> - <result>/jsp/temporaryXml.jsp</result> + <action name="*Xml"> + <result>/jsp/{1}Xml.jsp</result> </action> - <action name="permanentXml"> - <result>/jsp/permanentXml.jsp</result> - </action> <action name="preferences" class="org.chorem.bow.action.PreferencesAction"> <result name="login" type="redirectAction">login_input</result> <result name="update" type="redirectAction">preferences</result> Modified: trunk/src/main/webapp/WEB-INF/decorators/main.jsp =================================================================== --- trunk/src/main/webapp/WEB-INF/decorators/main.jsp 2011-02-03 09:59:36 UTC (rev 180) +++ trunk/src/main/webapp/WEB-INF/decorators/main.jsp 2011-02-03 14:26:21 UTC (rev 181) @@ -5,13 +5,6 @@ <%@taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator" %> <%@taglib prefix="page" uri="http://www.opensymphony.com/sitemesh/page" %> <%@taglib prefix="s" uri="/struts-tags" %> -<% -String token = request.getParameter("token"); - -if (token != null && !token.isEmpty()) { - session.setAttribute("user", BowUtils.checkToken(token, session)); -} -%> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Bow : <decorator:title default="Bow" /></title> @@ -37,7 +30,7 @@ <%@include file="/jsp/inc/errorFrame.jsp" %> <decorator:body /> </div> - <s:if test="#session.user"> + <s:if test="%{#session.user != null}"> <jsp:include page="/jsp/inc/rightMenu.jsp" /> </s:if> </div> Modified: trunk/src/main/webapp/jsp/permanentXml.jsp =================================================================== --- trunk/src/main/webapp/jsp/permanentXml.jsp 2011-02-03 09:59:36 UTC (rev 180) +++ trunk/src/main/webapp/jsp/permanentXml.jsp 2011-02-03 14:26:21 UTC (rev 181) @@ -41,7 +41,7 @@ <Description>bookmarkSearch</Description> <InputEncoding>inputEncoding</InputEncoding> <Image width="16" height="16" type="image/ico"><%=url%>img/bow.gif</Image> - <Url type="text/html" method="GET" template="<%=url%>openSearchResult.action?token=<%=token%>&searchLine={searchTerms}" /> - <Url type="application/x-suggestions+json" method="GET" template="<%=url%>openSearchSuggestion.action?token=<%=token%>&searchLine={searchTerms}" /> + <Url type="text/html" method="GET" template="<%=url%>openSearchResult.action?token=<%=token%>&searchLine={searchTerms}" /> + <Url type="application/x-suggestions+json" method="GET" template="<%=url%>openSearchSuggestion.action?token=<%=token%>&searchLine={searchTerms}" /> <moz:SearchForm><%=url%></moz:SearchForm> </OpenSearchDescription> Modified: trunk/src/main/webapp/jsp/temporaryXml.jsp =================================================================== --- trunk/src/main/webapp/jsp/temporaryXml.jsp 2011-02-03 09:59:36 UTC (rev 180) +++ trunk/src/main/webapp/jsp/temporaryXml.jsp 2011-02-03 14:26:21 UTC (rev 181) @@ -41,7 +41,7 @@ <Description>bookmarkSearch</Description> <InputEncoding>inputEncoding</InputEncoding> <Image width="16" height="16" type="image/ico"><%=url%>img/bow.gif</Image> - <Url type="text/html" method="GET" template="<%=url%>openSearchResult.action?token=<%=token%>&searchLine={searchTerms}" /> - <Url type="application/x-suggestions+json" method="GET" template="<%=url%>openSearchSuggestion.action?token=<%=token%>&search={searchTerms}" /> + <Url type="text/html" method="GET" template="<%=url%>openSearchResult.action?token=<%=token%>&searchLine={searchTerms}" /> + <Url type="application/x-suggestions+json" method="GET" template="<%=url%>openSearchSuggestion.action?token=<%=token%>&search={searchTerms}" /> <moz:SearchForm><%=url%></moz:SearchForm> </OpenSearchDescription>