use of org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy in project hale by halestudio.
the class BaseWebApplication method init.
@Override
public void init() {
super.init();
BootstrapSettings settings = new BootstrapSettings();
final ThemeProvider themeProvider = new BootswatchThemeProvider() {
{
add(new MetroTheme());
add(new GoogleTheme());
add(new WicketTheme());
add(new Bootstrap3Theme());
defaultTheme("bootstrap-responsive");
// defaultTheme("bootstrap");
}
};
settings.setThemeProvider(themeProvider);
Bootstrap.install(this, settings);
BootstrapLess.install(this);
configureResourceBundles();
IPackageResourceGuard packageResourceGuard = getResourceSettings().getPackageResourceGuard();
if (packageResourceGuard instanceof SecurePackageResourceGuard) {
SecurePackageResourceGuard guard = (SecurePackageResourceGuard) packageResourceGuard;
guard.addPattern("+org/apache/wicket/resource/jquery/*.map");
}
// enforce mounts so security interceptors based on URLs can't be fooled
getSecuritySettings().setEnforceMounts(true);
getSecuritySettings().setAuthorizationStrategy(new SimplePageAuthorizationStrategy(SecuredPage.class, getLoginPageClass()) {
@Override
protected boolean isAuthorized() {
SecurityContext securityContext = SecurityContextHolder.getContext();
if (securityContext != null) {
Authentication authentication = securityContext.getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {
for (GrantedAuthority authority : authentication.getAuthorities()) {
if (authority.getAuthority().equals(UserConstants.ROLE_USER) || authority.getAuthority().equals(UserConstants.ROLE_ADMIN)) {
// allow access only for users/admins
return true;
}
}
}
}
return false;
}
});
getComponentInstantiationListeners().add(new SpringComponentInjector(this));
getRequestCycleListeners().add(new AbstractRequestCycleListener() {
@Override
public IRequestHandler onException(RequestCycle cycle, Exception ex) {
return new RenderPageRequestHandler(new PageProvider(new ExceptionPage(ex)));
}
});
// add login page to every application based on this one (if enabled)
Class<? extends BasePage> loginClass = getLoginPageClass();
if (loginClass != null) {
// login page
mountPage("/login", loginClass);
// user settings
mountPage("/settings", UserSettingsPage.class);
// about
mountPage("/about", AboutPage.class);
// contact
mountPage("/contact", ContactPage.class);
if (OpenIdLoginPage.class.equals(loginClass)) {
// for OpenID auth also add page for new users
mountPage("/new", NewUserPage.class);
}
}
}
use of org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy in project wicket by apache.
the class Test method testRedirect.
/**
*/
@org.junit.Test
public void testRedirect() {
final IAuthorizationStrategy authorizationStrategy = new SimplePageAuthorizationStrategy(RedirectPage.class, LoginPage.class) {
@Override
protected boolean isAuthorized() {
return false;
}
};
tester.getApplication().getSecuritySettings().setAuthorizationStrategy(authorizationStrategy);
tester.startPage(RedirectPage.class);
tester.assertRenderedPage(LoginPage.class);
}
use of org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy in project wicket by apache.
the class LibraryApplication method init.
@Override
protected void init() {
super.init();
getResourceSettings().setThrowExceptionOnMissingResource(false);
getRequestCycleSettings().setRenderStrategy(RequestCycleSettings.RenderStrategy.REDIRECT_TO_RENDER);
// Install a simple page authorization strategy, that checks all pages
// of type AuthenticatedWebPage.
IAuthorizationStrategy authorizationStrategy = new SimplePageAuthorizationStrategy(AuthenticatedWebPage.class, SignIn.class) {
@Override
protected boolean isAuthorized() {
// check whether the user is logged on
return (((LibrarySession) Session.get()).isSignedIn());
}
};
getSecuritySettings().setAuthorizationStrategy(authorizationStrategy);
}
Aggregations