View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.policies;
20  
21  import java.util.List;
22  import org.apache.syncope.client.console.rest.PolicyRestClient;
23  import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
24  import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
25  import org.apache.syncope.common.lib.policy.AccessPolicyTO;
26  import org.apache.syncope.common.lib.policy.DefaultAccessPolicyConf;
27  import org.apache.syncope.common.lib.types.IdRepoEntitlement;
28  import org.apache.syncope.common.lib.types.PolicyType;
29  import org.apache.wicket.PageReference;
30  import org.apache.wicket.ajax.AjaxRequestTarget;
31  import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
32  import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
33  import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
34  import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
35  import org.apache.wicket.markup.html.basic.Label;
36  import org.apache.wicket.markup.repeater.Item;
37  import org.apache.wicket.model.IModel;
38  import org.apache.wicket.model.Model;
39  import org.apache.wicket.model.StringResourceModel;
40  
41  public class AccessPolicyDirectoryPanel extends PolicyDirectoryPanel<AccessPolicyTO> {
42  
43      private static final long serialVersionUID = 4984337552918213290L;
44  
45      public AccessPolicyDirectoryPanel(final String id, final PolicyRestClient restClient, final PageReference pageRef) {
46          super(id, restClient, PolicyType.ACCESS, pageRef);
47  
48          AccessPolicyTO defaultItem = new AccessPolicyTO();
49  
50          this.addNewItemPanelBuilder(
51                  new PolicyModalPanelBuilder<>(PolicyType.ACCESS, defaultItem, modal, restClient, pageRef), true);
52          MetaDataRoleAuthorizationStrategy.authorize(addAjaxLink, RENDER, IdRepoEntitlement.POLICY_CREATE);
53  
54          initResultTable();
55      }
56  
57      @Override
58      protected void addCustomColumnFields(final List<IColumn<AccessPolicyTO, String>> columns) {
59          columns.add(new AbstractColumn<AccessPolicyTO, String>(new StringResourceModel("conf", this)) {
60  
61              private static final long serialVersionUID = -7226955670801277153L;
62  
63              @Override
64              public void populateItem(
65                      final Item<ICellPopulator<AccessPolicyTO>> cellItem,
66                      final String componentId,
67                      final IModel<AccessPolicyTO> rowModel) {
68  
69                  cellItem.add(new Label(componentId, rowModel.getObject().getConf() == null
70                          ? ""
71                          : rowModel.getObject().getConf().getClass().getName()));
72              }
73          });
74      }
75  
76      @Override
77      protected void addCustomActions(final ActionsPanel<AccessPolicyTO> panel, final IModel<AccessPolicyTO> model) {
78          panel.add(new ActionLink<>() {
79  
80              private static final long serialVersionUID = -3722207913631435501L;
81  
82              @Override
83              public void onClick(final AjaxRequestTarget target, final AccessPolicyTO ignore) {
84                  model.setObject(restClient.read(type, model.getObject().getKey()));
85                  if (model.getObject().getConf() == null) {
86                      model.getObject().setConf(new DefaultAccessPolicyConf());
87                  }
88                  target.add(policySpecModal.setContent(
89                          new AccessPolicyModalPanel(policySpecModal, model, pageRef)));
90                  policySpecModal.header(new Model<>(getString("accessPolicyConf.title", model)));
91                  policySpecModal.show(true);
92              }
93          }, ActionLink.ActionType.CHANGE_VIEW, IdRepoEntitlement.POLICY_UPDATE);
94      }
95  }