Example usage for org.apache.wicket Component ENABLE

List of usage examples for org.apache.wicket Component ENABLE

Introduction

In this page you can find the example usage for org.apache.wicket Component ENABLE.

Prototype

Action ENABLE

To view the source code for org.apache.wicket Component ENABLE.

Click Source Link

Document

Action used with IAuthorizationStrategy to determine whether a component is allowed to be enabled.

Usage

From source file:com.googlecode.wicketelements.security.AnnotationAuthorizationStrategy.java

License:Apache License

public boolean isActionAuthorized(final Component componentParam, final Action actionParam) {
    PARAM_REQ.Object.requireNotNull(componentParam, "The component parameter must not be null.");
    PARAM_REQ.Object.requireNotNull(actionParam, "The action parameter must not be null.");
    final Class<? extends Component> componentClass = componentParam.getClass();
    if (securityCheck.isSecurityAnnotatedComponent(componentClass)) {
        final IUser user = SecureSession.get().getUser();
        if (user != null) {
            Class<? extends Annotation> securityAnnotationClass = null;
            List<Class<? extends SecurityConstraint>> constraints = null;
            if (Component.RENDER.equals(actionParam)) {
                securityAnnotationClass = RenderAction.class;
                constraints = securityCheck.findSecurityConstraintsForRender(componentParam);
            } else if (Component.ENABLE.equals(actionParam)) {
                securityAnnotationClass = EnableAction.class;
                if (!isActionAuthorized(componentParam.getParent(), actionParam)) {
                    return false;
                } //else go on, check if the user has the permission
                constraints = securityCheck.findSecurityConstraintsForEnable(componentParam);
            }// w  ww.j  ava2  s .c o  m
            if (securityAnnotationClass == null) {
                throw new IllegalStateException(
                        "Action is unknown (Render or Enable expected).: " + actionParam);
            }
            final boolean constraintsSatisfied = securityCheck
                    .isAllSecurityConstraintsSatisfiedForAction(componentParam, constraints);
            final Set<String> permissions = securityCheck.findImpliedPermissions(componentClass,
                    securityAnnotationClass);
            final boolean userHasPermission = securityCheck.isAtLeastOnePermissionGivenToUser(permissions);
            return constraintsSatisfied && userHasPermission;
        }
    } else {
        LOGGER.debug("No security annotation on the component.  Action is authorized.");
        return true;
    }
    return true;
}

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

License:Open Source License

public boolean isActionAuthorized(Component component, Action action) {
    if (action.equals(Component.RENDER)) {
        Class<? extends Component> c = component.getClass();
        AdminOnly adminOnly = c.getAnnotation(AdminOnly.class);

        if (adminOnly != null) {
            return UserWeaveSession.get().isAdmin();
        }/*from  w w  w  .j a v  a  2s  .  com*/

        /**
         * To set the state of an AuthOnlyTextComponent
         * may be stupid here, but there is currently
         * no other option.
         */
        if (component instanceof IAuthOnly) {
            IAuthOnly comp = (IAuthOnly) component;

            User user = UserWeaveSession.get().getUser();

            AuthorizeAction authAction = comp.getClass().getAnnotation(AuthorizeAction.class);

            boolean auth = false;

            if (authAction == null) {
                // if no annotation is given, admins and participants
                // have access
                auth = user.hasRole(Role.PROJECT_ADMIN) || user.hasRole(Role.PROJECT_PARTICIPANT);
            } else {
                // evaluate annotation roles
                auth = user.hasAnyRole(new Roles(authAction.roles()));
            }

            comp.setIsAuthorized(auth || user.isAdmin());

            return true;
        }
    }

    if (action.equals(Component.ENABLE)) {
        AuthorizeAction authAction = component.getClass().getAnnotation(AuthorizeAction.class);

        if (authAction != null) {
            User user = UserWeaveSession.get().getUser();

            boolean isEnabled = user.hasAnyRole(new Roles(authAction.roles()));

            if (!isEnabled) {
                if (component instanceof IToolTipComponent) {
                    ((IToolTipComponent) component).setToolTipType(ToolTipType.RIGHTS);
                }
            }

            return isEnabled && component.isEnabled();
        }

        return true;
    }

    return true;
}

