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.rest.cxf.service.wa;
20  
21  import java.time.LocalDateTime;
22  import java.util.List;
23  import org.apache.syncope.common.lib.to.PagedResult;
24  import org.apache.syncope.common.lib.wa.GoogleMfaAuthToken;
25  import org.apache.syncope.common.rest.api.service.wa.GoogleMfaAuthTokenService;
26  import org.apache.syncope.core.logic.wa.GoogleMfaAuthTokenLogic;
27  import org.apache.syncope.core.rest.cxf.service.AbstractService;
28  import org.springframework.stereotype.Service;
29  
30  @Service
31  public class GoogleMfaAuthTokenServiceImpl extends AbstractService implements GoogleMfaAuthTokenService {
32  
33      protected final GoogleMfaAuthTokenLogic logic;
34  
35      public GoogleMfaAuthTokenServiceImpl(final GoogleMfaAuthTokenLogic logic) {
36          this.logic = logic;
37      }
38  
39      @Override
40      public void delete(final LocalDateTime expirationDate) {
41          if (expirationDate == null) {
42              logic.deleteAll();
43          } else {
44              logic.delete(expirationDate);
45          }
46      }
47  
48      @Override
49      public void delete(final String owner, final int otp) {
50          logic.delete(owner, otp);
51      }
52  
53      @Override
54      public void delete(final String owner) {
55          logic.delete(owner);
56      }
57  
58      @Override
59      public void delete(final int otp) {
60          logic.delete(otp);
61      }
62  
63      @Override
64      public void store(final String owner, final GoogleMfaAuthToken token) {
65          logic.store(owner, token);
66      }
67  
68      @Override
69      public GoogleMfaAuthToken read(final String owner, final int otp) {
70          return logic.read(owner, otp);
71      }
72  
73      private PagedResult<GoogleMfaAuthToken> build(final List<GoogleMfaAuthToken> read) {
74          PagedResult<GoogleMfaAuthToken> result = new PagedResult<>();
75          result.setPage(1);
76          result.setSize(read.size());
77          result.setTotalCount(read.size());
78          result.getResult().addAll(read);
79          return result;
80      }
81  
82      @Override
83      public PagedResult<GoogleMfaAuthToken> read(final String owner) {
84          return build(logic.read(owner));
85      }
86  
87      @Override
88      public PagedResult<GoogleMfaAuthToken> list() {
89          return build(logic.list());
90      }
91  }