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 org.apache.syncope.client.console.rest.PolicyRestClient;
22  import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
23  import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
24  import org.apache.syncope.common.lib.policy.AuthPolicyTO;
25  import org.apache.syncope.common.lib.policy.DefaultAuthPolicyConf;
26  import org.apache.syncope.common.lib.types.IdRepoEntitlement;
27  import org.apache.syncope.common.lib.types.PolicyType;
28  import org.apache.wicket.PageReference;
29  import org.apache.wicket.ajax.AjaxRequestTarget;
30  import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
31  import org.apache.wicket.model.IModel;
32  import org.apache.wicket.model.Model;
33  
34  public class AuthPolicyDirectoryPanel extends PolicyDirectoryPanel<AuthPolicyTO> {
35  
36      private static final long serialVersionUID = 4984337552918213290L;
37  
38      public AuthPolicyDirectoryPanel(final String id, final PolicyRestClient restClient, final PageReference pageRef) {
39          super(id, restClient, PolicyType.AUTH, pageRef);
40  
41          AuthPolicyTO defaultItem = new AuthPolicyTO();
42  
43          this.addNewItemPanelBuilder(
44                  new PolicyModalPanelBuilder<>(PolicyType.AUTH, defaultItem, modal, restClient, pageRef), true);
45          MetaDataRoleAuthorizationStrategy.authorize(addAjaxLink, RENDER, IdRepoEntitlement.POLICY_CREATE);
46  
47          initResultTable();
48      }
49  
50      @Override
51      protected void addCustomActions(final ActionsPanel<AuthPolicyTO> panel, final IModel<AuthPolicyTO> model) {
52  
53          panel.add(new ActionLink<>() {
54  
55              private static final long serialVersionUID = -3722207913631435501L;
56  
57              @Override
58              public void onClick(final AjaxRequestTarget target, final AuthPolicyTO ignore) {
59                  model.setObject(restClient.read(type, model.getObject().getKey()));
60                  if (model.getObject().getConf() == null) {
61                      model.getObject().setConf(new DefaultAuthPolicyConf());
62                  }
63                  target.add(policySpecModal.setContent(
64                          new AuthPolicyModalPanel(policySpecModal, model, pageRef)));
65                  policySpecModal.header(new Model<>(getString("authPolicyConf.title", model)));
66                  policySpecModal.show(true);
67              }
68          }, ActionLink.ActionType.CHANGE_VIEW, IdRepoEntitlement.POLICY_UPDATE);
69      }
70  }