From source file:com.visural.wicket.security.AuthorizationStrategy.java

License:Apache License

public boolean isActionAuthorized(Component com, Action action) {
    if (action.equals(Component.ENABLE) && ISecureEnableInstance.class.isAssignableFrom(com.getClass())) {
        if (!((ISecureEnableInstance) com).getEnablePrivilege()
                .isGrantedToClient(clientProvider.getCurrentClient())) {
            return false;
        }//from w  w  w  . j av  a 2 s.  co  m
    }
    if (action.equals(Component.RENDER) && ISecureRenderInstance.class.isAssignableFrom(com.getClass())) {
        if (!((ISecureRenderInstance) com).getRenderPrivilege()
                .isGrantedToClient(clientProvider.getCurrentClient())) {
            return false;
        }
    }
    return true;
}

From source file:dk.frankbille.scoreboard.security.ScoreBoardAuthorizationStrategy.java

License:Open Source License

@Override
public boolean isActionAuthorized(Component component, Action action) {
    if (component instanceof RequiresLoginToRender && Component.RENDER.equals(action)) {
        return isAuthorized();
    } else if (component instanceof RequiresLoginToBeEnabled && Component.ENABLE.equals(action)) {
        return isAuthorized();
    }/*from  w  w  w.ja  v  a 2s  .  c om*/
    return true;
}

From source file:org.devgateway.eudevfin.dim.pages.transaction.crs.TransactionPage.java

License:Open Source License

