Package com.groiss.org
Class AuthUtil
java.lang.Object
com.groiss.org.AuthUtil
Utilities for writing an authorization class.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addNodeCookie
(HttpServletResponse res, String rn) static String
authorizeBrowser
(HttpServletRequest req, HttpServletResponse res, User u) This function can be called from the client to instantiate a session.static void
authorizeBrowser
(HttpServletRequest req, HttpServletResponse res, User u, String nextUrl) This function can be called from the client to instantiate a session and send the session cookie to the browser.static void
checkSysadmPasswd
(String passwd) static Principal
Checks the user.static Principal
Checks the user.static void
static boolean
equalUserIds
(String firstId, String secondId) Checks if both id strings are equal respecting the configuration value for case sensitive user Id checkingstatic String
-
Method Details
-
authorizeBrowser
public static String authorizeBrowser(HttpServletRequest req, HttpServletResponse res, User u) throws IOException This function can be called from the client to instantiate a session. No cookie is being send back. The caller is responsible for dispatching the correct request. This can be accomplished via req.getRequestDispatcher(path).forward(req,res);- Parameters:
req
- the HttpServletRequestres
- the HttpServletResponseu
- the user- Returns:
- null, if no error condition occurred, or a string containing the error message which should be written back to the client; via res.getWriter().println(result);
- Throws:
IOException
-
authorizeBrowser
public static void authorizeBrowser(HttpServletRequest req, HttpServletResponse res, User u, String nextUrl) throws IOException This function can be called from the client to instantiate a session and send the session cookie to the browser.- Parameters:
req
- the HttpServletRequestres
- the HttpServletResponseu
- the usernextUrl
- the url for redirection When referer check is enabled (ep.check.http.referer), nextUrl must be also be in ep.check.http.referer.exempt, or annotated viaEntryPoint
.- Throws:
IOException
-
checkUser
Checks the user. Compares the password and checks whether the user is active. If one of the check fails an Exception is thrown. If the password is not correct an unsuccessful login will be recorded.- Parameters:
userId
- the id of the userpasswd
- the passwdclientAddr
- the ip address of the client- Returns:
- the user with the given id, if found.
- Throws:
Exception
-
checkUser
public static Principal checkUser(String userId, String passwd, String clientAddr, boolean ignoreUnsuccessfulLogin) throws Exception Checks the user. Compares the password and checks whether the user is active. If one of the check fails an Exception is thrown. If the password is not correct an unsuccessful login will be recorded but only if parameter ignoreUnsuccessfulLogin ist not true.- Parameters:
userId
- the id of the userpasswd
- the passwdclientAddr
- the ip address of the clientignoreUnsuccessfulLogin
- if true unsuccessful logins will not be recorded- Returns:
- the user with the given id, if found.
- Throws:
Exception
-
checkSysadmPasswd
-
equalUserIds
Checks if both id strings are equal respecting the configuration value for case sensitive user Id checking- Parameters:
firstId
- a user Id stringsecondId
- a user Id string to compare with firstId- Returns:
- true if the ids are considered as equal, false otherwise
-
getNodeCookieName
-
addNodeCookie
-
deleteNodeCookie
-