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.wizards.mapping;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  import org.apache.syncope.client.console.init.ClassPathScanImplementationLookup;
25  import org.apache.syncope.client.console.rest.AnyTypeClassRestClient;
26  import org.apache.syncope.client.console.rest.AnyTypeRestClient;
27  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
28  import org.apache.syncope.common.lib.to.SAML2SP4UIIdPTO;
29  import org.apache.syncope.common.lib.types.AnyTypeKind;
30  import org.apache.syncope.common.lib.types.MappingPurpose;
31  import org.apache.wicket.model.IModel;
32  import org.apache.wicket.model.Model;
33  import org.apache.wicket.model.util.ListModel;
34  import org.apache.wicket.spring.injection.annot.SpringBean;
35  
36  public class SAML2IdPMappingPanel extends AbstractMappingPanel {
37  
38      private static final long serialVersionUID = 2248901624411541853L;
39  
40      @SpringBean
41      protected AnyTypeRestClient anyTypeRestClient;
42  
43      @SpringBean
44      protected AnyTypeClassRestClient anyTypeClassRestClient;
45  
46      public SAML2IdPMappingPanel(
47              final String id,
48              final SAML2SP4UIIdPTO idpTO,
49              final ItemTransformersTogglePanel mapItemTransformers,
50              final JEXLTransformersTogglePanel jexlTransformers) {
51  
52          super(id,
53                  mapItemTransformers,
54                  jexlTransformers,
55                  new ListModel<>(idpTO.getItems()),
56                  true,
57                  MappingPurpose.NONE);
58  
59          setOutputMarkupId(true);
60      }
61  
62      @Override
63      protected boolean hidePurpose() {
64          return true;
65      }
66  
67      @Override
68      protected void onBeforeRender() {
69          super.onBeforeRender();
70          intAttrNameInfo.setVisible(false);
71      }
72  
73      @Override
74      protected IModel<List<String>> getExtAttrNames() {
75          return Model.ofList(Collections.<String>singletonList("NameID"));
76      }
77  
78      @Override
79      protected void setAttrNames(final AjaxTextFieldPanel toBeUpdated) {
80          toBeUpdated.setRequired(true);
81          toBeUpdated.setEnabled(true);
82  
83          List<String> choices = new ArrayList<>(ClassPathScanImplementationLookup.USER_FIELD_NAMES);
84  
85          anyTypeClassRestClient.list(anyTypeRestClient.read(AnyTypeKind.USER.name()).getClasses()).
86                  forEach(anyTypeClassTO -> {
87                      choices.addAll(anyTypeClassTO.getPlainSchemas());
88                      choices.addAll(anyTypeClassTO.getDerSchemas());
89                      choices.addAll(anyTypeClassTO.getVirSchemas());
90                  });
91  
92          Collections.sort(choices);
93          toBeUpdated.setChoices(choices);
94      }
95  }