I am trying to do authorization stuff, but how to configure so that UserPermissions.class can be obtained using ApplicationStateManger.exists(UserPermissions.class) method?
What I want to do is user request -> AccessController (Dispatcher) -> News (Page) User will click the url and then AccessController will check using ApplicationStateManager.exists() method, in which to check if user has privilege to access to the Page `News' class. I check the SessionApplicationStatePersistenceStrategy.java, discovering that it will lookup http session to see if class exists or not, but I can not figure out how to get UserPermission created so that when executing ApplicationStateManager.exists(), it will return true. public <T> boolean exists(Class<T> ssoClass) { String key = buildKey(ssoClass); Session session = request.getSession(false); return session != null && session.getAttribute(key) != null; } In addition, after reading the chenillenKit source code, I disocover that seemingly ChenilleKitAccessModule will build the AccessValidator (the same as UserPermission) first and then directly using that instance in PageRenderAccessFilter (that implements PageRenderRequestFilter). ChenilleKitAccessModule.java public static AccessValidator buildAccessValidator(ComponentSource componentSource, ...){ ... return new AccessValidatorImpl(componentSource, locator, logger, manager, webSessionUserClass); } PageRenderAccessFilter.java public void handle(PageRenderRequestParameters parameters, PageRenderRequestHandler handler) throws IOException{ ... if ( !accessValidator.hasAccess(parameters.getLogicalPageName(), null, null) ) ... ... } Is this the same way as explained in http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher2? Or what's difference between this srategy? Thanks for help. Howard Lewis Ship wrote: > > exists() looks for an instance in the HttpSession ... what is supposed > to be creating this instance? > > On Tue, Mar 31, 2009 at 3:52 AM, Kasper <kas...@nekoconeko.nl> wrote: >> Hi, >> >> I am trying to create a dispatcher to define the access levels for the >> current user. I have followed the steps from the Wiki pages: >> http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher >> http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher2 >> >> This seems to work. But as I try to do asm.exists(UserPermissions.class) >> it >> returns false. I checked the classpath for the class >> my.project.services.UserPermissions. And there it does exist. I also >> tried >> to make it an interface but this didn't work out either. >> >> My classes: >> ---------------------------------------------------------------------------------------------- >> AccessController.java: >> >> public class AccessController implements Dispatcher { >> >> private ApplicationStateManager asm; >> >> public AccessController(ApplicationStateManager asm) { >> this.asm = asm; >> } >> >> public boolean dispatch(Request request, Response response) throws >> IOException { >> boolean canAccess = true; // to avoid the access violation >> for now >> >> if (asm.exists(UserPermissions.class)) { >> UserPermissions perms = >> asm.get(UserPermissions.class); >> >> canAccess = perms.canAccess(request); >> } >> >> if (!canAccess) { >> throw new RuntimeException("Access violation!"); >> } >> >> return false; >> } >> } >> >> ---------------------------------------------------------------------------------------------- >> UserPermissions.java: >> >> public class UserPermissions { >> >> public boolean canAccess(Request request) { >> return true; >> } >> >> } >> ---------------------------------------------------------------------------------------------- >> AppModule.java: >> >> public class AppModule { >> >> public static void bind(ServiceBinder binder) { >> >> binder.bind(AccessController.class).withId("AccessController"); >> } >> >> public void >> contributeMasterDispatcher(OrderedConfiguration<Dispatcher> >> configuration, >> �...@injectservice("AccessController") Dispatcher >> accessController) { >> configuration.add("AccessController", accessController, >> "before:PageRender"); >> } >> } >> ---------------------------------------------------------------------------------------------- >> >> Does anyone have a clue what I am doing wrong? >> >> Yours, >> Kasper >> >> ---------------------------------------------------------------- >> This message was sent using IMP, the Internet Messaging Program. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> > > > > -- > Howard M. Lewis Ship > > Creator Apache Tapestry and Apache HiveMind > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > > -- View this message in context: http://www.nabble.com/T5%3A-AccessController-Dispatcher-asm.exists%28%29-not-working--tp22802711p25387261.html Sent from the Tapestry - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org