Example usage for org.apache.wicket.authroles.authorization.strategies.role RoleAuthorizationStrategy add

List of usage examples for org.apache.wicket.authroles.authorization.strategies.role RoleAuthorizationStrategy add

Introduction

In this page you can find the example usage for org.apache.wicket.authroles.authorization.strategies.role RoleAuthorizationStrategy add.

Prototype

public final void add(IAuthorizationStrategy strategy) 

Source Link

Document

Adds a strategy to the chain

Usage

From source file:com.userweave.application.UserWeaveApplication.java

License:Open Source License

private void setupAuthorization() {
    UserWeaveAuthorizationStrategy authStrat = new UserWeaveAuthorizationStrategy();

    RoleAuthorizationStrategy roleStrat = new RoleAuthorizationStrategy(new IRoleCheckingStrategy() {
        @Override//from   w w  w. java2 s .c o  m
        public boolean hasAnyRole(Roles roles) {
            /*
             * Only deny roles contain the empty role. If this fact changes,
             * go to hell.
             */
            if (roles.hasRole("")) {
                return false;
            } else {
                User user = UserWeaveSession.get().getUser();
                return user.isAdmin() || user.hasAnyRole(roles);
            }
        }

    });

    roleStrat.add(authStrat);

    ISecuritySettings securitySettings = getSecuritySettings();
    //securitySettings.setAuthorizationStrategy(authStrat);
    securitySettings.setAuthorizationStrategy(roleStrat);
    securitySettings.setUnauthorizedComponentInstantiationListener(authStrat);
    if (!ENCRYPTION) {
        securitySettings.setCryptFactory(new CachingSunJceCryptFactory(
                HashProvider.md5("do what you desire", System.currentTimeMillis())));
    }
}