From aff46cafbc15c2f25660789d5f04fbf962587903 Mon Sep 17 00:00:00 2001 From: vovasty Date: Wed, 18 Feb 2009 21:39:22 +0300 Subject: [PATCH] misc --- .../src/main/java/ru/rentdom/pages/Error403.java | 5 +++ .../src/main/java/ru/rentdom/pages/Error404.java | 5 +++ .../src/main/java/ru/rentdom/pages/Index.java | 10 +++--- .../src/main/java/ru/rentdom/pages/Logout.java | 16 +++++++++ .../src/main/java/ru/rentdom/pages/Recover.java | 4 +++ .../src/main/java/ru/rentdom/pages/Register.java | 29 ++++++++++++++- .../src/main/java/ru/rentdom/pages/Secured.java | 16 +++++++++ .../main/java/ru/rentdom/services/AppModule.java | 4 ++- .../java/ru/rentdom/services/CyrillicModule.java | 41 ---------------------- .../java/ru/rentdom/services/user/UserModule.java | 23 +++++++++++- .../resources/ru/rentdom/pages/Login.properties | 4 +++ .../resources/ru/rentdom/pages/Recover.properties | 2 ++ .../resources/ru/rentdom/pages/Register.properties | 4 ++- .../src/main/webapp/{Index.tml => Error403.tml} | 4 +-- .../src/main/webapp/{Index.tml => Error404.tml} | 4 +-- tapestry-quickstart/src/main/webapp/Index.tml | 2 ++ tapestry-quickstart/src/main/webapp/Login.tml | 4 ++- tapestry-quickstart/src/main/webapp/Recover.tml | 4 +++ tapestry-quickstart/src/main/webapp/Register.tml | 7 ++-- .../src/main/webapp/{Index.tml => Secured.tml} | 5 +-- .../src/main/webapp/WEB-INF/web.xml | 39 ++++++++++---------- 21 files changed, 153 insertions(+), 79 deletions(-) create mode 100644 tapestry-quickstart/src/main/java/ru/rentdom/pages/Error403.java create mode 100644 tapestry-quickstart/src/main/java/ru/rentdom/pages/Error404.java create mode 100644 tapestry-quickstart/src/main/java/ru/rentdom/pages/Logout.java create mode 100644 tapestry-quickstart/src/main/java/ru/rentdom/pages/Secured.java delete mode 100644 tapestry-quickstart/src/main/java/ru/rentdom/services/CyrillicModule.java create mode 100644 tapestry-quickstart/src/main/resources/ru/rentdom/pages/Login.properties create mode 100644 tapestry-quickstart/src/main/resources/ru/rentdom/pages/Recover.properties copy tapestry-quickstart/src/main/webapp/{Index.tml => Error403.tml} (78%) copy tapestry-quickstart/src/main/webapp/{Index.tml => Error404.tml} (78%) copy tapestry-quickstart/src/main/webapp/{Index.tml => Secured.tml} (53%) diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Error403.java b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Error403.java new file mode 100644 index 0000000..446433f --- /dev/null +++ b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Error403.java @@ -0,0 +1,5 @@ +package ru.rentdom.pages; + +public class Error403 { + +} diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Error404.java b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Error404.java new file mode 100644 index 0000000..2b084f3 --- /dev/null +++ b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Error404.java @@ -0,0 +1,5 @@ +package ru.rentdom.pages; + +public class Error404 { + +} diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Index.java b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Index.java index a4762db..e5404ed 100644 --- a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Index.java +++ b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Index.java @@ -1,14 +1,16 @@ package ru.rentdom.pages; -import java.util.Date; +import javax.servlet.http.HttpServletResponse; + +import net.aramzamzam.commons.pagesbehavoir.services.HttpStatusCode; /** * Start page of application rentdom-web. */ public class Index { - public Date getCurrentTime() - { - return new Date(); + Object onActivate(Object context) { + return new HttpStatusCode(HttpServletResponse.SC_NOT_FOUND, "Requested resource was not found"); } + } diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Logout.java b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Logout.java new file mode 100644 index 0000000..aabe267 --- /dev/null +++ b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Logout.java @@ -0,0 +1,16 @@ +package ru.rentdom.pages; + +import org.apache.tapestry5.ioc.annotations.Inject; + +import nu.localhost.tapestry5.springsecurity.services.LogoutService; + +public class Logout { + @Inject + private LogoutService logoutService; + + Object onActivate() + { + logoutService.logout(); + return Index.class; + } +} diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Recover.java b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Recover.java index ecf74bb..93d04c0 100644 --- a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Recover.java +++ b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Recover.java @@ -65,6 +65,9 @@ public class Recover { @Inject private Block invalidToken; + @Inject + private Block success; + void onActivate(User user) { activeBlock=tokenManager.isValid()?step3:invalidToken; @@ -99,6 +102,7 @@ public class Recover { { user.setPassword(password); userService.changeUserPassword(user); + activeBlock=success; } } diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Register.java b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Register.java index 6485d9f..c32ef8c 100644 --- a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Register.java +++ b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Register.java @@ -1,7 +1,10 @@ package ru.rentdom.pages; import org.apache.tapestry5.ValidationException; +import org.apache.tapestry5.annotations.Component; import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.corelib.components.Form; +import org.apache.tapestry5.corelib.components.PasswordField; import org.apache.tapestry5.hibernate.annotations.CommitAfter; import org.apache.tapestry5.ioc.Messages; import org.apache.tapestry5.ioc.annotations.Inject; @@ -18,11 +21,17 @@ public class Register { private User user; @Property - private String password; + private String password1; @Inject private Messages messages; + @Component + private Form registerForm; + + @Component + private PasswordField password; + void onActivate() { user=new User(); @@ -49,5 +58,23 @@ public class Register { return; throw new ValidationException(messages.get(err.toString())); } + + void onValidateFromPassword1(String password) throws ValidationException + { + if (password==null) + throw new ValidationException(messages.get("empty-password")); + } + + void onValidateFromPassword(String password) throws ValidationException + { + if (password==null) + throw new ValidationException(messages.get("empty-password")); + } + + void onValidateForm() + { + if (password1!=null && user.getPassword()!=null && !password1.equals(user.getPassword())) + registerForm.recordError(password, messages.get("passwords-not-mathes")); + } } diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/pages/Secured.java b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Secured.java new file mode 100644 index 0000000..b8b36a4 --- /dev/null +++ b/tapestry-quickstart/src/main/java/ru/rentdom/pages/Secured.java @@ -0,0 +1,16 @@ +package ru.rentdom.pages; + +import org.apache.tapestry5.annotations.ApplicationState; +import org.apache.tapestry5.annotations.Property; + +import ru.rentdom.entities.User; + +@org.springframework.security.annotation.Secured("ROLE_USER") +public class Secured { + + @SuppressWarnings("unused") + @ApplicationState + @Property + private User currentUser; + +} diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/services/AppModule.java b/tapestry-quickstart/src/main/java/ru/rentdom/services/AppModule.java index 055c0fb..5b6d7ed 100644 --- a/tapestry-quickstart/src/main/java/ru/rentdom/services/AppModule.java +++ b/tapestry-quickstart/src/main/java/ru/rentdom/services/AppModule.java @@ -1,5 +1,7 @@ package ru.rentdom.services; +import net.aramzamzam.commons.pagesbehavoir.services.PagesBehavoirModule; + import org.apache.tapestry5.SymbolConstants; import org.apache.tapestry5.ioc.MappedConfiguration; import org.apache.tapestry5.ioc.ServiceBinder; @@ -14,7 +16,7 @@ import ru.rentdom.services.user.UserModule; */ @SubModule ({ - CyrillicModule.class, + PagesBehavoirModule.class, UserModule.class, SecurityModule.class, UserModule.class diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/services/CyrillicModule.java b/tapestry-quickstart/src/main/java/ru/rentdom/services/CyrillicModule.java deleted file mode 100644 index 5db3bd7..0000000 --- a/tapestry-quickstart/src/main/java/ru/rentdom/services/CyrillicModule.java +++ /dev/null @@ -1,41 +0,0 @@ -package ru.rentdom.services; - -import java.io.IOException; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.tapestry5.ioc.OrderedConfiguration; -import org.apache.tapestry5.ioc.annotations.InjectService; -import org.apache.tapestry5.services.HttpServletRequestFilter; -import org.apache.tapestry5.services.HttpServletRequestHandler; - -public class CyrillicModule { - /** - * UTF-8 в tapestry http://wiki.apache.org/tapestry/Tapestry5Utf8Encoding - * @param requestGlobals - * @return - */ - - public HttpServletRequestFilter buildUtf8Filter() - { - return new HttpServletRequestFilter() - { - @Override - public boolean service(HttpServletRequest request, - HttpServletResponse response, - HttpServletRequestHandler handler) throws IOException { - request.setCharacterEncoding("UTF-8"); - return handler.service(request, response); - } - }; - } - - public void contributeHttpServletRequestHandler( - OrderedConfiguration configuration, - @InjectService("Utf8Filter") - HttpServletRequestFilter utf8Filter) - { - configuration.add("Utf8Filter", utf8Filter, "before:MultipartFilter"); - } -} diff --git a/tapestry-quickstart/src/main/java/ru/rentdom/services/user/UserModule.java b/tapestry-quickstart/src/main/java/ru/rentdom/services/user/UserModule.java index 6962751..11d16c2 100644 --- a/tapestry-quickstart/src/main/java/ru/rentdom/services/user/UserModule.java +++ b/tapestry-quickstart/src/main/java/ru/rentdom/services/user/UserModule.java @@ -2,12 +2,17 @@ package ru.rentdom.services.user; import java.util.List; +import org.apache.tapestry5.ioc.MappedConfiguration; import org.apache.tapestry5.ioc.ServiceBinder; import org.apache.tapestry5.ioc.annotations.InjectService; import org.apache.tapestry5.ioc.services.PipelineBuilder; +import org.apache.tapestry5.services.ApplicationStateContribution; +import org.apache.tapestry5.services.ApplicationStateCreator; +import org.apache.tapestry5.services.RequestGlobals; import org.slf4j.Logger; import ru.rentdom.dao.UserDAO; +import ru.rentdom.entities.User; public class UserModule { public static void bind(ServiceBinder binder) { @@ -47,5 +52,21 @@ public class UserModule { ChangePasswordFilter.class, configuration, new TerminatorImpl()); } - + + @SuppressWarnings("unchecked") + public void contributeApplicationStateManager(MappedConfiguration configuration, + final RequestGlobals requestGlobals, + final UserService userService) + { + ApplicationStateCreator creator = new ApplicationStateCreator() + { + public User create() + { + String username = requestGlobals.getHTTPServletRequest().getRemoteUser(); + return userService.findByUserName(username); + } + }; + + configuration.add(User.class, new ApplicationStateContribution("session", creator)); + } } diff --git a/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Login.properties b/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Login.properties new file mode 100644 index 0000000..18ca37b --- /dev/null +++ b/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Login.properties @@ -0,0 +1,4 @@ +username=user name +password=user password +rememberme=remember me +login=login \ No newline at end of file diff --git a/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Recover.properties b/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Recover.properties new file mode 100644 index 0000000..a1b42b9 --- /dev/null +++ b/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Recover.properties @@ -0,0 +1,2 @@ +recover=recover password +change=change password \ No newline at end of file diff --git a/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Register.properties b/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Register.properties index ff09b56..b012fcc 100644 --- a/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Register.properties +++ b/tapestry-quickstart/src/main/resources/ru/rentdom/pages/Register.properties @@ -1,2 +1,4 @@ DUBLICATE=dublicate -INVALID_SYMBOLS=invalid symbols in nickname \ No newline at end of file +INVALID_SYMBOLS=invalid symbols in nickname +empty-password=empty password not allowed +passwords-not-mathes=password not matches \ No newline at end of file diff --git a/tapestry-quickstart/src/main/webapp/Index.tml b/tapestry-quickstart/src/main/webapp/Error403.tml similarity index 78% copy from tapestry-quickstart/src/main/webapp/Index.tml copy to tapestry-quickstart/src/main/webapp/Error403.tml index c7a55b0..7605424 100644 --- a/tapestry-quickstart/src/main/webapp/Index.tml +++ b/tapestry-quickstart/src/main/webapp/Error403.tml @@ -1,3 +1,3 @@ - hello world - +404 + \ No newline at end of file diff --git a/tapestry-quickstart/src/main/webapp/Index.tml b/tapestry-quickstart/src/main/webapp/Error404.tml similarity index 78% copy from tapestry-quickstart/src/main/webapp/Index.tml copy to tapestry-quickstart/src/main/webapp/Error404.tml index c7a55b0..7605424 100644 --- a/tapestry-quickstart/src/main/webapp/Index.tml +++ b/tapestry-quickstart/src/main/webapp/Error404.tml @@ -1,3 +1,3 @@ - hello world - +404 + \ No newline at end of file diff --git a/tapestry-quickstart/src/main/webapp/Index.tml b/tapestry-quickstart/src/main/webapp/Index.tml index c7a55b0..928b909 100644 --- a/tapestry-quickstart/src/main/webapp/Index.tml +++ b/tapestry-quickstart/src/main/webapp/Index.tml @@ -1,3 +1,5 @@ hello world + secured + register diff --git a/tapestry-quickstart/src/main/webapp/Login.tml b/tapestry-quickstart/src/main/webapp/Login.tml index dba7795..85d2e70 100644 --- a/tapestry-quickstart/src/main/webapp/Login.tml +++ b/tapestry-quickstart/src/main/webapp/Login.tml @@ -1,10 +1,12 @@ +register +recover
-
\ No newline at end of file diff --git a/tapestry-quickstart/src/main/webapp/Recover.tml b/tapestry-quickstart/src/main/webapp/Recover.tml index 8ff7702..60779e9 100644 --- a/tapestry-quickstart/src/main/webapp/Recover.tml +++ b/tapestry-quickstart/src/main/webapp/Recover.tml @@ -23,4 +23,8 @@ + + success + index + \ No newline at end of file diff --git a/tapestry-quickstart/src/main/webapp/Register.tml b/tapestry-quickstart/src/main/webapp/Register.tml index 15b6170..85376a2 100644 --- a/tapestry-quickstart/src/main/webapp/Register.tml +++ b/tapestry-quickstart/src/main/webapp/Register.tml @@ -1,13 +1,14 @@ - + + : : : - + : - + diff --git a/tapestry-quickstart/src/main/webapp/Index.tml b/tapestry-quickstart/src/main/webapp/Secured.tml similarity index 53% copy from tapestry-quickstart/src/main/webapp/Index.tml copy to tapestry-quickstart/src/main/webapp/Secured.tml index c7a55b0..945f0e4 100644 --- a/tapestry-quickstart/src/main/webapp/Index.tml +++ b/tapestry-quickstart/src/main/webapp/Secured.tml @@ -1,3 +1,4 @@ - hello world - +${currentUser.email} +logout + \ No newline at end of file diff --git a/tapestry-quickstart/src/main/webapp/WEB-INF/web.xml b/tapestry-quickstart/src/main/webapp/WEB-INF/web.xml index c058b5a..259aaa6 100644 --- a/tapestry-quickstart/src/main/webapp/WEB-INF/web.xml +++ b/tapestry-quickstart/src/main/webapp/WEB-INF/web.xml @@ -1,24 +1,9 @@ - - - - rentdom-web Tapestry 5 Application app org.apache.tapestry5.TapestryFilter + app - /* + /* + REQUEST + ERROR + + + 404 + /error404 + + + 403 + /error403 + -- 2.11.4.GIT