@SuppressWarnings("unchecked")
public TransactionPage(final PageParameters parameters) {
    super(parameters);

    //override the title
    pageTitle.setDefaultModel(new StringResourceModel(
            parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString(""), this, null, null));

    try {//from w  ww .  j av  a2s  .  com
        // check if the key is missing in the resource file
        getString(parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString("") + ".note");
        note = new Label("note", new StringResourceModel(
                parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString("") + ".note", this, null, null));
    } catch (MissingResourceException mre) {
        note = new Label("note", new Model<String>(" "));
        note.add(new AttributeAppender("class", new Model<String>("hide"), " "));
    }
    add(note.setEscapeModelStrings(false));
    try {
        // check if the key is missing in the resource file
        getString(parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString("") + ".subnote");
        subnote = new Label("subnote", new StringResourceModel(
                parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString("") + ".subnote", this, null, null));
    } catch (MissingResourceException mre) {
        subnote = new Label("subnote", new Model<String>(" "));
        subnote.add(new AttributeAppender("class", new Model<String>("hide"), " "));
    }
    add(subnote.setEscapeModelStrings(false));

    onUnloadScript = "window.onbeforeunload = function(e) {\n" + "   var message = '"
            + new StringResourceModel("leaveMessage", this, null, null).getObject() + "';\n"
            + "   e = e || window.event;\n" + "   if(e) {\n" + "       e.returnValue = message;\n" + // For IE 8 and old Firefox
            "   }\n" + "   return message;\n" + "};";

    // TODO: check that transactionType in the request parameters is the
    // same as the loaded transaction's type
    FinancialTransaction financialTransaction = null;

    if (!parameters.get(PARAM_TRANSACTION_ID).isNull()) {
        long transactionId = parameters.get(PARAM_TRANSACTION_ID).toLong();
        financialTransaction = financialTransactionService.findOne(transactionId).getEntity();
    } else {
        financialTransaction = getFinancialTransaction();
        initializeFinancialTransaction(financialTransaction, parameters);
    }

    CompoundPropertyModel<FinancialTransaction> model = new CompoundPropertyModel<FinancialTransaction>(
            financialTransaction);

    setModel(model);

    form = new Form("form");
    add(form);

    List<ITabWithKey> tabList = populateTabList(parameters);

    BootstrapJSTabbedPanel<ITabWithKey> bc = new BootstrapJSTabbedPanel<>("bc", tabList)
            .positionTabs(BootstrapJSTabbedPanel.Orientation.RIGHT);
    form.add(bc);

    submitButton = new TransactionPageSubmitButton("submit",
            new StringResourceModel("button.submit", this, null, null)) {
        private static final long serialVersionUID = -1909494416938537482L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            logger.info("Submit pressed");
            FinancialTransaction transaction = (FinancialTransaction) form.getInnermostModel().getObject();
            Message message = prepareMessage(transaction);
            super.onSubmit(target, form);
            message = checkNewId(message, transaction);

            if (!form.hasError()) {
                //send the message if any
                if (message != null)
                    mxService.save(message);
                setResponsePage(HomePage.class);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            super.onError(target, form);
            target.appendJavaScript(onUnloadScript);
        }
    };

    submitButton
            .add(new AttributePrepender("onclick", new Model<String>("window.onbeforeunload = null;"), " "));
    form.add(submitButton);

    TransactionPageSubmitButton saveButton = new TransactionPageSubmitButton("save",
            new StringResourceModel("button.save", this, null, null)) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (TransactionPage.this instanceof CustomTransactionPage) {
                CustomTransactionPage ctp = (CustomTransactionPage) TransactionPage.this;
                ctp.getApproved().getField().setModelObject(false);
                ctp.getDraft().getField().setModelObject(true);
                target.add(ctp.getDraft().getField());
                target.add(ctp.getApproved().getField());
            }

            super.onSubmit(target, form);
        }
    };
    saveButton.setDefaultFormProcessing(false);
    form.add(saveButton);

    TransactionPageDeleteButton transactionPageDeleteButton = new TransactionPageDeleteButton("delete",
            new StringResourceModel("button.delete", this, null, null));
    MetaDataRoleAuthorizationStrategy.authorize(transactionPageDeleteButton, Component.ENABLE,
            AuthConstants.Roles.ROLE_TEAMLEAD);
    form.add(transactionPageDeleteButton);

    form.add(new BootstrapCancelButton("cancel", new StringResourceModel("button.cancel", this, null, null)) {
        private static final long serialVersionUID = -3097577464142022353L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            logger.info("Cancel pressed");
            setResponsePage(HomePage.class);
        }

    });

    feedbackPanel = new NotificationPanel("feedback");
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.hideAfter(Duration.seconds(5));
    add(feedbackPanel);
}

From source file:org.devgateway.eudevfin.dim.pages.transaction.custom.CustomTransactionPage.java

License:Open Source License

public CustomTransactionPage(PageParameters parameters) {
    super(parameters);

    draft = new CheckBoxField("draft", new RWComponentPropertyModel<Boolean>("draft")) {
        @Override//from w  ww. j  a  va  2 s  . co m
        protected CheckBox newField(String id, IModel<Boolean> model) {
            return new AjaxCheckBox(id, model) {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    if (this.getModel().getObject()) {
                        info(new NotificationMessage(new StringResourceModel("notification.draftState",
                                CustomTransactionPage.this, null, null)));
                        approved.getField().setModelObject(false);
                        target.add(approved.getField());
                        submitButton.setDefaultFormProcessing(false); //unvalidated form save is allowed as draft
                    } else {
                        info(new NotificationMessage(new StringResourceModel("notification.nonDraftState",
                                CustomTransactionPage.this, null, null)));
                        submitButton.setDefaultFormProcessing(true); //unvalidated form save is NOT allowed as non-draft
                    }
                    target.add(feedbackPanel);
                }
            };
        }
    };

    approved = new CheckBoxField("approved", new RWComponentPropertyModel<Boolean>("approved")) {
        @Override
        protected CheckBox newField(String id, IModel<Boolean> model) {
            return new AjaxCheckBox(id, model) {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    if (this.getModel().getObject()) {
                        info(new NotificationMessage(new StringResourceModel("notification.approvedState",
                                CustomTransactionPage.this, null, null)));
                        draft.getField().setModelObject(false);
                        target.add(draft.getField());
                        submitButton.setDefaultFormProcessing(true);
                    } else
                        info(new NotificationMessage(new StringResourceModel("notification.unapprovedState",
                                CustomTransactionPage.this, null, null)));
                    target.add(feedbackPanel);
                    submitButton.setDefaultFormProcessing(true);
                }
            };
        }
    };

    MetaDataRoleAuthorizationStrategy.authorize(approved, Component.ENABLE, AuthConstants.Roles.ROLE_TEAMLEAD);
    form.add(draft);
    form.add(approved);

    CustomFinancialTransaction financialTransaction = (CustomFinancialTransaction) form.getInnermostModel()
            .getObject();
    if (!parameters.get(PARAM_REUSE).isNull())
        initializeFinancialTransaction(FinancialTransactionUtil.prepareClonedTransaction(financialTransaction),
                parameters);

    draft.removeSpanFromControlGroup();
    approved.removeSpanFromControlGroup();
}

