List of usage examples for org.apache.wicket.authroles.authorization.strategies.role.metadata ActionPermissions ActionPermissions
ActionPermissions
From source file:org.apache.syncope.client.console.commons.ITabComponent.java
License:Apache License
/** * Constructor.//w w w . j a va 2s.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.Groups.java
License:Apache License
public <T extends AnyTO> Groups(final T anyTO, final boolean templateMode) { super();//from w w w . j a va 2 s .c o m final String realm = templateMode ? "/" : anyTO.getRealm(); // ----------------------------------------------------------------- // Pre-Authorizations // ----------------------------------------------------------------- final ActionPermissions permissions = new ActionPermissions(); setMetaData(MetaDataRoleAuthorizationStrategy.ACTION_PERMISSIONS, permissions); permissions.authorizeAll(RENDER); // ----------------------------------------------------------------- setOutputMarkupId(true); Args.isTrue((anyTO instanceof UserTO) || (anyTO instanceof AnyObjectTO), "Expected user or anyObject"); AjaxPalettePanel.Builder<MembershipTO> builder = new AjaxPalettePanel.Builder<MembershipTO>() .setRenderer(new IChoiceRenderer<MembershipTO>() { private static final long serialVersionUID = -3086661086073628855L; @Override public Object getDisplayValue(final MembershipTO object) { return object.getGroupName(); } @Override public String getIdValue(final MembershipTO object, final int index) { return object.getGroupName(); } @Override public MembershipTO getObject(final String id, final IModel<? extends List<? extends MembershipTO>> choices) { return IterableUtils.find(choices.getObject(), new Predicate<MembershipTO>() { @Override public boolean evaluate(final MembershipTO object) { return id.equalsIgnoreCase(object.getGroupName()); } }); } }); add(builder.setAllowOrder(true).withFilter() .build("groups", new ListModel<>(GroupableRelatableTO.class.cast(anyTO).getMemberships()), new AjaxPalettePanel.Builder.Query<MembershipTO>() { private static final long serialVersionUID = -7223078772249308813L; @Override public List<MembershipTO> execute(final String filter) { return CollectionUtils.collect( groupRestClient.search(realm, SyncopeClient.getGroupSearchConditionBuilder().isAssignable().and() .is("name").equalTo(filter).query(), -1, -1, new SortParam<>("name", true), null), new Transformer<GroupTO, MembershipTO>() { @Override public MembershipTO transform(final GroupTO input) { return new MembershipTO.Builder() .group(input.getKey(), input.getName()).build(); } }, new ArrayList<MembershipTO>()); } }) .hideLabel().setOutputMarkupId(true)); allGroups = groupRestClient.search("/", null, -1, -1, new SortParam<>("name", true), null); final Map<String, GroupTO> allGroupsByKey = new LinkedHashMap<>(allGroups.size()); for (GroupTO group : allGroups) { allGroupsByKey.put(group.getKey(), group); } add(new AjaxPalettePanel.Builder<String>().setAllowOrder(true).build("dyngroups", new ListModel<>(CollectionUtils.collect(GroupableRelatableTO.class.cast(anyTO).getDynGroups(), new Transformer<String, String>() { @Override public String transform(final String input) { return allGroupsByKey.get(input).getName(); } }, new ArrayList<String>())), new ListModel<>(CollectionUtils.collect(allGroups, new Transformer<GroupTO, String>() { @Override public String transform(final GroupTO input) { return input.getName(); } }, new ArrayList<String>()))).hideLabel().setEnabled(false).setOutputMarkupId(true)); }
From source file:org.apache.syncope.client.console.wizards.any.Ownership.java
License:Apache License
public Ownership(final GroupWrapper groupWrapper, final PageReference pageRef) { super();/* ww w. j a va 2s. 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 ww. java 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,//from ww w . j av a 2 s .co m 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); 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)); }