Class SecurityService


  • public final class SecurityService
    extends java.lang.Object
    This class provides a security service to register and check user authentication
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getAccessControledTemplate()
      Returns the access controled template
      java.lang.String getAccessDeniedTemplate()
      Returns the access denied template
      LuteceAuthentication getAuthenticationService()
      Gets the actual authentication implementation
      java.lang.String getDoLoginUrl()
      Returns the DoLogin URL of the Authentication Service
      java.lang.String getDoLogoutUrl()
      Returns the DoLogout URL of the Authentication Service
      static SecurityService getInstance()
      Get the unique instance of the Security Service
      java.lang.String getLoginPageUrl()
      Returns the Login page URL of the Authentication Service
      java.lang.String getLostPasswordPageUrl()
      Returns the lost password URL of the Authentication Service
      java.lang.String getNewAccountPageUrl()
      Returns the new account page URL of the Authentication Service
      LuteceUser getRegisteredUser​(javax.servlet.http.HttpServletRequest request)
      Gets the Lutece user registered in the Http session
      LuteceUser getRemoteUser​(javax.servlet.http.HttpServletRequest request)
      Gets the LuteceUser attached to the current Http session
      java.lang.String[] getRolesByUser​(LuteceUser user)
      get all roles for this user : - user's roles - user's groups roles
      LuteceUser getUser​(java.lang.String strUserLogin)
      Returns user managed by the authentication service if this feature is available.
      java.security.Principal getUserPrincipal​(javax.servlet.http.HttpServletRequest request)
      Returns the user's principal
      java.util.Collection<LuteceUser> getUsers()
      Returns all users managed by the authentication service if this feature is available.
      java.lang.String getViewAccountPageUrl()
      Returns the view account page URL of the Authentication Service
      static void init()
      Initialize service
      static boolean isAuthenticationEnable()
      Returns the authentication's activation : enable or disable
      boolean isExternalAuthentication()
      Returns the authentication type : External or Lutece portal based
      boolean isLoginUrl​(javax.servlet.http.HttpServletRequest request)
      Return true if the requested url is equal to LoginUrl
      boolean isMultiAuthenticationSupported()
      true when the service provides multi authentication support
      boolean isPortalAuthenticationRequired()
      Returns whether or not the portal needs authentication
      boolean isUserInAnyRole​(javax.servlet.http.HttpServletRequest request, java.util.List<java.lang.String> listRoles)
      Checks if the user is associated to a at least a role
      boolean isUserInRole​(javax.servlet.http.HttpServletRequest request, java.lang.String strRole)
      Checks if the user is associated to a given role
      void loginUser​(javax.servlet.http.HttpServletRequest request, java.lang.String strUserName, java.lang.String strPassword)
      Checks user's login with the Authentication service.
      void logoutUser​(javax.servlet.http.HttpServletRequest request)
      Logout the user
      void registerUser​(javax.servlet.http.HttpServletRequest request, LuteceUser user)
      Register the user in the Http session
      LuteceUser remoteLoginUser​(javax.servlet.http.HttpServletRequest request, java.lang.String strUserName, java.lang.String strPassword)
      Checks user's login with the Authentication service.
      void unregisterUser​(javax.servlet.http.HttpServletRequest request)
      Unregister the user in the Http session
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 java.security.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,
                                    java.lang.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,
                                       java.util.List<java.lang.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 java.lang.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,
                              java.lang.String strUserName,
                              java.lang.String strPassword)
                       throws javax.security.auth.login.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:
        javax.security.auth.login.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 java.lang.String getLoginPageUrl()
        Returns the Login page URL of the Authentication Service
        Returns:
        The URL
      • getDoLoginUrl

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

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

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

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

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

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

        public java.lang.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,
                                          java.lang.String strUserName,
                                          java.lang.String strPassword)
                                   throws javax.security.auth.login.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:
        javax.security.auth.login.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 java.util.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​(java.lang.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.