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.extensions.markup.html.repeater.data.table.BooleanPropertyColumn;
24  import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.CollectionPropertyColumn;
25  import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
26  import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
27  import org.apache.syncope.common.lib.policy.AccountPolicyTO;
28  import org.apache.syncope.common.lib.types.IdRepoEntitlement;
29  import org.apache.syncope.common.lib.types.PolicyType;
30  import org.apache.wicket.PageReference;
31  import org.apache.wicket.ajax.AjaxRequestTarget;
32  import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
33  import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
34  import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
35  import org.apache.wicket.model.IModel;
36  import org.apache.wicket.model.StringResourceModel;
37  
38  /**
39   * Account policies page.
40   */
41  public class AccountPolicyDirectoryPanel extends PolicyDirectoryPanel<AccountPolicyTO> {
42  
43      private static final long serialVersionUID = 4984337552918213290L;
44  
45      public AccountPolicyDirectoryPanel(
46              final String id,
47              final PolicyRestClient restClient,
48              final PageReference pageRef) {
49  
50          super(id, restClient, PolicyType.ACCOUNT, pageRef);
51  
52          this.addNewItemPanelBuilder(new PolicyModalPanelBuilder<>(
53                  PolicyType.ACCOUNT, new AccountPolicyTO(), modal, restClient, pageRef), true);
54          MetaDataRoleAuthorizationStrategy.authorize(addAjaxLink, RENDER, IdRepoEntitlement.POLICY_CREATE);
55  
56          initResultTable();
57      }
58  
59      @Override
60      protected void addCustomColumnFields(final List<IColumn<AccountPolicyTO, String>> columns) {
61          columns.add(new CollectionPropertyColumn<>(new StringResourceModel(
62                  "passthroughResources", this), "passthroughResources"));
63  
64          columns.add(new PropertyColumn<>(new StringResourceModel(
65                  "maxAuthenticationAttempts", this), "maxAuthenticationAttempts", "maxAuthenticationAttempts"));
66  
67          columns.add(new BooleanPropertyColumn<>(new StringResourceModel(
68                  "propagateSuspension", this), "propagateSuspension", "propagateSuspension"));
69      }
70  
71      @Override
72      protected void addCustomActions(final ActionsPanel<AccountPolicyTO> panel, final IModel<AccountPolicyTO> model) {
73          panel.add(new ActionLink<>() {
74  
75              private static final long serialVersionUID = -3722207913631435501L;
76  
77              @Override
78              public void onClick(final AjaxRequestTarget target, final AccountPolicyTO ignore) {
79                  target.add(ruleCompositionModal.setContent(new PolicyRuleDirectoryPanel<>(
80                          ruleCompositionModal, model.getObject().getKey(), PolicyType.ACCOUNT, restClient, pageRef)));
81  
82                  ruleCompositionModal.header(new StringResourceModel(
83                          "policy.rules", AccountPolicyDirectoryPanel.this, model));
84  
85                  MetaDataRoleAuthorizationStrategy.authorize(
86                          ruleCompositionModal.getForm(), ENABLE, IdRepoEntitlement.POLICY_UPDATE);
87  
88                  ruleCompositionModal.show(true);
89              }
90          }, ActionLink.ActionType.COMPOSE, IdRepoEntitlement.POLICY_UPDATE);
91      }
92  }