Hi Paul,
Thanks for the reply. I think you are misunderstanding me. I have the my
instantiation authorization working perfectly the way I want it. I now
want my action (RENDER or ENABLE) authorization to work the same way.
IAuthorizationStrategy says yes or no to instantiations and actions.
If the question was instantiation and the answer was no, then
IUnauthorizedComponentInstantiationListener can make a decision to
possibly redirect to a login page.
If the question was action and the answer was no, then an
UnauthorizedActionException is thrown. The IExceptionMapper is asked
about what to do with the exception, and an access denied page is shown.
I dont think the IAuthorizationStrategy is the right place to be
throwing redirect exception. If it was, the return type would be void
and and it would either work or throw an exception. Also, it seems a
shame to limit the use of IAuthorizationStrategy to components involved
in the current request cycle, as would be the case if
IAuthorizationStrategy threw redirect exceptions. You would not be able
to get a target page/page class, check permissions, and enable/disable a
link based on the answer.
Seems to me IExceptionMapper should make decisions about what to do, but
the default implementation is very unfriendly towards being extended.
Either that, or we need something like a IUnauthorizedActionListener.
For now I'm just going ahead with IExceptionMapper, copy and paste
DefaultExceptionMapper...
Cheers,
Jesse
On 11/12/2012 18:28, Paul Bors wrote:
Maybe this helps you a bit more...
I have my own CompoundAuthorizationStrategy that in turn uses a few nested
IAuthorizationStrategy and one of them throws
RestartResponseAtInterceptPageException depending on the condition inside
isInstantiationAuthorized() similar to:
public boolean isInstantiationAuthorized(Class componentClass) {
MySession session = MySession.session();
...
// Page is the parent of all protected pages
if(componentClass.getAnnotation(Authenticate.class) != null) {
User user = session.getUser();
if(user == null) {
throw new
RestartResponseAtInterceptPageException(MyApplication.myApp().getSignInPageC
lass());
}
}
...
}
For the above code I have my pages annotated with my own Authenticate but I
think you should be able to check the type of the componentClass for what
you want and etc.
~ Thank you,
Paul Bors
-----Original Message-----
From: Jesse Long [mailto:[email protected]]
Sent: Tuesday, December 11, 2012 2:30 AM
To: [email protected]
Subject: Re: Redirect to login page on
UnauthorizedActionException(Page,RENDER)
Hi Paul,
Thanks for the reply. Yes, I only want to redirect to a login page on
UnauthorizedActionException when the component is an instance of Page and
the action as RENDER and when the session is not authenticated, so a custom
access denied page is not exactly what I'm looking for, but I could probably
make it work.
Cheers,
Jesse
On 10/12/2012 19:40, Paul Bors wrote:
Do you want to redirect to the Login page for all "thrown"
AccessDenied exceptions? Or just in some situations?
If you want to do it for all, then create your own WebPage for
AccessDeinedPage such as:
public class AccessDeniedPage extends WebPage {
private static final long serialVersionUID = 1L;
public AccessDeniedPage() {
Session.get().warn(ResourceModel("access.denied"));
throw new
RestartResponseException(Application.get().getLoginPage());
}
}
And inside your Application class in your init():
@Override
protected void init() {
...
IApplicationSettings applicationSettings = getApplicationSettings();
applicationSettings.setAccessDeniedPage(AccessDeniedPage.class);
...
}
There are other such exceptions which you can assign your own page
implementation, see the API for IApplicationSettings.
As for redirecting the user to your custom AccessDeined page (the
LoginPage) only under few circumstances, I haven't run into that need
yet so someone else could help you if you really need to do that.
~ Thank you,
Paul Bors
-----Original Message-----
From: Jesse Long [mailto:[email protected]]
Sent: Monday, December 10, 2012 11:05 AM
To: [email protected]
Subject: Redirect to login page on
UnauthorizedActionException(Page,RENDER)
Hi All,
I am using the authorization strategy to authorize viewing of pages by
checking if instantiation is allowed. If the session is not
authenticated, and if instantiation is not allowed, I redirect the
user to a login page using an IUnauthorizedComponentInstantiationListener.
I also check if the RENDER action is allowed using the authorization
strategy. At the moment, if the user tries to view a Page which he is
allowed to instantiate, but where the authorization strategy denies
RENDER permission (permissions configured for render/enable, but not
for instantiation), he gets a AccessDenied page. In these situations,
I also want to redirect the user to a login page if the session is not
authenticated.
Would IExceptionMapper be the correct place to do this? If so, could
we make DefaultExceptionMapper a bit easier to extend please?
Thanks,
Jesse
---------------------------------------------------------------------
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]
---------------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]