Java
Getting started
The jar file can be found in the tcell-jvmagent-*.tar.gz
or tcell-jvmagent-*.zip
as tcellagent-hooks-*.jar
Login Event
In order to send a login event, at the time of login, once you've determined if the login is successful or not, you should call the method:
1io.tcellagent.hooks.v1.login.LoginReporter.registerLoginEvent()
Settings
In some cases, tCell will not be able to get your sessionid or userid for http requests. In such cases, you can set them yourself at the earliest point these values are known. This is done by the following methods, respectively:
1io.tcellagent.hooks.v1.TCellSettings.setSessionId(String sid)23io.tcellagent.hooks.v1.TCellSettings.setUserId(String userName).
API Documentation
1public final class io.tcellagent.hooks.v1.login.LoginReporter extends java.lang.Object
1public static void registerLoginEvent(LoginStatus event,2java.lang.String session,3java.lang.String userAgent,4java.lang.String referrer,5java.lang.String remoteAddr,6java.lang.String[] headerKeys,7java.lang.String userId,8java.lang.String documentUri)
1public static void registerLoginEvent(LoginStatus event,2java.lang.String session,3java.lang.String userAgent,4java.lang.String referrer,5java.lang.String remoteAddr,6java.lang.String[] headerKeys,7java.lang.String userId,8java.lang.String documentUri,9java.lang.Boolean userValid)
1public static void registerLoginEvent(LoginStatus event,2java.lang.String session,3java.lang.String userAgent,4java.lang.String referrer,5java.lang.String remoteAddr,6java.lang.String[] headerKeys,7java.lang.String userId,8java.lang.String documentUri,9java.lang.Boolean userValid,10java.lang.String password)
Detailed parameter information is below
Parameter | Details |
---|---|
event | type of event. See LoginStatus |
session | String for the sessionId. See code example below |
userAgent | Value from Http Header. For example, from req.getHeader("User-Agent") |
referrer | Value from Http Header. For example, from req.getHeader("Referer") |
remoteAddr | The IP from the client. (at times could be X-Forwarded-For) |
headerKeys | an array of header keys. For example, from req.getHeaderNames() |
userId | String for the userid being used. |
password | Password of failed/successful login. |
LoginStatus
1java.lang.Object2java.lang.Enum<LoginStatus>3io.tcellagent.hooks.v1.login.LoginStatus45public static final LoginStatus LOGIN_SUCCESS6public static final LoginStatus LOGIN_FAILURE
1public final class io.tcellagent.hooks.v1.TCellSettings23public static void setUserId( String userId )4userId - String value of user id, e.g 'joe.user@customer.com'.56public static void setSessionId( String sessionId )7sessionId - String of sessionId value. Note that this value will be securely hashed before sending to the tCell service.
Example Login
1public class LoginServlet extends HttpServlet {23@Override4protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {5String userId = req.getParameter("customUserIdField");6String password = req.getParameter("customPasswordField");7boolean success = false;8boolean validUser = isUserValid(userId);9if (validUser) {10success = login(userId, password);11}12LoginStatus status = success ? LoginStatus.LOGIN_SUCCESS : LoginStatus.LOGIN_FAILURE;13HttpSession session = req.getSession(false);14String sessionId = session != null ? session.getId() : null;15Enumeration < String > headerNames = req.getHeaderNames();16ArrayList < String > names = new ArrayList < > ();17while (headerNames.hasMoreElements()) {18names.add(headerNames.nextElement());19}20LoginReporter.registerLoginEvent(status,21sessionId,22req.getHeader("User-Agent"),23req.getHeader("Referer"),24req.getRemoteAddr(), // Note: the real client IP may be in a header if using proxy!25names.toArray(new String[0]),26userId,27req.getRequestURI(),28validUser,29password);30resp.setStatus(success ? 200 : 401);31}3233public boolean isUserValid(String userId) {34return "user".equals(userId);35}3637public boolean login(String userId, String password) {38return "user".equals(userId) && "password".equals(password);39}40}
1Example Session Filter23public class MySessionFilter implements Filter {45public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {67...8io.tcellagent.hooks.v1.TCellSettings.setUserId( <User Id> );9io.tcellagent.hooks.v1.TCellSettings.setSessionId( <session ID> );10doFilter(request, response, chain);11}12}
Did this page help you?