Reputation: 3329
I have a navigation bar like:
<nav>
<ul>
<wicket:link>
<li><a href="Page1.html">Page1</a></li>
<li><a href="Page2.html">Page2</a></li>
<li><a href="Page3.html">Page3</a></li>
</wicket:link>
</ul>
</nav>
This panel works really well (with the matching css).
But, Page3
is only accessible for users logged in.
@AuthorizeInstantiation("SIGNED_IN")
public class Page3 extends MyPage {
// ...
}
When a user is logged in, everything is as expected.
Navigation: Page1 Page2 Page3
But when the user is not logged in, I expect Page3
not to be part of the navigation bar (because it is not accessible).
Navigation: Page1 Page2
How can I do this? TIA!
Upvotes: 2
Views: 347
Reputation: 1273
Add your links using wicket. Then use IAuthorizationStrategy to check if you can instantiate the page the link refers to. Hide the link if not:
IAuthorizationStrategy strategy = getApplication().getSecuritySettings().getAuthorizationStrategy();
Link<?> page1link = new Link<Void>("page1") {
@Override
public void onClick() {
setResponsPage(Page1.class);
}
}
page1link.add(new Label("page1linklabel","Page 1"));
page1link.setVisible(strategy.isInstantiationAuthorized(Page1.class));
add(page1link);
The html for your link then looks like this:
<a href="#" wicket:id="page1"><span wicket:id="page1linklabel"></span></a>
Upvotes: 3