Commit be9763ef by mahx

增加登录和退出日志

parent 73904261
package com.keymobile.login.conf; package com.keymobile.login.conf;
import com.keymobile.login.logging.LogConstants;
import com.keymobile.login.logging.LogManager;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
...@@ -27,6 +29,7 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc ...@@ -27,6 +29,7 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
UserDetails userDetails = (UserDetails) authentication.getPrincipal(); UserDetails userDetails = (UserDetails) authentication.getPrincipal();
String userNameWithIdAttached = userDetails.getUsername(); String userNameWithIdAttached = userDetails.getUsername();
LogManager.logInfo(LogConstants.CTX_API, userNameWithIdAttached + " 登录了系统");
if (userNameWithIdAttached.split(":")[0].equalsIgnoreCase("root") if (userNameWithIdAttached.split(":")[0].equalsIgnoreCase("root")
&& !rootAllowLogin) && !rootAllowLogin)
returnStatus = "root not allow login"; returnStatus = "root not allow login";
......
package com.keymobile.login.conf; package com.keymobile.login.conf;
import com.keymobile.auth.common.security.GrantedAuthHelper;
import com.keymobile.login.logging.LogConstants;
import com.keymobile.login.logging.LogManager;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -17,6 +22,11 @@ public class RESTLogoutSuccessHandler implements LogoutSuccessHandler { ...@@ -17,6 +22,11 @@ public class RESTLogoutSuccessHandler implements LogoutSuccessHandler {
public void onLogoutSuccess(HttpServletRequest request, public void onLogoutSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication) HttpServletResponse response, Authentication authentication)
throws IOException, ServletException { throws IOException, ServletException {
if (authentication != null) {
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
String userNameWithIdAttached = userDetails != null ? userDetails.getUsername() : authentication.getName();
LogManager.logInfo(LogConstants.CTX_API, userNameWithIdAttached + " 退出了系统");
}
response.setStatus(HttpStatus.OK.value()); response.setStatus(HttpStatus.OK.value());
response.getWriter().flush(); response.getWriter().flush();
} }
......
...@@ -2,4 +2,6 @@ package com.keymobile.login.logging; ...@@ -2,4 +2,6 @@ package com.keymobile.login.logging;
public interface LogConstants { public interface LogConstants {
String CTX_API = "sso.API";
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment