if (session != null) {
SecurityContext context = (SecurityContext) session.getAttribute("SPRING_SECURITY_CONTEXT");
if (context != null) {
if (context.getAuthentication() != null && context.getAuthentication().getPrincipal() != null && context.getAuthentication().getPrincipal() instanceof User) {
User user = userService.getUserFromSecurityContext();
String servletPath = request.getServletPath();
if (!servletPath.startsWith("/auth") && !servletPath.startsWith("/resources") && !servletPath.startsWith("/static") && !servletPath.startsWith("/contacts") && user != null && !servletPath.startsWith("/getSystemNotifications")) {
boolean skipValidation = false;
if (user.isPasswordExpired() && !servletPath.startsWith("/profile/changePassword") && !servletPath.startsWith("/profile/resetPassword") && !servletPath.startsWith("/auth/forgotPassword")) {
response.sendRedirect(request.getContextPath() + "/profile/changePassword");
skipValidation = true;
redirect = true;
} else if (user.isPasswordExpired() && (servletPath.startsWith("/profile/changePassword") || servletPath.startsWith("/profile/resetPassword") || servletPath.startsWith("/auth/forgotPassword"))) {
skipValidation = true;
}
if (!user.isActivated() && !servletPath.startsWith("/activate") && !skipValidation) {
response.sendRedirect(request.getContextPath() + "/activate");
redirect = true;
}
}
}