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:org.devgateway.eudevfin.ui.common.permissions.PermissionAuthorizationStrategy.java

License:Open Source License

/**
 * {@inheritDoc IAuthorizationStrategy#isActionAuthorized}
 *///from   w  w  w .  j  a va2s.  c  om
@Override
public boolean isActionAuthorized(Component component, Action action) {
    if (action == Component.ENABLE)
        return true; // we don't have permissions for enable, yet
    if (!(component instanceof PermissionAwareComponent))
        return true;
    if (action != Component.RENDER)
        throw new AssertionError("was assuming that action is render from this step forward");
    PermissionAwareComponent pwc = (PermissionAwareComponent) component;
    Page page = component.getPage();
    if (page == null || !(page instanceof PermissionAwarePage))
        return true; //not a permission aware page => other strategies decide

    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();
    HttpServletRequest httpServletRequest = requestAttributes.getRequest();
    String transactionType = httpServletRequest.getParameter(Constants.PARAM_TRANSACTION_TYPE);
    if (transactionType == null || transactionType.isEmpty())
        return true; //not a transaction aware scope => others decide

    HashMap<String, RoleActionMapping> permissions = ((PermissionAwarePage) page).getPermissions();
    return checkPermissions(pwc, transactionType, permissions);
}

From source file:org.devgateway.toolkit.forms.wicket.page.user.EditUserPage.java

License:Open Source License

@Override
protected void onInitialize() {
    Person person = SecurityUtil.getCurrentAuthenticatedPerson();

    if (!SecurityUtil.isCurrentUserAdmin()) {
        if (person.getId() != getPageParameters().get(WebConstants.PARAM_ID).toLong()) {
            setResponsePage(getApplication().getHomePage());
        }//from   w ww . jav  a2  s.  c  o m
    }

    super.onInitialize();

    userName.required();
    userName.getField().add(new UsernamePatternValidator());
    StringValue idPerson = getPageParameters().get(WebConstants.PARAM_ID);
    if (!idPerson.isNull()) {
        userName.getField().add(new UniqueUsernameValidator(idPerson.toLong()));
    } else {
        userName.getField().add(new UniqueUsernameValidator());
    }
    userName.setIsFloatedInput(true);
    editForm.add(userName);
    MetaDataRoleAuthorizationStrategy.authorize(userName, Component.ENABLE, SecurityConstants.Roles.ROLE_ADMIN);

    firstName.required();
    firstName.setIsFloatedInput(true);
    editForm.add(firstName);

    lastName.required();
    lastName.setIsFloatedInput(true);
    editForm.add(lastName);

    email.required();
    email.getField().add(EmailAddressValidator.getInstance());
    if (!idPerson.isNull()) {
        email.getField().add(new UniqueEmailAddressValidator(idPerson.toLong()));
    } else {
        email.getField().add(new UniqueEmailAddressValidator());
    }
    email.setIsFloatedInput(true);
    editForm.add(email);

    title.setIsFloatedInput(true);
    editForm.add(title);

    group.required();
    group.setIsFloatedInput(true);
    editForm.add(group);
    MetaDataRoleAuthorizationStrategy.authorize(group, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);

    editForm.add(defaultDashboard);
    MetaDataRoleAuthorizationStrategy.authorize(defaultDashboard, Component.ENABLE,
            SecurityConstants.Roles.ROLE_ADMIN);

    roles.required();
    roles.getField().setOutputMarkupId(true);
    roles.setIsFloatedInput(true);
    editForm.add(roles);
    MetaDataRoleAuthorizationStrategy.authorize(roles, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);

    // stop resetting the password fields each time they are rendered
    password.getField().setResetPassword(false);
    cpassword.getField().setResetPassword(false);
    if (SecurityUtil.isCurrentUserAdmin() && !SecurityUtil.isUserAdmin(compoundModel.getObject())
            && idPerson.isNull()) {
        // hide the change password checkbox and set it's model to true
        compoundModel.getObject().setChangePass(true);
        changePass.setVisibilityAllowed(false);
    } else {
        compoundModel.getObject().setChangePass(compoundModel.getObject().getChangePassword());
        password.getField().setEnabled(compoundModel.getObject().getChangePassword());
        cpassword.getField().setEnabled(compoundModel.getObject().getChangePassword());
    }

    changePass.setIsFloatedInput(true);
    editForm.add(changePass);

    password.getField().add(new PasswordPatternValidator());
    password.setOutputMarkupId(true);
    password.setIsFloatedInput(true);
    editForm.add(password);

    cpassword.setOutputMarkupId(true);
    cpassword.setIsFloatedInput(true);
    editForm.add(cpassword);

    editForm.add(new EqualPasswordInputValidator(password.getField(), cpassword.getField()));

    enabled.setIsFloatedInput(true);
    editForm.add(enabled);
    MetaDataRoleAuthorizationStrategy.authorize(enabled, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);

    changePassword.setIsFloatedInput(true);
    editForm.add(changePassword);
    MetaDataRoleAuthorizationStrategy.authorize(changePassword, Component.RENDER,
            SecurityConstants.Roles.ROLE_ADMIN);

    MetaDataRoleAuthorizationStrategy.authorize(deleteButton, Component.RENDER,
            SecurityConstants.Roles.ROLE_ADMIN);
}