From source file:org.devgateway.eudevfin.mcm.pages.EditPersistedUserPage.java

License:Open Source License

@SuppressWarnings("unchecked")
public EditPersistedUserPage(final PageParameters parameters) {
    super(parameters);

    final PersistedUser persistedUser = getEditablePersistedUser(parameters);

    Form form = new Form("form");

    CompoundPropertyModel<? extends PersistedUser> model = new CompoundPropertyModel<>(persistedUser);
    setModel(model);/*from  w w w . j a va2  s.  c  o m*/

    TextInputField<String> userName = new TextInputField<>("username",
            new RWComponentPropertyModel<String>("username")).required().typeString();

    TextInputField<String> firstName = new TextInputField<>("firstName",
            new RWComponentPropertyModel<String>("firstName")).required().typeString();

    TextInputField<String> lastName = new TextInputField<>("lastName",
            new RWComponentPropertyModel<String>("lastName")).required().typeString();

    TextInputField<String> email = new TextInputField<>("email", new RWComponentPropertyModel<String>("email"))
            .typeString();
    email.getField().add(EmailAddressValidator.getInstance());

    TextInputField<String> phone = new TextInputField<>("phone", new RWComponentPropertyModel<String>("phone"))
            .typeString();

    userName.getField().add(new UniqueUsernameValidator(persistedUser.getId()));

    final PasswordInputField password = new PasswordInputField("password",
            new RWComponentPropertyModel<String>("plainPassword"));
    password.getField().setResetPassword(false).setEnabled(false);
    password.getField().add(new PasswordPatternValidator());

    final PasswordInputField passwordCheck = new PasswordInputField("passwordCheck",
            new RWComponentPropertyModel<String>("plainPasswordCheck"));
    passwordCheck.getField().setResetPassword(false).setEnabled(false);

    final LocalComponentDetachableModel<Boolean> passwordChangeModel = new LocalComponentDetachableModel<Boolean>();
    final CheckBoxField passwordChangeField = new CheckBoxField("passwordChange", passwordChangeModel) {
        @Override
        protected CheckBox newField(String id, final IModel<Boolean> model) {
            return new AjaxCheckBox(id, model) {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    password.getField().setEnabled(this.getModelObject());
                    passwordCheck.getField().setEnabled(this.getModelObject());
                    target.add(password.getField());
                    target.add(passwordCheck.getField());
                }
            };
        }
    };

    form.add(passwordChangeField);

    CheckBoxField enabled = new CheckBoxField("enabled", new RWComponentPropertyModel<Boolean>("enabled"));

    final MultiSelectField<PersistedAuthority> authorities = new MultiSelectField<>("persistedAuthorities",
            new RWComponentPropertyModel<Collection<PersistedAuthority>>("persistedAuthorities"),
            authorityChoiceProvider);

    authorities.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = -8044183148051422831L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            if (persistedUser.getPersistedAuthorities() != null
                    && persistedUser.getPersistedAuthorities().size() > 0
                    && !persistedUser.getPersistedAuthorities().contains(
                            persistedAuthorityService.findOne(AuthConstants.Roles.ROLE_VIEWER).getEntity()))
                persistedUser.getPersistedAuthorities()
                        .add(persistedAuthorityService.findOne(AuthConstants.Roles.ROLE_USER).getEntity());

            if (persistedUser.getPersistedAuthorities() != null
                    && persistedUser.getPersistedAuthorities().contains(persistedAuthorityService
                            .findOne(AuthConstants.Roles.ROLE_SUPERVISOR).getEntity())) {
                persistedUser.getPersistedAuthorities()
                        .add(persistedAuthorityService.findOne(AuthConstants.Roles.ROLE_USER).getEntity());
                persistedUser.getPersistedAuthorities()
                        .add(persistedAuthorityService.findOne(AuthConstants.Roles.ROLE_TEAMLEAD).getEntity());
            }

            target.add(authorities);
        }

    });

    authorities.required();

    DropDownField<PersistedUserGroup> group = new DropDownField<>("group",
            new RWComponentPropertyModel<PersistedUserGroup>("group"), userGroupChoiceProvider);

    form.add(userName);
    MetaDataRoleAuthorizationStrategy.authorize(userName, Component.ENABLE,
            AuthConstants.Roles.ROLE_SUPERVISOR);

    form.add(firstName);
    form.add(lastName);

    form.add(group);
    MetaDataRoleAuthorizationStrategy.authorize(group, Component.ENABLE, AuthConstants.Roles.ROLE_SUPERVISOR);

    form.add(email);
    form.add(password);
    form.add(passwordCheck);
    form.add(phone);

    form.add(enabled);
    MetaDataRoleAuthorizationStrategy.authorize(enabled, Component.ENABLE, AuthConstants.Roles.ROLE_SUPERVISOR);

    form.add(authorities);
    MetaDataRoleAuthorizationStrategy.authorize(authorities, Component.ENABLE,
            AuthConstants.Roles.ROLE_SUPERVISOR);

    form.add(new BootstrapSubmitButton("submit", new StringResourceModel("button.submit", this, null, null)) {

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            // TODO Auto-generated method stub
            super.onError(target, form);
            target.add(feedbackPanel);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            logger.info("Submitted ok!");
            logger.info("Object:" + getModel().getObject());

            //password reset requested?
            if (passwordChangeField.getField().getModelObject()) {
                persistedUser.setPassword(DigestUtils.passwordEncrypt(persistedUser.getPlainPassword()));
            }

            userService.save(persistedUser);
            setResponsePage(ListPersistedUsersPage.class);
        }

    });

    form.add(new BootstrapCancelButton("cancel", new StringResourceModel("button.cancel", this, null, null)) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            logger.info("Cancel pressed");
            setResponsePage(ListPersistedUsersPage.class);
        }

    });

    add(form);
    form.add(new EqualPasswordInputValidator(password.getField(), passwordCheck.getField()));

    feedbackPanel = new NotificationPanel("feedback");
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.hideAfter(Duration.seconds(3));
    add(feedbackPanel);
}

