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

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

Introduction

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

Prototype

public final void authorize(final Action action, final Roles rolesToAdd) 

Source Link

Document

Gives permission for the given roles to perform the given action

Usage

From source file:org.apache.syncope.client.console.commons.ITabComponent.java

License:Apache License

/**
 * Constructor.// w  w  w .  j  a  v a 2  s  .  c o m
 *
 * @param title IModel used to represent the title of the tab. Must contain a string
 * @param roles authorized roles
 */
public ITabComponent(final IModel<String> title, final String roles) {
    super(UUID.randomUUID().toString());
    this.title = title;

    final ActionPermissions permissions = new ActionPermissions();
    setMetaData(MetaDataRoleAuthorizationStrategy.ACTION_PERMISSIONS, permissions);
    if (StringUtils.isBlank(roles)) {
        permissions.authorizeAll(RENDER);
    } else {
        permissions.authorize(RENDER, new Roles(roles));
    }
}

From source file:org.apache.syncope.client.console.wizards.any.Ownership.java

License:Apache License

public Ownership(final GroupWrapper groupWrapper, final PageReference pageRef) {
    super();// www.  j a v a2 s .c  om

    // -----------------------------------------------------------------
    // Pre-Authorizations
    // -----------------------------------------------------------------
    final ActionPermissions permissions = new ActionPermissions();
    setMetaData(MetaDataRoleAuthorizationStrategy.ACTION_PERMISSIONS, permissions);
    permissions.authorize(RENDER, new Roles(StandardEntitlement.USER_SEARCH));
    // -----------------------------------------------------------------

    setTitleModel(new ResourceModel("group.ownership"));
    this.wrapper = groupWrapper;

    isGroupOwnership = Model.of(groupWrapper.getInnerObject().getGroupOwner() != null);

    final BootstrapToggleConfig config = new BootstrapToggleConfig()
            .withOnStyle(BootstrapToggleConfig.Style.info).withOffStyle(BootstrapToggleConfig.Style.warning)
            .withSize(BootstrapToggleConfig.Size.mini);

    add(new BootstrapToggle("ownership", new Model<Boolean>() {

        private static final long serialVersionUID = 6062041315055645807L;

        @Override
        public Boolean getObject() {
            return isGroupOwnership.getObject();
        }
    }, config) {

        private static final long serialVersionUID = 2969634208049189343L;

        @Override
        protected IModel<String> getOffLabel() {
            return Model.of("USER Owner");
        }

        @Override
        protected IModel<String> getOnLabel() {
            return Model.of("GROUP Owner");
        }

        @Override
        protected CheckBox newCheckBox(final String id, final IModel<Boolean> model) {
            final CheckBox checkBox = super.newCheckBox(id, model);
            checkBox.add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(final AjaxRequestTarget target) {
                    isGroupOwnership.setObject(!isGroupOwnership.getObject());
                    if (isGroupOwnership.getObject()) {
                        ownerContainer.addOrReplace(groupSearchFragment);
                        groupDirectoryPanel.search(null, target);
                    } else {
                        ownerContainer.addOrReplace(userSearchFragment);
                        userDirectoryPanel.search(null, target);
                    }
                    target.add(ownerContainer);
                }
            });
            return checkBox;
        }
    });

    ownerContainer = new WebMarkupContainer("ownerContainer");
    ownerContainer.setOutputMarkupId(true);
    add(ownerContainer);

    groupSearchFragment = new Fragment("search", "groupSearchFragment", this);
    groupSearchPanel = new GroupSearchPanel.Builder(new ListModel<>(new ArrayList<SearchClause>()))
            .required(false).enableSearch(Ownership.this).build("groupsearch");
    groupSearchFragment.add(groupSearchPanel.setRenderBodyOnly(true));

    AnyTypeTO anyTypeTO = anyTypeRestClient.read(AnyTypeKind.GROUP.name());

    groupDirectoryPanel = GroupSelectionDirectoryPanel.class
            .cast(new GroupSelectionDirectoryPanel.Builder(anyTypeClassRestClient.list(anyTypeTO.getClasses()),
                    anyTypeTO.getKey(), pageRef).build("searchResult"));

    groupSearchFragment.add(groupDirectoryPanel);

    userSearchFragment = new Fragment("search", "userSearchFragment", this);
    userSearchPanel = UserSearchPanel.class
            .cast(new UserSearchPanel.Builder(new ListModel<>(new ArrayList<SearchClause>())).required(false)
                    .enableSearch(Ownership.this).build("usersearch"));
    userSearchFragment.add(userSearchPanel.setRenderBodyOnly(true));

    anyTypeTO = anyTypeRestClient.read(AnyTypeKind.USER.name());

    userDirectoryPanel = UserSelectionDirectoryPanel.class
            .cast(new UserSelectionDirectoryPanel.Builder(anyTypeClassRestClient.list(anyTypeTO.getClasses()),
                    anyTypeTO.getKey(), pageRef).build("searchResult"));

    userSearchFragment.add(userDirectoryPanel);

    if (isGroupOwnership.getObject()) {
        ownerContainer.add(groupSearchFragment);
    } else {
        ownerContainer.add(userSearchFragment);
    }

    final AjaxTextFieldPanel userOwner = new AjaxTextFieldPanel("userOwner", "userOwner",
            new PropertyModel<String>(groupWrapper.getInnerObject(), "userOwner") {

                private static final long serialVersionUID = -3743432456095828573L;

                @Override
                public String getObject() {
                    if (groupWrapper.getInnerObject().getUserOwner() == null) {
                        return StringUtils.EMPTY;
                    } else {
                        UserTO userTO = userRestClient.read(groupWrapper.getInnerObject().getUserOwner());
                        if (userTO == null) {
                            return StringUtils.EMPTY;
                        } else {
                            return String.format("[%s] %s", userTO.getKey(), userTO.getUsername());
                        }
                    }
                }

                @Override
                public void setObject(final String object) {
                    if (StringUtils.isBlank(object)) {
                        groupWrapper.getInnerObject().setUserOwner(null);
                    } else {
                        final Matcher matcher = owner.matcher(object);
                        if (matcher.matches()) {
                            groupWrapper.getInnerObject().setUserOwner(matcher.group(1));
                        }
                    }
                }
            }, false);
    userOwner.setPlaceholder("userOwner");
    userOwner.hideLabel();
    userOwner.setReadOnly(true).setOutputMarkupId(true);
    userSearchFragment.add(userOwner);

    final IndicatingAjaxLink<Void> userOwnerReset = new IndicatingAjaxLink<Void>("userOwnerReset") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            send(Ownership.this, Broadcast.EXACT,
                    new GroupSelectionDirectoryPanel.ItemSelection<GroupTO>(target, null));
        }
    };
    userSearchFragment.add(userOwnerReset);

    final AjaxTextFieldPanel groupOwner = new AjaxTextFieldPanel("groupOwner", "groupOwner",
            new PropertyModel<String>(groupWrapper.getInnerObject(), "groupOwner") {

                private static final long serialVersionUID = -3743432456095828573L;

                @Override
                public String getObject() {
                    if (groupWrapper.getInnerObject().getGroupOwner() == null) {
                        return StringUtils.EMPTY;
                    } else {
                        GroupTO groupTO = groupRestClient.read(groupWrapper.getInnerObject().getGroupOwner());
                        if (groupTO == null) {
                            return StringUtils.EMPTY;
                        } else {
                            return String.format("[%s] %s", groupTO.getKey(), groupTO.getName());
                        }
                    }
                }

                @Override
                public void setObject(final String object) {
                    if (StringUtils.isBlank(object)) {
                        groupWrapper.getInnerObject().setGroupOwner(null);
                    } else {
                        final Matcher matcher = owner.matcher(object);
                        if (matcher.matches()) {
                            groupWrapper.getInnerObject().setGroupOwner(matcher.group(1));
                        }
                    }
                }
            }, false);
    groupOwner.setPlaceholder("groupOwner");
    groupOwner.hideLabel();
    groupOwner.setReadOnly(true).setOutputMarkupId(true);
    groupSearchFragment.add(groupOwner);

    final IndicatingAjaxLink<Void> groupOwnerReset = new IndicatingAjaxLink<Void>("groupOwnerReset") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            send(Ownership.this, Broadcast.EXACT,
                    new GroupSelectionDirectoryPanel.ItemSelection<GroupTO>(target, null));
        }
    };
    groupSearchFragment.add(groupOwnerReset);
}

