Class SecurityService


  • public final class SecurityService
    extends Object
    This class provides a security service to register and check user authentication
    • Method Detail

      • getInstance

        public static SecurityService getInstance()
        Get the unique instance of the Security Service
        Returns:
        The instance
      • isAuthenticationEnable

        public static boolean isAuthenticationEnable()
        Returns the authentication's activation : enable or disable
        Returns:
        true if the authentication is active, false otherwise
      • getRemoteUser

        public LuteceUser getRemoteUser​(javax.servlet.http.HttpServletRequest request)
                                 throws UserNotSignedException
        Gets the LuteceUser attached to the current Http session
        Parameters:
        request - The Http request
        Returns:
        A LuteceUser object if found
        Throws:
        UserNotSignedException - If there is no current user
      • getUserPrincipal

        public Principal getUserPrincipal​(javax.servlet.http.HttpServletRequest request)
                                   throws UserNotSignedException
        Returns the user's principal
        Parameters:
        request - The HTTP request
        Returns:
        The user's principal
        Throws:
        UserNotSignedException - The UserNotSignedException
      • isUserInRole

        public boolean isUserInRole​(javax.servlet.http.HttpServletRequest request,
                                    String strRole)
        Checks if the user is associated to a given role
        Parameters:
        request - The Http request
        strRole - The Role name
        Returns:
        Returns true if the user is associated to the given role
      • isUserInAnyRole

        public boolean isUserInAnyRole​(javax.servlet.http.HttpServletRequest request,
                                       List<String> listRoles)
        Checks if the user is associated to a at least a role
        Parameters:
        request - The Http request
        listRoles - The Role list
        Returns:
        Returns true if the user is associated to any role
      • getRolesByUser

        public String[] getRolesByUser​(LuteceUser user)
        get all roles for this user : - user's roles - user's groups roles
        Parameters:
        user - The user
        Returns:
        Array of roles
      • loginUser

        public void loginUser​(javax.servlet.http.HttpServletRequest request,
                              String strUserName,
                              String strPassword)
                       throws LoginException,
                              LoginRedirectException
        Checks user's login with the Authentication service.
        Parameters:
        request - The Http request
        strUserName - The user's login
        strPassword - The user's password
        Throws:
        LoginException - The LoginException
        LoginRedirectException - if redirect exception
      • logoutUser

        public void logoutUser​(javax.servlet.http.HttpServletRequest request)
        Logout the user
        Parameters:
        request - The HTTP request
      • registerUser

        public void registerUser​(javax.servlet.http.HttpServletRequest request,
                                 LuteceUser user)
        Register the user in the Http session
        Parameters:
        request - The Http request
        user - The current user
      • unregisterUser

        public void unregisterUser​(javax.servlet.http.HttpServletRequest request)
        Unregister the user in the Http session
        Parameters:
        request - The Http request
      • getRegisteredUser

        public LuteceUser getRegisteredUser​(javax.servlet.http.HttpServletRequest request)
        Gets the Lutece user registered in the Http session
        Parameters:
        request - The HTTP request
        Returns:
        The User registered or null if the user has not been registered
      • isExternalAuthentication

        public boolean isExternalAuthentication()
        Returns the authentication type : External or Lutece portal based
        Returns:
        true if the user is already authenticated or false if it needs to login.
      • getLoginPageUrl

        public String getLoginPageUrl()
        Returns the Login page URL of the Authentication Service
        Returns:
        The URL
      • getDoLoginUrl

        public String getDoLoginUrl()
        Returns the DoLogin URL of the Authentication Service
        Returns:
        The URL
      • getDoLogoutUrl

        public String getDoLogoutUrl()
        Returns the DoLogout URL of the Authentication Service
        Returns:
        The URL
      • getNewAccountPageUrl

        public String getNewAccountPageUrl()
        Returns the new account page URL of the Authentication Service
        Returns:
        The URL
      • getViewAccountPageUrl

        public String getViewAccountPageUrl()
        Returns the view account page URL of the Authentication Service
        Returns:
        The URL
      • getLostPasswordPageUrl

        public String getLostPasswordPageUrl()
        Returns the lost password URL of the Authentication Service
        Returns:
        The URL
      • getAccessDeniedTemplate

        public String getAccessDeniedTemplate()
        Returns the access denied template
        Returns:
        The template
      • getAccessControledTemplate

        public String getAccessControledTemplate()
        Returns the access controled template
        Returns:
        The template
      • isPortalAuthenticationRequired

        public boolean isPortalAuthenticationRequired()
        Returns whether or not the portal needs authentication
        Returns:
        true if the access needs authentication, otherwise
        Since:
        1.3.1
      • remoteLoginUser

        public LuteceUser remoteLoginUser​(javax.servlet.http.HttpServletRequest request,
                                          String strUserName,
                                          String strPassword)
                                   throws LoginException,
                                          LoginRedirectException
        Checks user's login with the Authentication service. Used during remote authentication validation We don't have to put user informations in session, since it is only used in external applications
        Parameters:
        request - the request
        strUserName - The user's login
        strPassword - The user's password
        Returns:
        user's informations
        Throws:
        LoginException - The LoginException
        LoginRedirectException - The redirect exception
      • isLoginUrl

        public boolean isLoginUrl​(javax.servlet.http.HttpServletRequest request)
        Return true if the requested url is equal to LoginUrl
        Parameters:
        request - The Http servlet request
        Returns:
        True if the requested url is equal to LoginUrl, false else.
      • getUsers

        public Collection<LuteceUser> getUsers()
        Returns all users managed by the authentication service if this feature is available.
        Returns:
        A collection of Lutece users or null if the service doesn't provide a users list
      • getUser

        public LuteceUser getUser​(String strUserLogin)
        Returns user managed by the authentication service if this feature is available.
        Parameters:
        strUserLogin - the user login
        Returns:
        A Lutece user or null if the service doesn't provide LuteceUser
      • isMultiAuthenticationSupported

        public boolean isMultiAuthenticationSupported()
        true when the service provides multi authentication support
        Returns:
        true if multi authentication is supported, false otherwise.