View Javadoc
1   /*
2    * Copyright (c) 2002-2023, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.adminauthenticationoauth2.service;
35  
36  import fr.paris.lutece.plugins.adminauthenticationoauth2.business.authentication.AdminOauth2Authentication;
37  import fr.paris.lutece.plugins.oauth2.business.AuthClientConf;
38  import fr.paris.lutece.plugins.oauth2.business.AuthServerConf;
39  import fr.paris.lutece.portal.service.spring.SpringContextService;
40  import fr.paris.lutece.portal.service.util.AppPropertiesService;
41  
42  /**
43   * Constants
44   */
45  public final class Oauth2Utils
46  {
47      // Beans properties names
48      public static final String AUTHENTICATION_BEAN_NAME = "adminauthenticationoauth2.authentication";
49      private static final String BEAN_AUTH_SERVER_CONF = "oauth2.server";
50      private static final String BEAN_AUTH_CLIENT_CONF = "oauth2.client";
51  
52  
53      // OAuth2 properties names
54      public static final String PROPERTY_USE_PROMPT_NONE = "adminauthenticationoauth2.usePromptNone";
55      public static final String PROPERTY_USE_PROMPT_NONE_WHITE_LISTING_URLS = "adminauthenticationoauth2.usePromptNoneWhiteListingUrls";
56      public static final String PROPERTY_USE_PROMPT_NONE_WHITE_LISTING_HEADERS = "adminauthenticationoauth2.usePromptNoneWhiteListingHeaders";
57      public static final String PROPERTY_VALIDATE_REFRESH_TOKEN = "adminauthenticationoauth2.validateRefreshToken";
58      public static final String PROPERTY_USER_KEY_NAME = "adminauthenticationoauth2.attributeKeyUsername";
59      public static final String PROPERTY_IDENTITY_ATTRIBUTE_KEY = "adminauthenticationoauth2.attributeIdentityKey";
60      public static final String PROPERTY_USER_MAPPING_ATTRIBUTES = "adminauthenticationoauth2.userMappingAttributes";
61      public static final String PROPERTY_EMAIL_ATTRIBUTE_KEY = "adminauthenticationoauth2.attribute.user.business-info.online.email";
62      public static final String PROPERTY_LASTNAME_ATTRIBUTE_KEY = "adminauthenticationoauth2.attribute.user.name.family";
63      public static final String PROPERTY_FIRSTNAME_ATTRIBUTE_KEY = "adminauthenticationoauth2.attribute.user.name.given";
64      public static final String CONSTANT_LUTECE_USER_PROPERTIES_PATH = "adminauthenticationoauth2.attribute";
65  
66      // urls properties names
67      public static final String OAUTH2_CHANGE_PASSWORD_URL = "adminauthenticationoauth2.url.changePassword";
68      public static final String OAUTH2_NEW_ACCOUNT_URL = "adminauthenticationoauth2.url.newAccount";
69      public static final String OAUTH2_VIEW_ACCOUNT_URL = "adminauthenticationoauth2.url.viewAccount";
70      public static final String OAUTH2_LOST_PASSWORD_URL = "adminauthenticationoauth2.url.lostPassword";
71      public static final String OAUTH2_LOST_LOGIN_URL = "adminauthenticationoauth2.url.lostLogin";
72  
73      // Other properties names
74      public static final String PROPERTY_AUTH_SERVICE_NAME = "adminauthenticationoauth2.service.name";
75  
76      // Simple constants
77      public static final String AUTH_DATA_CLIENT_NAME = "authData";
78      public static final String CONSTANT_ACTION_DOLOGOUT = "doLogout";
79      public static final String CONSTANT_BO = "BO";
80      public static final String URL_INTERROGATIVE = "?";
81      public static final String URL_AMPERSAND = "&";
82      public static final String URL_EQUAL = "=";
83      public static final String URL_STAR = "*";
84      public static final String SEPARATOR = ",";
85      public static final String ERROR_TYPE_LOGIN_REQUIRED = "login_required";
86      public static final String REINIT_ERROR_LOGIN = "reinit_error_login";
87      public static final String SESSION_ERROR_LOGIN = "session_error_login";
88      public static final String PARAM_ERROR_LOGIN = "error_login";
89      public static final String PARAMETER_UID = AppPropertiesService.getProperty(PROPERTY_USER_KEY_NAME,"uid");
90  
91  
92      // Beans
93      private static AuthServerConf _authServerConf;
94      private static AuthClientConf _authClientConf;
95      private static AdminOauth2Authentication _authService;
96  
97      /** Private constructor */
98      private Oauth2Utils( )
99      {
100     }
101 
102     public static AuthServerConf getAuthServerConf( )
103     {
104         if ( _authServerConf == null )
105         {
106             _authServerConf = SpringContextService.getBean( BEAN_AUTH_SERVER_CONF );
107         }
108         return _authServerConf;
109     }
110 
111     public static AuthClientConf getAuthClientConf( )
112     {
113         if ( _authClientConf == null )
114         {
115             _authClientConf = SpringContextService.getBean( BEAN_AUTH_CLIENT_CONF );
116         }
117         return _authClientConf;
118     }
119 
120     static AdminOauth2Authentication getAuthService()
121     {
122         if ( _authService == null )
123         {
124             _authService = SpringContextService.getBean( AUTHENTICATION_BEAN_NAME );
125         }
126         return _authService;
127     }
128 }