Commit 04b03863 by zhix

深圳地铁单点新增用户权限初始化和登录日志信息修改

parent d46d91f3
......@@ -134,6 +134,13 @@ public class LoginManagement {
toAdd.put("name", userDetailByTokenInfo.get("unique_name"));
toAdd.put("password", "37fa265330ad83eaa879efb1e2db6380896cf639");
authService.addUser(toAdd);
log.info("新增单点用户成功:{}", userDetailByTokenInfo.get("given_name"));
//初始权限
List<Map<String, Object>> newUser = authService.getUserByName(userDetailByTokenInfo.get("unique_name"));
List<Long> userIds = new ArrayList<>();
userIds.add(Long.parseLong(newUser.get(0).get("id").toString()));
authService.dataRoles(oauth2Properties.getInitRoleId(),userIds);
log.info("初始化权限id:{},新增用户{}权限初始化成功。", oauth2Properties.getInitRoleId(), userDetailByTokenInfo.get("given_name"));
}
UserDetails userDetails = customizedUserDetailService.loadUserByUsername(userDetailByTokenInfo.get("unique_name"));
UsernamePasswordAuthenticationToken authentication =
......
......@@ -26,14 +26,17 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
clearAuthenticationAttributes(request);
String returnStatus = "ok";
//check if allow root login
String log = "登录成功。";
LogManager.logInfo(LogConstants.CTX_API, log);
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
String userNameWithIdAttached = userDetails.getUsername();
if (userNameWithIdAttached.split(":")[0].equalsIgnoreCase("root")
&& !rootAllowLogin)
returnStatus = "root not allow login";
if (!userNameWithIdAttached.split(":")[0].equalsIgnoreCase("root")){
String log = "登录了系统。";
LogManager.logInfo(LogConstants.CTX_API, log);
}
PrintWriter writer = response.getWriter();
writer.write(returnStatus);
writer.flush();
......
......@@ -6,6 +6,7 @@ import com.keymobile.login.oauth2.Oauth2Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;
......@@ -25,8 +26,12 @@ public class RESTLogoutSuccessHandler implements LogoutSuccessHandler {
HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
// response.sendRedirect(oauth2Properties.getAuthorizeLogoutUri());
String log = "退出成功。";
LogManager.logInfo(LogConstants.CTX_API, log);
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
String userNameWithIdAttached = userDetails.getUsername();
if (!userNameWithIdAttached.split(":")[0].equalsIgnoreCase("root")){
String log = "退出了系统";
LogManager.logInfo(LogConstants.CTX_API, log);
}
response.setStatus(HttpStatus.OK.value());
response.getWriter().flush();
}
......
......@@ -27,6 +27,8 @@ public class Oauth2Properties {
private String authorizationLoginOutUri;
private Long initRoleId;
public void setPostLogoutRedirectUri(String postLogoutRedirectUri) {
this.postLogoutRedirectUri = postLogoutRedirectUri;
}
......@@ -107,6 +109,14 @@ public class Oauth2Properties {
this.userInfoUri = userInfoUri;
}
public Long getInitRoleId() {
return initRoleId;
}
public void setInitRoleId(Long initRoleId) {
this.initRoleId = initRoleId;
}
public String getAuthorizeLogoutUri() {
String authorizeUri = getAuthorizationLoginOutUri();
String clientId = getClientId();
......
......@@ -15,5 +15,8 @@ public interface AuthService {
@PostMapping(value = "/users")
Map<String, Object> addUser(@RequestBody Map<String, Object> user);
@PostMapping(value = "/dataRoles/{dataRoleId}/users/sync")
Map<String, Object> dataRoles(@PathVariable(value = "dataRoleId") Long roleId, @RequestParam(value = "userIds") List<Long> userIds);
}
......@@ -57,6 +57,7 @@ security:
authorization-success-redirect-uri: http://10.37.54.154:8080/center-home/menu/index #认证成功后跳转地址
post-login-redirect-uri: http://10.37.54.154:8080/api/auth/ssologin #登录后回调系统的登录接口
post-logout-redirect_uri: http://10.37.54.154:8080/center-home/view/login #退出后回调系统的注销接口
init-role-id: 7
feign:
authUser: root
......
......@@ -30,7 +30,6 @@
</logger>
<root level="INFO">
<appender-ref ref="logstash" />
<appender-ref ref="stdout" />
</root>
......
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