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.OIDCC4UIProviderTO;
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 OIDCProviderMappingPanel extends AbstractMappingPanel {
37  
38      private static final long serialVersionUID = -4123879435574382968L;
39  
40      @SpringBean
41      protected AnyTypeRestClient anyTypeRestClient;
42  
43      @SpringBean
44      protected AnyTypeClassRestClient anyTypeClassRestClient;
45  
46      public OIDCProviderMappingPanel(
47              final String id,
48              final OIDCC4UIProviderTO opTO,
49              final ItemTransformersTogglePanel mapItemTransformers,
50              final JEXLTransformersTogglePanel jexlTransformers) {
51  
52          super(id,
53                  mapItemTransformers,
54                  jexlTransformers,
55                  new ListModel<>(opTO.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          List<String> extAttrNames = new ArrayList<>();
76          extAttrNames.add("email");
77          extAttrNames.add("family_name");
78          extAttrNames.add("name");
79          extAttrNames.add("middle_name");
80          extAttrNames.add("given_name");
81          extAttrNames.add("preferred_username");
82          extAttrNames.add("nickname");
83          extAttrNames.add("profile");
84          extAttrNames.add("gender");
85          extAttrNames.add("locale");
86          extAttrNames.add("zoneinfo");
87          extAttrNames.add("birthdate");
88          extAttrNames.add("phone_number");
89          extAttrNames.add("address");
90          extAttrNames.add("updated_at");
91  
92          return Model.ofList(extAttrNames);
93      }
94  
95      @Override
96      protected void setAttrNames(final AjaxTextFieldPanel toBeUpdated) {
97          toBeUpdated.setRequired(true);
98          toBeUpdated.setEnabled(true);
99  
100         List<String> choices = new ArrayList<>(ClassPathScanImplementationLookup.USER_FIELD_NAMES);
101 
102         anyTypeClassRestClient.list(anyTypeRestClient.read(AnyTypeKind.USER.name()).getClasses()).
103                 forEach(anyTypeClassTO -> {
104                     choices.addAll(anyTypeClassTO.getPlainSchemas());
105                     choices.addAll(anyTypeClassTO.getDerSchemas());
106                     choices.addAll(anyTypeClassTO.getVirSchemas());
107                 });
108 
109         Collections.sort(choices);
110         toBeUpdated.setChoices(choices);
111     }
112 }