From source file:org.apache.syncope.client.console.wizards.any.Resources.java

License:Apache License

public <T extends AnyTO> Resources(final T entityTO) {
    // -----------------------------------------------------------------
    // Pre-Authorizations
    // -----------------------------------------------------------------
    final ActionPermissions permissions = new ActionPermissions();
    setMetaData(MetaDataRoleAuthorizationStrategy.ACTION_PERMISSIONS, permissions);
    permissions.authorize(RENDER, new org.apache.wicket.authroles.authorization.strategies.role.Roles(
            StandardEntitlement.RESOURCE_LIST));
    // -----------------------------------------------------------------

    this.setOutputMarkupId(true);
    this.available = new ListModel<>(Collections.<String>emptyList());

    add(new AjaxPalettePanel.Builder<String>()
            .build("resources", new PropertyModel<List<String>>(entityTO, "resources") {

                private static final long serialVersionUID = 3799387950428254072L;

                @Override/*from   w w  w  .jav  a 2  s. co m*/
                public List<String> getObject() {
                    return new ArrayList<>(entityTO.getResources());
                }

                @Override
                public void setObject(final List<String> object) {
                    entityTO.getResources().clear();
                    entityTO.getResources().addAll(object);
                }
            }, available).hideLabel().setOutputMarkupId(true));
}

From source file:org.apache.syncope.client.console.wizards.any.Roles.java

License:Apache License

public <T extends AnyTO> Roles(final UserTO entityTO) {
    // -----------------------------------------------------------------
    // Pre-Authorizations
    // -----------------------------------------------------------------
    final ActionPermissions permissions = new ActionPermissions();
    setMetaData(MetaDataRoleAuthorizationStrategy.ACTION_PERMISSIONS, permissions);
    permissions.authorize(RENDER,
            new org.apache.wicket.authroles.authorization.strategies.role.Roles(StandardEntitlement.ROLE_LIST));
    // -----------------------------------------------------------------

    this.setOutputMarkupId(true);

    allRoles = SyncopeConsoleApplication.get().getSecuritySettings().getAuthorizationStrategy()
            .isActionAuthorized(this, RENDER)
                    ? CollectionUtils.collect(new RoleRestClient().list(),
                            EntityTOUtils.<RoleTO>keyTransformer(), new ArrayList<String>())
                    : Collections.<String>emptyList();
    Collections.sort(allRoles);//from   w w w  . j av a  2  s.c  om

    add(new AjaxPalettePanel.Builder<String>()
            .build("roles", new PropertyModel<List<String>>(entityTO, "roles"), new ListModel<>(allRoles))
            .hideLabel().setOutputMarkupId(true));

    add(new AjaxPalettePanel.Builder<String>()
            .build("dynroles", new PropertyModel<List<String>>(entityTO, "dynRoles"), new ListModel<>(allRoles))
            .hideLabel().setEnabled(false).setOutputMarkupId(true));
}