From source file:org.devgateway.eudevfin.projects.module.components.tabs.ResultsTab.java

public ResultsTab(String id, PageParameters parameters) {
    super(id);/*from   w  w  w. ja  va  2  s  .com*/

    Label tabDescription = new Label("resultsDescription",
            new StringResourceModel("resultsDescription", this, null, null));
    add(tabDescription);

    resultTableListPanel = new ResultsTableListPanel(WICKETID_LIST_PANEL,
            new ProjectResultsListGenerator(NewProjectPage.project.getProjectResults()));
    add(resultTableListPanel);

    final ModalWindow modal = AddModalWindow(parameters);
    add(modal);

    BootstrapSubmitButton submitButton = new BootstrapSubmitButton("addResult",
            new StringResourceModel("button.addResult", this, null)) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            modal.show(target);
        }
    };

    MetaDataRoleAuthorizationStrategy.authorize(submitButton, Component.ENABLE,
            AuthConstants.Roles.ROLE_PROJECTS_MFA);
    MetaDataRoleAuthorizationStrategy.authorize(submitButton, Component.ENABLE,
            AuthConstants.Roles.ROLE_SUPERVISOR);
    submitButton.setDefaultFormProcessing(false);
    add(submitButton);
}

From source file:org.devgateway.eudevfin.projects.module.modals.ResultsTableModal.java

