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.panels.search;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.stream.Collectors;
24  import org.apache.syncope.client.console.rest.ApplicationRestClient;
25  import org.apache.syncope.client.console.rest.RoleRestClient;
26  import org.apache.syncope.client.lib.SyncopeClient;
27  import org.apache.syncope.common.lib.search.AbstractFiqlSearchConditionBuilder;
28  import org.apache.syncope.common.lib.to.PrivilegeTO;
29  import org.apache.syncope.common.lib.to.RoleTO;
30  import org.apache.syncope.common.lib.types.AnyTypeKind;
31  import org.apache.wicket.PageReference;
32  import org.apache.wicket.model.IModel;
33  import org.apache.wicket.model.LoadableDetachableModel;
34  import org.apache.wicket.spring.injection.annot.SpringBean;
35  
36  public class UserSearchPanel extends AnyObjectSearchPanel {
37  
38      private static final long serialVersionUID = -1769527800450203738L;
39  
40      public static class Builder extends AnyObjectSearchPanel.Builder {
41  
42          private static final long serialVersionUID = 6308997285778809578L;
43  
44          public Builder(final IModel<List<SearchClause>> model, final PageReference pageRef) {
45              super(AnyTypeKind.USER.name(), model, pageRef);
46          }
47  
48          @Override
49          public UserSearchPanel build(final String id) {
50              return new UserSearchPanel(id, this);
51          }
52      }
53  
54      @SpringBean
55      protected RoleRestClient roleRestClient;
56  
57      @SpringBean
58      protected ApplicationRestClient applicationRestClient;
59  
60      protected UserSearchPanel(final String id, final Builder builder) {
61          super(id, AnyTypeKind.USER, builder);
62      }
63  
64      @Override
65      protected AbstractFiqlSearchConditionBuilder<?, ?, ?> getSearchConditionBuilder() {
66          return SyncopeClient.getUserSearchConditionBuilder();
67      }
68  
69      @Override
70      protected String getFIQLQueryTarget() {
71          return AnyTypeKind.USER.name();
72      }
73  
74      @Override
75      protected void populate() {
76          super.populate();
77  
78          this.roleNames = new LoadableDetachableModel<>() {
79  
80              private static final long serialVersionUID = 5275935387613157437L;
81  
82              @Override
83              protected List<String> load() {
84                  return roleRestClient.list().stream().map(RoleTO::getKey).collect(Collectors.toList());
85              }
86          };
87  
88          this.privilegeNames = new LoadableDetachableModel<>() {
89  
90              private static final long serialVersionUID = 5275935387613157437L;
91  
92              @Override
93              protected List<String> load() {
94                  return applicationRestClient.list().stream().
95                          flatMap(application -> application.getPrivileges().stream()).
96                          map(PrivilegeTO::getKey).collect(Collectors.toList());
97              }
98          };
99      }
100 
101     @Override
102     protected List<SearchClause.Type> getAvailableTypes() {
103         List<SearchClause.Type> result = new ArrayList<>();
104         result.add(SearchClause.Type.ATTRIBUTE);
105         result.add(SearchClause.Type.ROLE_MEMBERSHIP);
106         result.add(SearchClause.Type.PRIVILEGE);
107         result.add(SearchClause.Type.GROUP_MEMBERSHIP);
108         result.add(SearchClause.Type.AUX_CLASS);
109         result.add(SearchClause.Type.RESOURCE);
110         result.add(SearchClause.Type.RELATIONSHIP);
111         return result;
112     }
113 }