Search in sources :

Example 1 with RestAuthenticationDetails

use of org.thingsboard.server.service.security.auth.rest.RestAuthenticationDetails in project thingsboard by thingsboard.

the class AuthController method logLogoutAction.

private void logLogoutAction(HttpServletRequest request) throws ThingsboardException {
    try {
        SecurityUser user = getCurrentUser();
        RestAuthenticationDetails details = new RestAuthenticationDetails(request);
        String clientAddress = details.getClientAddress();
        String browser = "Unknown";
        String os = "Unknown";
        String device = "Unknown";
        if (details.getUserAgent() != null) {
            Client userAgent = details.getUserAgent();
            if (userAgent.userAgent != null) {
                browser = userAgent.userAgent.family;
                if (userAgent.userAgent.major != null) {
                    browser += " " + userAgent.userAgent.major;
                    if (userAgent.userAgent.minor != null) {
                        browser += "." + userAgent.userAgent.minor;
                        if (userAgent.userAgent.patch != null) {
                            browser += "." + userAgent.userAgent.patch;
                        }
                    }
                }
            }
            if (userAgent.os != null) {
                os = userAgent.os.family;
                if (userAgent.os.major != null) {
                    os += " " + userAgent.os.major;
                    if (userAgent.os.minor != null) {
                        os += "." + userAgent.os.minor;
                        if (userAgent.os.patch != null) {
                            os += "." + userAgent.os.patch;
                            if (userAgent.os.patchMinor != null) {
                                os += "." + userAgent.os.patchMinor;
                            }
                        }
                    }
                }
            }
            if (userAgent.device != null) {
                device = userAgent.device.family;
            }
        }
        auditLogService.logEntityAction(user.getTenantId(), user.getCustomerId(), user.getId(), user.getName(), user.getId(), null, ActionType.LOGOUT, null, clientAddress, browser, os, device);
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) RestAuthenticationDetails(org.thingsboard.server.service.security.auth.rest.RestAuthenticationDetails) Client(ua_parser.Client) URISyntaxException(java.net.URISyntaxException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException)

Aggregations

URISyntaxException (java.net.URISyntaxException)1 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)1 RestAuthenticationDetails (org.thingsboard.server.service.security.auth.rest.RestAuthenticationDetails)1 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)1 Client (ua_parser.Client)1