Class SecurityService
- java.lang.Object
-
- fr.paris.lutece.portal.service.security.SecurityService
-
public final class SecurityService extends java.lang.ObjectThis 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.StringgetAccessControledTemplate()Returns the access controled templatejava.lang.StringgetAccessDeniedTemplate()Returns the access denied templateLuteceAuthenticationgetAuthenticationService()Gets the actual authentication implementationjava.lang.StringgetDoLoginUrl()Returns the DoLogin URL of the Authentication Servicejava.lang.StringgetDoLogoutUrl()Returns the DoLogout URL of the Authentication Servicestatic SecurityServicegetInstance()Get the unique instance of the Security Servicejava.lang.StringgetLoginPageUrl()Returns the Login page URL of the Authentication Servicejava.lang.StringgetLostPasswordPageUrl()Returns the lost password URL of the Authentication Servicejava.lang.StringgetNewAccountPageUrl()Returns the new account page URL of the Authentication ServiceLuteceUsergetRegisteredUser(javax.servlet.http.HttpServletRequest request)Gets the Lutece user registered in the Http sessionLuteceUsergetRemoteUser(javax.servlet.http.HttpServletRequest request)Gets the LuteceUser attached to the current Http sessionjava.lang.String[]getRolesByUser(LuteceUser user)get all roles for this user : - user's roles - user's groups rolesLuteceUsergetUser(java.lang.String strUserLogin)Returns user managed by the authentication service if this feature is available.java.security.PrincipalgetUserPrincipal(javax.servlet.http.HttpServletRequest request)Returns the user's principaljava.util.Collection<LuteceUser>getUsers()Returns all users managed by the authentication service if this feature is available.java.lang.StringgetViewAccountPageUrl()Returns the view account page URL of the Authentication Servicestatic voidinit()Initialize servicestatic booleanisAuthenticationEnable()Returns the authentication's activation : enable or disablebooleanisExternalAuthentication()Returns the authentication type : External or Lutece portal basedbooleanisLoginUrl(javax.servlet.http.HttpServletRequest request)Return true if the requested url is equal to LoginUrlbooleanisMultiAuthenticationSupported()true when the service provides multi authentication supportbooleanisPortalAuthenticationRequired()Returns whether or not the portal needs authenticationbooleanisUserInAnyRole(javax.servlet.http.HttpServletRequest request, java.util.List<java.lang.String> listRoles)Checks if the user is associated to a at least a rolebooleanisUserInRole(javax.servlet.http.HttpServletRequest request, java.lang.String strRole)Checks if the user is associated to a given rolevoidloginUser(javax.servlet.http.HttpServletRequest request, java.lang.String strUserName, java.lang.String strPassword)Checks user's login with the Authentication service.voidlogoutUser(javax.servlet.http.HttpServletRequest request)Logout the uservoidregisterUser(javax.servlet.http.HttpServletRequest request, LuteceUser user)Register the user in the Http sessionLuteceUserremoteLoginUser(javax.servlet.http.HttpServletRequest request, java.lang.String strUserName, java.lang.String strPassword)Checks user's login with the Authentication service.voidunregisterUser(javax.servlet.http.HttpServletRequest request)Unregister the user in the Http session
-
-
-
Method Detail
-
init
public static void init() throws LuteceInitExceptionInitialize service- Throws:
LuteceInitException- if an error occurs
-
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 UserNotSignedExceptionReturns 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 requeststrRole- 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 requestlistRoles- 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, LoginRedirectExceptionChecks user's login with the Authentication service.- Parameters:
request- The Http requeststrUserName- The user's loginstrPassword- The user's password- Throws:
javax.security.auth.login.LoginException- The LoginExceptionLoginRedirectException- 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 requestuser- 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 requeststrUserName- The user's loginstrPassword- The user's password- Returns:
- user's informations
- Throws:
javax.security.auth.login.LoginException- The LoginExceptionLoginRedirectException- 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:
trueif multi authentication is supported,falseotherwise.
-
getAuthenticationService
public LuteceAuthentication getAuthenticationService()
Gets the actual authentication implementation- Returns:
LuteceAuthenticationimplementation
-
-