use of com.jeeagile.springsecurity.userdetails.AgileUserDetails in project jeeagile by jeeagile.
the class AgileSpringSecurity method userLogin.
@Override
public void userLogin(AgileLoginUser agileLoginUser) {
try {
UsernamePasswordAuthenticationToken passwordAuthenticationToken = new UsernamePasswordAuthenticationToken(agileLoginUser.getUserName(), agileLoginUser.getPassword());
Authentication authentication = authenticationManager.authenticate(passwordAuthenticationToken);
AgileUserDetails agileUserDetails = (AgileUserDetails) authentication.getPrincipal();
if (agileUserDetails != null && AgileStringUtil.isNotEmpty(agileUserDetails.getUsername())) {
String userToken = agileUserDetails.getUserData().getUserToken();
AgileCacheUtil.put(AgileCacheConstants.AGILE_CACHE_SESSION_NAME, userToken, agileUserDetails);
sessionRegistry.registerNewSession(userToken, userToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
}
} catch (AgileBaseException ex) {
throw ex;
} catch (Exception ex) {
if (ex.getCause() instanceof AgileBaseException) {
throw (AgileBaseException) ex.getCause();
} else if (ex instanceof BadCredentialsException) {
throw new AgileAuthException("用户登录密码错误!");
} else {
log.error("Spring Security用户登录认证出现异常", ex);
throw new AgileAuthException("Spring Security用户登录认证出现异常!");
}
}
}
use of com.jeeagile.springsecurity.userdetails.AgileUserDetails in project jeeagile by jeeagile.
the class AgilePermissionEvaluator method checkPermission.
private boolean checkPermission(Authentication authentication, Object permission) {
if (AgileStringUtil.isEmpty(permission)) {
return false;
}
AgileUserDetails agileUserDetails = (AgileUserDetails) authentication.getPrincipal();
AgileBaseUser userData = null;
if (agileUserDetails != null) {
userData = agileUserDetails.getUserData();
}
if (AgileStringUtil.isEmpty(userData) || CollectionUtils.isEmpty(userData.getUserPerm())) {
return false;
}
return userData.getUserPerm().contains("*:*:*") || userData.getUserPerm().contains(permission);
}
use of com.jeeagile.springsecurity.userdetails.AgileUserDetails in project jeeagile by jeeagile.
the class AgileUserTokenFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
String userToken = AgileServletUtil.getUserToken(httpServletRequest);
SecurityContext securityContext = SecurityContextHolder.getContext();
if (AgileStringUtil.isNotEmpty(userToken) && securityContext.getAuthentication() == null) {
AgileUserDetails agileUserDetails = (AgileUserDetails) AgileCacheUtil.get(AgileCacheConstants.AGILE_CACHE_SESSION_NAME, userToken);
if (agileUserDetails != null && AgileStringUtil.isNotEmpty(agileUserDetails.getUsername())) {
AgileCacheUtil.put(AgileCacheConstants.AGILE_CACHE_SESSION_NAME, userToken, agileUserDetails);
SessionInformation sessionInformation = sessionRegistry.getSessionInformation(userToken);
if (sessionInformation == null) {
sessionRegistry.registerNewSession(userToken, userToken);
} else {
sessionRegistry.refreshLastRequest(userToken);
}
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(agileUserDetails, null, agileUserDetails.getAuthorities());
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest));
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
} else {
sessionRegistry.removeSessionInformation(userToken);
}
}
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
use of com.jeeagile.springsecurity.userdetails.AgileUserDetails in project jeeagile by jeeagile.
the class AgileSpringSecurity method getOnlineUserList.
@Override
public List<AgileOnlineUser> getOnlineUserList() {
List<AgileOnlineUser> onlineUserList = new ArrayList<>();
List<Object> sessionIdList = sessionRegistry.getAllPrincipals();
for (Object sessionId : sessionIdList) {
AgileUserDetails agileUserDetails = (AgileUserDetails) AgileCacheUtil.get(AgileCacheConstants.AGILE_CACHE_SESSION_NAME, sessionId.toString());
if (agileUserDetails == null || AgileStringUtil.isEmpty(agileUserDetails.getUsername())) {
sessionRegistry.removeSessionInformation(sessionId.toString());
continue;
}
SessionInformation sessionInformation = sessionRegistry.getSessionInformation(sessionId.toString());
if (sessionInformation == null) {
sessionRegistry.removeSessionInformation(sessionId.toString());
continue;
}
AgileOnlineUser agileOnlineUser = new AgileOnlineUser();
BeanUtils.copyProperties(agileUserDetails.getUserData(), agileOnlineUser);
agileOnlineUser.setStartAccessTime(agileUserDetails.getUserData().getLoginTime());
agileOnlineUser.setLastAccessTime(sessionInformation.getLastRequest());
onlineUserList.add(agileOnlineUser);
}
return onlineUserList;
}
Aggregations