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.markup.html.form.ActionLink;
25  import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
26  import org.apache.syncope.common.lib.policy.PasswordPolicyTO;
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.table.IColumn;
33  import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
34  import org.apache.wicket.model.IModel;
35  import org.apache.wicket.model.Model;
36  import org.apache.wicket.model.StringResourceModel;
37  
38  /**
39   * Password policies page.
40   */
41  public class PasswordPolicyDirectoryPanel extends PolicyDirectoryPanel<PasswordPolicyTO> {
42  
43      private static final long serialVersionUID = 4984337552918213290L;
44  
45      public PasswordPolicyDirectoryPanel(
46              final String id,
47              final PolicyRestClient restClient,
48              final PageReference pageRef) {
49  
50          super(id, restClient, PolicyType.PASSWORD, pageRef);
51  
52          this.addNewItemPanelBuilder(new PolicyModalPanelBuilder<>(
53                  PolicyType.PASSWORD, new PasswordPolicyTO(), 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<PasswordPolicyTO, String>> columns) {
61          columns.add(new PropertyColumn<>(new StringResourceModel(
62                  "historyLength", this), "historyLength", "historyLength"));
63  
64          columns.add(new BooleanPropertyColumn<>(new StringResourceModel(
65                  "allowNullPassword", this), "allowNullPassword", "allowNullPassword"));
66      }
67  
68      @Override
69      protected void addCustomActions(final ActionsPanel<PasswordPolicyTO> panel, final IModel<PasswordPolicyTO> model) {
70          panel.add(new ActionLink<>() {
71  
72              private static final long serialVersionUID = -3722207913631435501L;
73  
74              @Override
75              public void onClick(final AjaxRequestTarget target, final PasswordPolicyTO ignore) {
76                  target.add(ruleCompositionModal.setContent(new PolicyRuleDirectoryPanel<>(
77                          ruleCompositionModal, model.getObject().getKey(), PolicyType.PASSWORD, restClient, pageRef)));
78  
79                  ruleCompositionModal.header(new StringResourceModel(
80                          "policy.rules", PasswordPolicyDirectoryPanel.this, Model.of(model.getObject())));
81  
82                  MetaDataRoleAuthorizationStrategy.authorize(
83                          ruleCompositionModal.getForm(), ENABLE, IdRepoEntitlement.POLICY_UPDATE);
84  
85                  ruleCompositionModal.show(true);
86              }
87          }, ActionLink.ActionType.COMPOSE, IdRepoEntitlement.POLICY_UPDATE);
88      }
89  }