public ResultsTableModal(final PageParameters parameters, final PageReference modalWindowPage,
        final ModalWindow window) {
    final ProjectResult result = getEditableResult(parameters);
    CompoundPropertyModel<ProjectResult> model = new CompoundPropertyModel<>(result);
    setModel(model);/*from  w w w.  j a  va2s . co  m*/

    Form<ProjectResult> form = new Form<>("form");

    TextInputField<String> plannedResult = new TextInputField<>("1plannedResult",
            new RWComponentPropertyModel<String>("result")).required().typeString();
    MetaDataRoleAuthorizationStrategy.authorize(plannedResult, Component.ENABLE,
            AuthConstants.Roles.ROLE_PROJECTS_MFA);
    MetaDataRoleAuthorizationStrategy.authorize(plannedResult, Component.ENABLE,
            AuthConstants.Roles.ROLE_SUPERVISOR);
    plannedResult.getField().add(new WordsValidator(100));

    StatusProvider statusProvider = new StatusProvider(this);
    DropDownField<String> projectStatus = new DropDownField<>("status",
            new RWComponentPropertyModel<String>("status"), statusProvider);
    MetaDataRoleAuthorizationStrategy.authorize(projectStatus, Component.ENABLE,
            AuthConstants.Roles.ROLE_PROJECTS_MFA);
    MetaDataRoleAuthorizationStrategy.authorize(projectStatus, Component.ENABLE,
            AuthConstants.Roles.ROLE_PROJECTS_NGO);
    MetaDataRoleAuthorizationStrategy.authorize(projectStatus, Component.ENABLE,
            AuthConstants.Roles.ROLE_SUPERVISOR);
    projectStatus.required();
    projectStatus.setVisible(true);

    final TextAreaInputField description = new TextAreaInputField("3description",
            new RWComponentPropertyModel<String>("description"));
    MetaDataRoleAuthorizationStrategy.authorize(description, Component.ENABLE,
            AuthConstants.Roles.ROLE_PROJECTS_MFA);
    MetaDataRoleAuthorizationStrategy.authorize(description, Component.ENABLE,
            AuthConstants.Roles.ROLE_PROJECTS_NGO);
    MetaDataRoleAuthorizationStrategy.authorize(description, Component.ENABLE,
            AuthConstants.Roles.ROLE_SUPERVISOR);
    description.setRows(ProjectUtil.MAX_AREA_ROWS);
    description.setOutputMarkupId(true);
    description.maxContentLength(MAX_STRING_LENGTH);
    description.required();
    description.getField().add(new WordsValidator(MAX_WORDS));

    form.add(plannedResult);
    form.add(projectStatus);
    form.add(description);

    form.add(new BootstrapSubmitButton("submit", new StringResourceModel("button.submit", this, null)) {

        private static final long serialVersionUID = -7833958712063599191L;

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            super.onError(target, form);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            replaceResult(result);
            if (window != null) {
                window.close(target);
            }
        }

    });

    BootstrapCancelButton cancelButton = new BootstrapCancelButton("cancel",
            new StringResourceModel("button.cancel", this, null)) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (window != null) {
                window.close(target);
            }
        }

    };
    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    add(form);
}

From source file:org.devgateway.eudevfin.projects.module.pages.NewProjectPage.java

private void AddDeleteButton() {
    ProjectPageDeleteButton deleteButton = new ProjectPageDeleteButton("delete",
            new StringResourceModel("button.delete", this, null));
    MetaDataRoleAuthorizationStrategy.authorize(deleteButton, Component.ENABLE,
            AuthConstants.Roles.ROLE_TEAMLEAD);
    form.add(deleteButton);//  w  ww.j a  va  2 s .c  o  m
}