mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-06 17:08:29 +08:00
11.11 应用访问日志改为线程写入,登录的ROLE->GROUP
This commit is contained in:
parent
f6cebda6e5
commit
8b0b1158b9
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package org.dromara.maxkey.authn;
|
package org.dromara.maxkey.authn;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.dromara.maxkey.authn.session.Session;
|
import org.dromara.maxkey.authn.session.Session;
|
||||||
import org.dromara.maxkey.entity.UserInfo;
|
import org.dromara.maxkey.entity.UserInfo;
|
||||||
@ -33,9 +33,13 @@ public class SignPrincipal implements UserDetails {
|
|||||||
UserDetails userDetails;
|
UserDetails userDetails;
|
||||||
|
|
||||||
String sessionId;
|
String sessionId;
|
||||||
ArrayList<GrantedAuthority> grantedAuthority;
|
|
||||||
ArrayList<GrantedAuthority> grantedAuthorityApps;
|
List<GrantedAuthority> grantedAuthority;
|
||||||
|
|
||||||
|
List<GrantedAuthority> grantedAuthorityApps;
|
||||||
|
|
||||||
boolean authenticated;
|
boolean authenticated;
|
||||||
|
|
||||||
boolean roleAdministrators;
|
boolean roleAdministrators;
|
||||||
|
|
||||||
private boolean accountNonExpired;
|
private boolean accountNonExpired;
|
||||||
@ -104,7 +108,7 @@ public class SignPrincipal implements UserDetails {
|
|||||||
return grantedAuthority;
|
return grantedAuthority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<GrantedAuthority> getGrantedAuthority() {
|
public List<GrantedAuthority> getGrantedAuthority() {
|
||||||
return grantedAuthority;
|
return grantedAuthority;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +120,7 @@ public class SignPrincipal implements UserDetails {
|
|||||||
this.userDetails = userDetails;
|
this.userDetails = userDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGrantedAuthority(ArrayList<GrantedAuthority> grantedAuthority) {
|
public void setGrantedAuthority(List<GrantedAuthority> grantedAuthority) {
|
||||||
this.grantedAuthority = grantedAuthority;
|
this.grantedAuthority = grantedAuthority;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,11 +163,11 @@ public class SignPrincipal implements UserDetails {
|
|||||||
return this.enabled;
|
return this.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<GrantedAuthority> getGrantedAuthorityApps() {
|
public List<GrantedAuthority> getGrantedAuthorityApps() {
|
||||||
return grantedAuthorityApps;
|
return grantedAuthorityApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGrantedAuthorityApps(ArrayList<GrantedAuthority> grantedAuthorityApps) {
|
public void setGrantedAuthorityApps(List<GrantedAuthority> grantedAuthorityApps) {
|
||||||
this.grantedAuthorityApps = grantedAuthorityApps;
|
this.grantedAuthorityApps = grantedAuthorityApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
package org.dromara.maxkey.authn.provider;
|
package org.dromara.maxkey.authn.provider;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.dromara.maxkey.authn.LoginCredential;
|
import org.dromara.maxkey.authn.LoginCredential;
|
||||||
import org.dromara.maxkey.authn.SignPrincipal;
|
import org.dromara.maxkey.authn.SignPrincipal;
|
||||||
@ -109,7 +110,7 @@ public abstract class AbstractAuthenticationProvider {
|
|||||||
//set session with principal
|
//set session with principal
|
||||||
SignPrincipal principal = new SignPrincipal(userInfo,session);
|
SignPrincipal principal = new SignPrincipal(userInfo,session);
|
||||||
|
|
||||||
ArrayList<GrantedAuthority> grantedAuthoritys = authenticationRealm.grantAuthority(userInfo);
|
List<GrantedAuthority> grantedAuthoritys = authenticationRealm.grantAuthority(userInfo);
|
||||||
principal.setAuthenticated(true);
|
principal.setAuthenticated(true);
|
||||||
|
|
||||||
for(GrantedAuthority administratorsAuthority : grantedAdministratorsAuthoritys) {
|
for(GrantedAuthority administratorsAuthority : grantedAdministratorsAuthoritys) {
|
||||||
|
|||||||
@ -17,14 +17,13 @@
|
|||||||
|
|
||||||
package org.dromara.maxkey.authn.realm;
|
package org.dromara.maxkey.authn.realm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dromara.maxkey.authn.SignPrincipal;
|
import org.dromara.maxkey.authn.SignPrincipal;
|
||||||
import org.dromara.maxkey.authn.realm.ldap.LdapAuthenticationRealmService;
|
import org.dromara.maxkey.authn.realm.ldap.LdapAuthenticationRealmService;
|
||||||
|
import org.dromara.maxkey.entity.Groups;
|
||||||
import org.dromara.maxkey.entity.HistoryLogin;
|
import org.dromara.maxkey.entity.HistoryLogin;
|
||||||
import org.dromara.maxkey.entity.Roles;
|
|
||||||
import org.dromara.maxkey.entity.UserInfo;
|
import org.dromara.maxkey.entity.UserInfo;
|
||||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||||
import org.dromara.maxkey.ip2location.Region;
|
import org.dromara.maxkey.ip2location.Region;
|
||||||
@ -89,8 +88,8 @@ public abstract class AbstractAuthenticationRealm {
|
|||||||
|
|
||||||
public abstract boolean passwordMatches(UserInfo userInfo, String password);
|
public abstract boolean passwordMatches(UserInfo userInfo, String password);
|
||||||
|
|
||||||
public List<Roles> queryGroups(UserInfo userInfo) {
|
public List<Groups> queryGroups(UserInfo userInfo) {
|
||||||
return loginRepository.queryRoles(userInfo);
|
return loginRepository.queryGroups(userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,7 +98,7 @@ public abstract class AbstractAuthenticationRealm {
|
|||||||
* @param userInfo
|
* @param userInfo
|
||||||
* @return ArrayList<GrantedAuthority>
|
* @return ArrayList<GrantedAuthority>
|
||||||
*/
|
*/
|
||||||
public ArrayList<GrantedAuthority> grantAuthority(UserInfo userInfo) {
|
public List<GrantedAuthority> grantAuthority(UserInfo userInfo) {
|
||||||
return loginRepository.grantAuthority(userInfo);
|
return loginRepository.grantAuthority(userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +108,7 @@ public abstract class AbstractAuthenticationRealm {
|
|||||||
* @param grantedAuthoritys
|
* @param grantedAuthoritys
|
||||||
* @return ArrayList<GrantedAuthority Apps>
|
* @return ArrayList<GrantedAuthority Apps>
|
||||||
*/
|
*/
|
||||||
public ArrayList<GrantedAuthority> queryAuthorizedApps(ArrayList<GrantedAuthority> grantedAuthoritys) {
|
public List<GrantedAuthority> queryAuthorizedApps(List<GrantedAuthority> grantedAuthoritys) {
|
||||||
return loginRepository.queryAuthorizedApps(grantedAuthoritys);
|
return loginRepository.queryAuthorizedApps(grantedAuthoritys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,9 +24,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.dromara.maxkey.constants.ConstsRoles;
|
import org.dromara.maxkey.constants.ConstsRoles;
|
||||||
import org.dromara.maxkey.constants.ConstsStatus;
|
import org.dromara.maxkey.constants.ConstsStatus;
|
||||||
import org.dromara.maxkey.entity.Roles;
|
import org.dromara.maxkey.entity.Groups;
|
||||||
import org.dromara.maxkey.entity.UserInfo;
|
import org.dromara.maxkey.entity.UserInfo;
|
||||||
import org.dromara.maxkey.util.StringUtils;
|
import org.dromara.maxkey.util.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -37,7 +38,7 @@ import org.springframework.security.core.GrantedAuthority;
|
|||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
|
|
||||||
public class LoginRepository {
|
public class LoginRepository {
|
||||||
private static Logger _logger = LoggerFactory.getLogger(LoginRepository.class);
|
private static final Logger _logger = LoggerFactory.getLogger(LoginRepository.class);
|
||||||
|
|
||||||
private static final String LOCK_USER_UPDATE_STATEMENT = "update mxk_userinfo set islocked = ? , unlocktime = ? where id = ?";
|
private static final String LOCK_USER_UPDATE_STATEMENT = "update mxk_userinfo set islocked = ? , unlocktime = ? where id = ?";
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ public class LoginRepository {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final String ROLES_SELECT_STATEMENT = "select distinct g.id,g.groupcode,g.groupname from mxk_userinfo u,mxk_groups g,mxk_group_member gm where u.id = ? and u.id=gm.memberid and gm.groupid=g.id ";
|
private static final String GROUPS_SELECT_STATEMENT = "select distinct g.id,g.groupcode,g.groupname from mxk_userinfo u,mxk_groups g,mxk_group_member gm where u.id = ? and u.id=gm.memberid and gm.groupid=g.id ";
|
||||||
|
|
||||||
private static final String DEFAULT_USERINFO_SELECT_STATEMENT = "select * from mxk_userinfo where username = ? ";
|
private static final String DEFAULT_USERINFO_SELECT_STATEMENT = "select * from mxk_userinfo where username = ? ";
|
||||||
|
|
||||||
@ -86,13 +87,8 @@ public class LoginRepository {
|
|||||||
}else if( LOGIN_ATTRIBUTE_TYPE == 3) {
|
}else if( LOGIN_ATTRIBUTE_TYPE == 3) {
|
||||||
listUserInfo = findByUsernameOrMobileOrEmail(username,password);
|
listUserInfo = findByUsernameOrMobileOrEmail(username,password);
|
||||||
}
|
}
|
||||||
|
_logger.debug("load UserInfo : {}" , listUserInfo);
|
||||||
UserInfo userInfo = null;
|
return (CollectionUtils.isNotEmpty(listUserInfo))? listUserInfo.get(0) : null;
|
||||||
if (listUserInfo != null && listUserInfo.size() > 0) {
|
|
||||||
userInfo = listUserInfo.get(0);
|
|
||||||
}
|
|
||||||
_logger.debug("load UserInfo : " + userInfo);
|
|
||||||
return userInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserInfo> findByUsername(String username, String password) {
|
public List<UserInfo> findByUsername(String username, String password) {
|
||||||
@ -194,7 +190,7 @@ public class LoginRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<GrantedAuthority> queryAuthorizedApps(ArrayList<GrantedAuthority> grantedAuthoritys) {
|
public List<GrantedAuthority> queryAuthorizedApps(List<GrantedAuthority> grantedAuthoritys) {
|
||||||
String grantedAuthorityString="'ROLE_ALL_USER'";
|
String grantedAuthorityString="'ROLE_ALL_USER'";
|
||||||
for(GrantedAuthority grantedAuthority : grantedAuthoritys) {
|
for(GrantedAuthority grantedAuthority : grantedAuthoritys) {
|
||||||
grantedAuthorityString += ",'"+ grantedAuthority.getAuthority()+"'";
|
grantedAuthorityString += ",'"+ grantedAuthority.getAuthority()+"'";
|
||||||
@ -208,20 +204,18 @@ public class LoginRepository {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_logger.debug("list Authorized Apps " + listAuthorizedApps);
|
_logger.debug("list Authorized Apps {}" , listAuthorizedApps);
|
||||||
return listAuthorizedApps;
|
return listAuthorizedApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Roles> queryRoles(UserInfo userInfo) {
|
public List<Groups> queryGroups(UserInfo userInfo) {
|
||||||
List<Roles> listRoles = jdbcTemplate.query(ROLES_SELECT_STATEMENT, new RowMapper<Roles>() {
|
List<Groups> listRoles = jdbcTemplate.query(GROUPS_SELECT_STATEMENT, new RowMapper<Groups>() {
|
||||||
public Roles mapRow(ResultSet rs, int rowNum) throws SQLException {
|
public Groups mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||||
Roles role = new Roles(rs.getString("id"), rs.getString("groupcode"),rs.getString("groupname"), 0);
|
return new Groups(rs.getString("id"), rs.getString("groupcode"),rs.getString("groupname"), 0);
|
||||||
|
|
||||||
return role;
|
|
||||||
}
|
}
|
||||||
}, userInfo.getId());
|
}, userInfo.getId());
|
||||||
|
|
||||||
_logger.debug("list Roles " + listRoles);
|
_logger.debug("list Roles {}" , listRoles);
|
||||||
return listRoles;
|
return listRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,23 +225,23 @@ public class LoginRepository {
|
|||||||
* @param userInfo
|
* @param userInfo
|
||||||
* @return ArrayList<GrantedAuthority>
|
* @return ArrayList<GrantedAuthority>
|
||||||
*/
|
*/
|
||||||
public ArrayList<GrantedAuthority> grantAuthority(UserInfo userInfo) {
|
public List<GrantedAuthority> grantAuthority(UserInfo userInfo) {
|
||||||
// query roles for user
|
// query Groups for user
|
||||||
List<Roles> listRoles = queryRoles(userInfo);
|
List<Groups> listGroups = queryGroups(userInfo);
|
||||||
|
|
||||||
//set default roles
|
//set default groups
|
||||||
ArrayList<GrantedAuthority> grantedAuthority = new ArrayList<GrantedAuthority>();
|
ArrayList<GrantedAuthority> grantedAuthority = new ArrayList<>();
|
||||||
grantedAuthority.add(ConstsRoles.ROLE_USER);
|
grantedAuthority.add(ConstsRoles.ROLE_USER);
|
||||||
grantedAuthority.add(ConstsRoles.ROLE_ALL_USER);
|
grantedAuthority.add(ConstsRoles.ROLE_ALL_USER);
|
||||||
grantedAuthority.add(ConstsRoles.ROLE_ORDINARY_USER);
|
grantedAuthority.add(ConstsRoles.ROLE_ORDINARY_USER);
|
||||||
for (Roles role : listRoles) {
|
for (Groups group : listGroups) {
|
||||||
grantedAuthority.add(new SimpleGrantedAuthority(role.getId()));
|
grantedAuthority.add(new SimpleGrantedAuthority(group.getId()));
|
||||||
if(role.getRoleCode().startsWith("ROLE_")
|
if(group.getGroupCode().startsWith("ROLE_")
|
||||||
&& !grantedAuthority.contains(new SimpleGrantedAuthority(role.getRoleCode()))) {
|
&& !grantedAuthority.contains(new SimpleGrantedAuthority(group.getGroupCode()))) {
|
||||||
grantedAuthority.add(new SimpleGrantedAuthority(role.getRoleCode()));
|
grantedAuthority.add(new SimpleGrantedAuthority(group.getGroupCode()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_logger.debug("Authority : " + grantedAuthority);
|
_logger.debug("Authority : {}" , grantedAuthority);
|
||||||
|
|
||||||
return grantedAuthority;
|
return grantedAuthority;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,15 +30,35 @@ public class HistoryLoginAppsService extends JpaService<HistoryLoginApps>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see com.connsec.db.service.BaseService#getMapper()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public HistoryLoginAppsMapper getMapper() {
|
public HistoryLoginAppsMapper getMapper() {
|
||||||
return (HistoryLoginAppsMapper)super.getMapper();
|
return (HistoryLoginAppsMapper)super.getMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean insert(HistoryLoginApps loginAppsHistory){
|
public boolean insert(HistoryLoginApps loginAppsHistory){
|
||||||
return getMapper().insert(loginAppsHistory)> 0;
|
//new Thread insert login app history
|
||||||
|
new Thread(new HistoryLoginAppsRunnable(getMapper(),loginAppsHistory)).start();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HistoryLoginAppsRunnable implements Runnable{
|
||||||
|
|
||||||
|
HistoryLoginAppsMapper historyLoginAppsMapper;
|
||||||
|
|
||||||
|
HistoryLoginApps loginAppsHistory;
|
||||||
|
|
||||||
|
public HistoryLoginAppsRunnable(HistoryLoginAppsMapper historyLoginAppsMapper,
|
||||||
|
HistoryLoginApps loginAppsHistory) {
|
||||||
|
super();
|
||||||
|
this.historyLoginAppsMapper = historyLoginAppsMapper;
|
||||||
|
this.loginAppsHistory = loginAppsHistory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
historyLoginAppsMapper.insert(loginAppsHistory);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
package org.dromara.maxkey.authz.oauth2.provider;
|
package org.dromara.maxkey.authz.oauth2.provider;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.dromara.maxkey.authn.SignPrincipal;
|
import org.dromara.maxkey.authn.SignPrincipal;
|
||||||
import org.dromara.maxkey.authn.provider.AbstractAuthenticationProvider;
|
import org.dromara.maxkey.authn.provider.AbstractAuthenticationProvider;
|
||||||
@ -52,7 +53,7 @@ public class OAuth2UserDetailsService implements UserDetailsService {
|
|||||||
//set OnlineTicket
|
//set OnlineTicket
|
||||||
principal.setSessionId(onlineTicket.getId());
|
principal.setSessionId(onlineTicket.getId());
|
||||||
|
|
||||||
ArrayList<GrantedAuthority> grantedAuthoritys = loginRepository.grantAuthority(userInfo);
|
List<GrantedAuthority> grantedAuthoritys = loginRepository.grantAuthority(userInfo);
|
||||||
principal.setAuthenticated(true);
|
principal.setAuthenticated(true);
|
||||||
|
|
||||||
for(GrantedAuthority administratorsAuthority : AbstractAuthenticationProvider.grantedAdministratorsAuthoritys) {
|
for(GrantedAuthority administratorsAuthority : AbstractAuthenticationProvider.grantedAdministratorsAuthoritys) {
|
||||||
|
|||||||
@ -58,16 +58,16 @@ public class ForgotPasswordContorller {
|
|||||||
EmailConfig emailConfig;
|
EmailConfig emailConfig;
|
||||||
|
|
||||||
public class ForgotType{
|
public class ForgotType{
|
||||||
public final static int NOTFOUND = 1;
|
public static final int NOTFOUND = 1;
|
||||||
public final static int EMAIL = 2;
|
public static final int EMAIL = 2;
|
||||||
public final static int MOBILE = 3;
|
public static final int MOBILE = 3;
|
||||||
public final static int CAPTCHAERROR = 4;
|
public static final int CAPTCHAERROR = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PasswordResetResult{
|
public class PasswordResetResult{
|
||||||
public final static int SUCCESS = 1;
|
public static final int SUCCESS = 1;
|
||||||
public final static int CAPTCHAERROR = 2;
|
public static final int CAPTCHAERROR = 2;
|
||||||
public final static int PASSWORDERROR = 3;
|
public static final int PASSWORDERROR = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user