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

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

Introduction

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

Prototype

String NO_ROLE

To view the source code for org.apache.wicket.authroles.authorization.strategies.role.metadata MetaDataRoleAuthorizationStrategy NO_ROLE.

Click Source Link

Document

Special role string for denying access to all

Usage

From source file:org.devgateway.toolkit.forms.wicket.components.form.FileInputBootstrapFormComponentWrapper.java

License:Open Source License

private void addBootstrapFileInputComponent() {
    // this is where the newly uploaded files are saved
    final IModel<List<FileUpload>> internalUploadModel = new ListModel<>();

    /*//from  w ww.  ja  va  2  s  .  c om
     * some customization of the BootstrapFileInput Component
     */
    FileInputConfig fileInputConfig = new FileInputConfig();
    fileInputConfig.put(new Key<String>("browseLabel"),
            new StringResourceModel("browseLabel", FileInputBootstrapFormComponentWrapper.this, null)
                    .getString());
    fileInputConfig.put(new Key<String>("uploadClass"), "btn btn-blue");
    fileInputConfig.put(new Key<String>("browseClass"), "btn btn-blue");

    bootstrapFileInput = new BootstrapFileInput("bootstrapFileInput", internalUploadModel, fileInputConfig) {
        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        protected void onSubmit(final AjaxRequestTarget target) {
            super.onSubmit(target);

            List<FileUpload> fileUploads = internalUploadModel.getObject();

            if (fileUploads != null) {
                // check if we uploaded too many files
                if (maxFiles > 0 && filesModel.size() + fileUploads.size() > maxFiles) {
                    if (maxFiles == 1) {
                        FileInputBootstrapFormComponentWrapper.this.fatal(new StringResourceModel("OneUpload",
                                FileInputBootstrapFormComponentWrapper.this, null).getString());
                    } else {
                        FileInputBootstrapFormComponentWrapper.this
                                .fatal(new StringResourceModel("tooManyFiles",
                                        FileInputBootstrapFormComponentWrapper.this, Model.of(maxFiles))
                                                .getString());
                    }
                    FileInputBootstrapFormComponentWrapper.this.invalid();
                } else {
                    // convert the uploaded files to the internal structure
                    // and update the model
                    for (FileUpload upload : fileUploads) {
                        FileMetadata fileMetadata = new FileMetadata();
                        fileMetadata.setName(upload.getClientFileName());
                        fileMetadata.setContentType(upload.getContentType());
                        fileMetadata.setSize(upload.getSize());

                        FileContent fileContent = new FileContent();
                        fileContent.setBytes(upload.getBytes());
                        fileMetadata.setContent(fileContent);

                        filesModel.add(fileMetadata);

                        // don't display the success notification
                        // FileInputBootstrapFormComponentWrapper.this.success(new
                        // StringResourceModel("successUpload",
                        // FileInputBootstrapFormComponentWrapper.this,
                        // null, new
                        // Model(upload.getClientFileName())).getString());
                    }
                }
            }

            FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);

            target.add(fileUploadFeedback);
            target.add(pendingFiles);
        }
    };

    add(bootstrapFileInput);

    /**
     * due to an upgrade of FormGroup in wicket7/wicket-bootrap-0.10, the
     * visitor that finds inner FormComponentS, will now find two instead of
     * one: the FileInputBootstrapFormComponentWrapper and also the
     * BootstrapFileInputField. This is the RIGHT result, previously in
     * wicket 6.x it only got the first level of children, hence only one
     * FormComponent (the FileInputBootstrapFormComponentWrapper). It would
     * then read the label from FileInputBootstrapFormComponentWrapper and
     * use it for displaying the label of the FormGroup. In
     * wicket7/wicket-bootstrap-0.10 this will result in reading the label
     * of BootstrapFileInputField which is null. So you will notice no
     * labels for FormGroupS. We fix this by forcing the label of the
     * underlying fileInput element to the same model as the label used by
     * FileInputBootstrapFormComponentWrapper
     */
    FormComponent<?> fileInput = (FormComponent<?>) bootstrapFileInput.get("fileInputForm").get("fileInput");
    fileInput.setLabel(this.getLabel());

    // there are situation when we want to display the upload file component
    // only to admins
    if (visibleOnlyToAdmin) {
        MetaDataRoleAuthorizationStrategy.authorize(bootstrapFileInput, Component.RENDER,
                SecurityConstants.Roles.ROLE_ADMIN);
    }

    // for download the documents when you're already signed in as admin and
    // want to read only
    if (disableDeleteButton) {
        MetaDataRoleAuthorizationStrategy.authorize(bootstrapFileInput, Component.RENDER,
                MetaDataRoleAuthorizationStrategy.NO_ROLE);
    }
}