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.core.persistence.jpa.dao;
20  
21  import java.util.List;
22  import java.util.Optional;
23  import java.util.Set;
24  import org.apache.commons.lang3.tuple.Pair;
25  import org.apache.syncope.core.persistence.api.dao.AccessTokenDAO;
26  import org.apache.syncope.core.persistence.api.dao.DelegationDAO;
27  import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO;
28  import org.apache.syncope.core.persistence.api.dao.DynRealmDAO;
29  import org.apache.syncope.core.persistence.api.dao.FIQLQueryDAO;
30  import org.apache.syncope.core.persistence.api.dao.GroupDAO;
31  import org.apache.syncope.core.persistence.api.dao.JPAJSONAnyDAO;
32  import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
33  import org.apache.syncope.core.persistence.api.dao.RoleDAO;
34  import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
35  import org.apache.syncope.core.persistence.api.entity.DerSchema;
36  import org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue;
37  import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
38  import org.apache.syncope.core.persistence.api.entity.PlainSchema;
39  import org.apache.syncope.core.persistence.api.entity.user.User;
40  import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONUser;
41  import org.apache.syncope.core.spring.security.SecurityProperties;
42  
43  public class JPAJSONUserDAO extends JPAUserDAO {
44  
45      protected final JPAJSONAnyDAO anyDAO;
46  
47      public JPAJSONUserDAO(
48              final AnyUtilsFactory anyUtilsFactory,
49              final PlainSchemaDAO plainSchemaDAO,
50              final DerSchemaDAO derSchemaDAO,
51              final DynRealmDAO dynRealmDAO,
52              final RoleDAO roleDAO,
53              final AccessTokenDAO accessTokenDAO,
54              final GroupDAO groupDAO,
55              final DelegationDAO delegationDAO,
56              final FIQLQueryDAO fiqlQueryDAO,
57              final SecurityProperties securityProperties,
58              final JPAJSONAnyDAO anyDAO) {
59  
60          super(anyUtilsFactory,
61                  plainSchemaDAO,
62                  derSchemaDAO,
63                  dynRealmDAO,
64                  roleDAO,
65                  accessTokenDAO,
66                  groupDAO,
67                  delegationDAO,
68                  fiqlQueryDAO,
69                  securityProperties);
70          this.anyDAO = anyDAO;
71      }
72  
73      @Override
74      public List<User> findByPlainAttrValue(
75              final PlainSchema schema,
76              final PlainAttrValue attrValue,
77              final boolean ignoreCaseMatch) {
78  
79          return anyDAO.findByPlainAttrValue(
80                  JPAJSONUser.TABLE, anyUtils(), schema, attrValue, ignoreCaseMatch);
81      }
82  
83      @Override
84      public Optional<User> findByPlainAttrUniqueValue(
85              final PlainSchema schema,
86              final PlainAttrUniqueValue attrUniqueValue,
87              final boolean ignoreCaseMatch) {
88  
89          return anyDAO.findByPlainAttrUniqueValue(
90                  JPAJSONUser.TABLE, anyUtils(), schema, attrUniqueValue, ignoreCaseMatch);
91      }
92  
93      @Override
94      public List<User> findByDerAttrValue(
95              final DerSchema schema,
96              final String value,
97              final boolean ignoreCaseMatch) {
98  
99          return anyDAO.findByDerAttrValue(JPAJSONUser.TABLE, anyUtils(), schema, value, ignoreCaseMatch);
100     }
101 
102     @Override
103     protected Pair<User, Pair<Set<String>, Set<String>>> doSave(final User user) {
104         entityManager().flush();
105         User merged = entityManager().merge(user);
106 
107         // ensure that entity listeners are invoked at this point
108         entityManager().flush();
109 
110         roleDAO.refreshDynMemberships(merged);
111         Pair<Set<String>, Set<String>> dynGroupMembs = groupDAO.refreshDynMemberships(merged);
112         dynRealmDAO.refreshDynMemberships(merged);
113 
114         return Pair.of(merged, dynGroupMembs);
115     }
116 
117     @Override
118     public User save(final User user) {
119         anyDAO.checkBeforeSave(JPAJSONUser.TABLE, anyUtils(), user);
120         return super.save(user);
121     }
122 
123     @Override
124     public Pair<Set<String>, Set<String>> saveAndGetDynGroupMembs(final User user) {
125         anyDAO.checkBeforeSave(JPAJSONUser.TABLE, anyUtils(), user);
126         return super.saveAndGetDynGroupMembs(user);
127     }
128 }