Example usage for org.apache.wicket.authroles.authorization.strategies.role.metadata MetaDataRoleAuthorizationStrategy authorize

List of usage examples for org.apache.wicket.authroles.authorization.strategies.role.metadata MetaDataRoleAuthorizationStrategy authorize

Introduction

In this page you can find the example usage for org.apache.wicket.authroles.authorization.strategies.role.metadata MetaDataRoleAuthorizationStrategy authorize.

Prototype

public static <T extends Component> void authorize(final Class<T> componentClass, final String roles) 

Source Link

Document

Authorizes the given role to create component instances of type componentClass.

Usage

From source file:org.apache.syncope.client.console.SyncopeConsoleApplication.java

License:Apache License

@Override
protected void init() {
    super.init();

    // read console.properties
    Properties props = new Properties();
    try (InputStream is = getClass().getResourceAsStream("/" + CONSOLE_PROPERTIES)) {
        props.load(is);//from www  .j  a va  2 s . c o m
        File consoleDir = new File(props.getProperty("console.directory"));
        if (consoleDir.exists() && consoleDir.canRead() && consoleDir.isDirectory()) {
            File consoleDirProps = FileUtils.getFile(consoleDir, CONSOLE_PROPERTIES);
            if (consoleDirProps.exists() && consoleDirProps.canRead() && consoleDirProps.isFile()) {
                props.clear();
                props.load(FileUtils.openInputStream(consoleDirProps));
            }
        }
    } catch (Exception e) {
        throw new WicketRuntimeException("Could not read " + CONSOLE_PROPERTIES, e);
    }
    version = props.getProperty("version");
    Args.notNull(version, "<version> not set");
    site = props.getProperty("site");
    Args.notNull(site, "<site> not set");
    anonymousUser = props.getProperty("anonymousUser");
    Args.notNull(anonymousUser, "<anonymousUser> not set");
    anonymousKey = props.getProperty("anonymousKey");
    Args.notNull(anonymousKey, "<anonymousKey> not set");

    String scheme = props.getProperty("scheme");
    Args.notNull(scheme, "<scheme> not set");
    String host = props.getProperty("host");
    Args.notNull(host, "<host> not set");
    String port = props.getProperty("port");
    Args.notNull(port, "<port> not set");
    String rootPath = props.getProperty("rootPath");
    Args.notNull(rootPath, "<rootPath> not set");
    String useGZIPCompression = props.getProperty("useGZIPCompression");
    Args.notNull(rootPath, "<useGZIPCompression> not set");

    clientFactory = new SyncopeClientFactoryBean()
            .setAddress(scheme + "://" + host + ":" + port + "/" + rootPath)
            .setUseCompression(BooleanUtils.toBoolean(useGZIPCompression));

    // process page properties
    pageClasses = new HashMap<>();
    populatePageClasses(props);
    pageClasses = Collections.unmodifiableMap(pageClasses);

    // Application settings
    IBootstrapSettings settings = new BootstrapSettings();

    // set theme provider
    settings.setThemeProvider(new SingleThemeProvider(new AdminLTE()));

    // install application settings
    Bootstrap.install(this, settings);

    getResourceSettings().setUseMinifiedResources(true);

    getResourceSettings().setThrowExceptionOnMissingResource(true);

    getJavaScriptLibrarySettings().setJQueryReference(new DynamicJQueryResourceReference());

    getSecuritySettings().setAuthorizationStrategy(new MetaDataRoleAuthorizationStrategy(this));

    ClassPathScanImplementationLookup lookup = (ClassPathScanImplementationLookup) getServletContext()
            .getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP);
    for (Class<? extends BasePage> clazz : lookup.getPageClasses()) {
        MetaDataRoleAuthorizationStrategy.authorize(clazz, SyncopeConsoleSession.AUTHENTICATED);
    }

    getMarkupSettings().setStripWicketTags(true);
    getMarkupSettings().setCompressWhitespace(true);

    getRequestCycleListeners().add(new SyncopeConsoleRequestCycleListener());

    mountPage("/login", getSignInPageClass());

    activitiModelerDirectory = props.getProperty("activitiModelerDirectory");
    Args.notNull(activitiModelerDirectory, "<activitiModelerDirectory> not set");

    try {
        reconciliationReportKey = props.getProperty("reconciliationReportKey");
    } catch (NumberFormatException e) {
        LOG.error("While parsing reconciliationReportKey", e);
    }
    Args.notNull(reconciliationReportKey, "<reconciliationReportKey> not set");

    mountResource("/" + ACTIVITI_MODELER_CONTEXT, new ResourceReference(ACTIVITI_MODELER_CONTEXT) {

        private static final long serialVersionUID = -128426276529456602L;

        @Override
        public IResource getResource() {
            return new FilesystemResource(ACTIVITI_MODELER_CONTEXT, activitiModelerDirectory);
        }

    });
    mountResource("/workflowDefGET", new ResourceReference("workflowDefGET") {

        private static final long serialVersionUID = -128426276529456602L;

        @Override
        public IResource getResource() {
            return new WorkflowDefGETResource();
        }
    });
    mountResource("/workflowDefPUT", new ResourceReference("workflowDefPUT") {

        private static final long serialVersionUID = -128426276529456602L;

        @Override
        public IResource getResource() {
            return new WorkflowDefPUTResource();
        }
    });

    // enable component path
    if (getDebugSettings().isAjaxDebugModeEnabled()) {
        getDebugSettings().setComponentPathAttributeName("syncope-path");
    }
}

From source file:org.wicketTutorial.metadataroles.WicketApplication.java

License:Apache License

@Override
public void init() {
    getSecuritySettings().setAuthorizationStrategy(new MetaDataRoleAuthorizationStrategy(this));
    MetaDataRoleAuthorizationStrategy.authorize(AdminOnlyPage.class, Roles.ADMIN);
}