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 java.util.stream.Collectors;
23  import org.apache.syncope.client.console.SyncopeConsoleSession;
24  import org.apache.syncope.client.console.panels.AbstractModalPanel;
25  import org.apache.syncope.client.console.rest.AuthModuleRestClient;
26  import org.apache.syncope.client.console.rest.PolicyRestClient;
27  import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
28  import org.apache.syncope.client.ui.commons.Constants;
29  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxCheckBoxPanel;
30  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPalettePanel;
31  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
32  import org.apache.syncope.client.ui.commons.pages.BaseWebPage;
33  import org.apache.syncope.common.lib.policy.AuthPolicyTO;
34  import org.apache.syncope.common.lib.to.AuthModuleTO;
35  import org.apache.syncope.common.lib.types.PolicyType;
36  import org.apache.wicket.PageReference;
37  import org.apache.wicket.ajax.AjaxRequestTarget;
38  import org.apache.wicket.model.IModel;
39  import org.apache.wicket.model.LoadableDetachableModel;
40  import org.apache.wicket.model.PropertyModel;
41  import org.apache.wicket.spring.injection.annot.SpringBean;
42  
43  public class AuthPolicyModalPanel extends AbstractModalPanel<AuthPolicyTO> {
44  
45      private static final long serialVersionUID = -7210166323800567306L;
46  
47      @SpringBean
48      protected PolicyRestClient policyRestClient;
49  
50      @SpringBean
51      protected AuthModuleRestClient authModuleRestClient;
52  
53      protected final IModel<List<String>> allAuthModules = new LoadableDetachableModel<>() {
54  
55          private static final long serialVersionUID = -2012833443695917883L;
56  
57          @Override
58          protected List<String> load() {
59              return authModuleRestClient.list().stream().map(AuthModuleTO::getKey).sorted().collect(Collectors.toList());
60          }
61      };
62  
63      private final IModel<AuthPolicyTO> model;
64  
65      public AuthPolicyModalPanel(
66              final BaseModal<AuthPolicyTO> modal,
67              final IModel<AuthPolicyTO> model,
68              final PageReference pageRef) {
69  
70          super(modal, pageRef);
71          this.model = model;
72  
73          add(new AjaxCheckBoxPanel(
74                  "tryAll",
75                  "tryAll",
76                  new PropertyModel<>(model.getObject().getConf(), "tryAll"),
77                  false));
78  
79          add(new AjaxPalettePanel.Builder<String>().setName("authModules").build(
80                  "authModules",
81                  new PropertyModel<>(model.getObject().getConf(), "authModules"),
82                  allAuthModules));
83  
84          add(new AjaxCheckBoxPanel(
85                  "bypassEnabled",
86                  "bypassEnabled",
87                  new PropertyModel<>(model.getObject().getConf(), "bypassEnabled"),
88                  false));
89  
90          add(new AjaxTextFieldPanel(
91                  "bypassPrincipalAttributeName",
92                  "bypassPrincipalAttributeName",
93                  new PropertyModel<>(model.getObject().getConf(), "bypassPrincipalAttributeName"),
94                  false));
95  
96          add(new AjaxTextFieldPanel(
97                  "bypassPrincipalAttributeValue",
98                  "bypassPrincipalAttributeValue",
99                  new PropertyModel<>(model.getObject().getConf(), "bypassPrincipalAttributeValue"),
100                 false));
101     }
102 
103     @Override
104     public void onSubmit(final AjaxRequestTarget target) {
105         try {
106             policyRestClient.update(PolicyType.AUTH, model.getObject());
107 
108             SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
109             modal.close(target);
110         } catch (Exception e) {
111             LOG.error("While updating Auth Policy {}", model.getObject().getKey(), e);
112             SyncopeConsoleSession.get().onException(e);
113         }
114         ((BaseWebPage) pageRef.getPage()).getNotificationPanel().refresh(target);
115     }
116 }