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.ui.commons;
20  
21  import java.util.List;
22  import java.util.Locale;
23  import java.util.concurrent.Callable;
24  import java.util.concurrent.Future;
25  import org.apache.syncope.client.lib.SyncopeAnonymousClient;
26  import org.apache.wicket.model.ResourceModel;
27  
28  public interface BaseSession {
29  
30      enum Error {
31          SESSION_EXPIRED("error.session.expired", "Session expired: please login again"),
32          AUTHORIZATION("error.authorization", "Insufficient access rights when performing the requested operation"),
33          REST("error.rest", "There was an error while contacting the Core server");
34  
35          private final String key;
36  
37          private final String fallback;
38  
39          Error(final String key, final String fallback) {
40              this.key = key;
41              this.fallback = fallback;
42          }
43  
44          public String message() {
45              return new ResourceModel(key, fallback).getObject();
46          }
47      }
48  
49      void setDomain(String domain);
50  
51      String getDomain();
52  
53      String getJWT();
54  
55      SyncopeAnonymousClient getAnonymousClient();
56  
57      <T> T getAnonymousService(Class<T> serviceClass);
58  
59      <T> T getService(Class<T> serviceClass);
60  
61      <T> T getService(String etag, Class<T> serviceClass);
62  
63      <T> void resetClient(Class<T> service);
64  
65      DateOps.Format getDateFormat();
66  
67      /**
68       * Extract and localize (if translation available) the actual message from the given exception; then, report it
69       * via {@link org.apache.wicket.Session#error(java.io.Serializable)}.
70       *
71       * @see org.apache.syncope.client.lib.RestClientExceptionMapper
72       *
73       * @param e raised exception
74       */
75      void onException(Exception e);
76  
77      <T> Future<T> execute(Callable<T> command);
78  
79      default List<Locale> getSupportedLocales() {
80          return List.of(
81                  Locale.ENGLISH,
82                  Locale.CANADA_FRENCH,
83                  Locale.ITALIAN,
84                  Locale.JAPANESE,
85                  new Locale("pt", "BR"),
86                  new Locale("ru"));
87      }
88  }