大量代码调整和优化

This commit is contained in:
shimingxy
2024-07-22 16:24:58 +08:00
parent 32b0f69c50
commit 363703f21e
288 changed files with 5873 additions and 1156 deletions

View File

@@ -21,7 +21,7 @@ import java.util.Collection;
import java.util.List;
import org.dromara.maxkey.authn.session.Session;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

View File

@@ -23,7 +23,7 @@ import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.dromara.maxkey.authn.SignPrincipal;
import org.dromara.maxkey.crypto.jwt.HMAC512Service;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.util.StrUtils;
import org.dromara.maxkey.web.WebContext;
import org.joda.time.DateTime;

View File

@@ -21,7 +21,7 @@ import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.dromara.maxkey.entity.HistoryLogin;
import org.dromara.maxkey.entity.history.HistoryLogin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -20,7 +20,7 @@ package org.dromara.maxkey.authn.session;
import java.time.LocalDateTime;
import java.util.List;
import org.dromara.maxkey.entity.HistoryLogin;
import org.dromara.maxkey.entity.history.HistoryLogin;
import org.dromara.maxkey.persistence.redis.RedisConnection;
import org.dromara.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;

View File

@@ -20,7 +20,7 @@ package org.dromara.maxkey.authn.session;
import java.time.LocalDateTime;
import java.util.List;
import org.dromara.maxkey.entity.HistoryLogin;
import org.dromara.maxkey.entity.history.HistoryLogin;
public interface SessionManager {

View File

@@ -25,8 +25,8 @@ import java.util.Date;
import java.util.List;
import org.dromara.maxkey.constants.ConstsPersistence;
import org.dromara.maxkey.entity.HistoryLogin;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.history.HistoryLogin;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.persistence.redis.RedisConnectionFactory;
import org.dromara.maxkey.util.DateUtils;
import org.slf4j.Logger;

View File

@@ -24,7 +24,7 @@ import org.dromara.maxkey.authn.SignPrincipal;
import org.dromara.maxkey.authn.jwt.AuthTokenService;
import org.dromara.maxkey.authn.session.Session;
import org.dromara.maxkey.authn.session.SessionManager;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.util.AuthorizationHeaderUtils;
import org.dromara.maxkey.web.WebConstants;
import org.dromara.maxkey.web.WebContext;

View File

@@ -18,7 +18,7 @@
package org.dromara.maxkey.authn.web;
import org.dromara.maxkey.authn.annotation.CurrentUser;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.web.WebConstants;
import org.springframework.core.MethodParameter;
import org.springframework.security.core.Authentication;

View File

@@ -22,7 +22,7 @@ import java.io.IOException;
import org.dromara.maxkey.authn.annotation.CurrentUser;
import org.dromara.maxkey.entity.FileUpload;
import org.dromara.maxkey.entity.Message;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.persistence.service.FileUploadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -30,7 +30,7 @@ import org.dromara.maxkey.authn.web.AuthorizationUtils;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.dromara.maxkey.constants.ConstsLoginType;
import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
import org.dromara.maxkey.password.onetimepwd.MailOtpAuthnService;
import org.dromara.maxkey.web.WebConstants;

View File

@@ -25,7 +25,7 @@ import org.dromara.maxkey.authn.session.SessionManager;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.dromara.maxkey.constants.ConstsLoginType;
import org.dromara.maxkey.entity.Institutions;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.web.WebConstants;
import org.dromara.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -72,10 +72,8 @@ public class MfaAuthenticationProvider extends AbstractAuthenticationProvider {
loginCredential.getPrincipal(), getProviderName());
try {
_logger.debug("authentication " + loginCredential);
Institutions inst = (Institutions)WebContext.getAttribute(WebConstants.CURRENT_INST);
_logger.debug("authentication {}" , loginCredential);
emptyPasswordValid(loginCredential.getPassword());
UserInfo userInfo = null;

View File

@@ -23,7 +23,7 @@ import org.dromara.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.dromara.maxkey.authn.session.SessionManager;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.dromara.maxkey.constants.ConstsLoginType;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
import org.dromara.maxkey.password.sms.SmsOtpAuthnService;
import org.dromara.maxkey.web.WebConstants;

View File

@@ -26,8 +26,7 @@ import org.dromara.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.dromara.maxkey.authn.session.SessionManager;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.dromara.maxkey.constants.ConstsLoginType;
import org.dromara.maxkey.entity.Institutions;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.web.WebConstants;
import org.dromara.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -73,16 +72,10 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
loginCredential.getPrincipal(), getProviderName());
try {
_logger.debug("authentication " + loginCredential);
Institutions inst = (Institutions)WebContext.getAttribute(WebConstants.CURRENT_INST);
_logger.debug("authentication {}" , loginCredential);
if(this.applicationConfig.getLoginConfig().isCaptcha()) {
captchaValid(loginCredential.getState(),loginCredential.getCaptcha());
}else if(!inst.getCaptcha().equalsIgnoreCase("NONE")) {
captchaValid(loginCredential.getState(),loginCredential.getCaptcha());
}
emptyPasswordValid(loginCredential.getPassword());
@@ -116,9 +109,9 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
WebConstants.LOGIN_RESULT.SUCCESS);
} catch (AuthenticationException e) {
_logger.error("Failed to authenticate user {} via {}: {}",
new Object[] { loginCredential.getPrincipal(),
loginCredential.getPrincipal(),
getProviderName(),
e.getMessage() });
e.getMessage() );
WebContext.setAttribute(
WebConstants.LOGIN_ERROR_SESSION_MESSAGE, e.getMessage());
} catch (Exception e) {
@@ -136,7 +129,7 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
* @param captcha String
* @throws ParseException
*/
protected void captchaValid(String state ,String captcha) throws ParseException {
protected void captchaValid(String state ,String captcha) {
// for basic
if(!authTokenService.validateCaptcha(state,captcha)) {
throw new BadCredentialsException(WebContext.getI18nValue("login.error.captcha"));

View File

@@ -22,7 +22,7 @@ import org.dromara.maxkey.authn.provider.AbstractAuthenticationProvider;
import org.dromara.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.dromara.maxkey.authn.session.SessionManager;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.web.WebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -22,9 +22,9 @@ import java.util.List;
import org.dromara.maxkey.authn.SignPrincipal;
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.UserInfo;
import org.dromara.maxkey.entity.history.HistoryLogin;
import org.dromara.maxkey.entity.idm.Groups;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.ip2location.IpLocationParser;
import org.dromara.maxkey.ip2location.Region;
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;

View File

@@ -23,8 +23,8 @@ import org.dromara.maxkey.authn.realm.ldap.LdapAuthenticationRealmService;
import org.dromara.maxkey.constants.ConstsLoginType;
import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.entity.ChangePassword;
import org.dromara.maxkey.entity.PasswordPolicy;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.ip2location.IpLocationParser;
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
import org.dromara.maxkey.persistence.repository.LoginRepository;
@@ -128,7 +128,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
if (!passwordMatches) {
passwordPolicyValidator.plusBadPasswordCount(userInfo);
insertLoginHistory(userInfo, ConstsLoginType.LOCAL, "", "xe00000004", WebConstants.LOGIN_RESULT.PASSWORD_ERROE);
PasswordPolicy passwordPolicy = passwordPolicyValidator.getPasswordPolicyRepository().getPasswordPolicy();
CnfPasswordPolicy passwordPolicy = passwordPolicyValidator.getPasswordPolicyRepository().getPasswordPolicy();
if(userInfo.getBadPasswordCount()>=(passwordPolicy.getAttempts()/2)) {
throw new BadCredentialsException(
WebContext.getI18nValue("login.error.password.attempts",

View File

@@ -21,7 +21,7 @@ import java.util.List;
import org.dromara.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.dromara.maxkey.authn.realm.IAuthenticationServer;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;

View File

@@ -22,10 +22,10 @@ import java.util.concurrent.TimeUnit;
import org.dromara.maxkey.authn.realm.IAuthenticationServer;
import org.dromara.maxkey.crypto.password.PasswordReciprocal;
import org.dromara.maxkey.entity.LdapContext;
import org.dromara.maxkey.entity.cnf.CnfLdapContext;
import org.dromara.maxkey.ldap.ActiveDirectoryUtils;
import org.dromara.maxkey.ldap.LdapUtils;
import org.dromara.maxkey.persistence.service.LdapContextService;
import org.dromara.maxkey.persistence.service.CnfLdapContextService;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@@ -36,23 +36,23 @@ public class LdapAuthenticationRealmService {
.expireAfterWrite(60, TimeUnit.MINUTES)
.build();
LdapContextService ldapContextService;
CnfLdapContextService ldapContextService;
public LdapAuthenticationRealmService(LdapContextService ldapContextService) {
public LdapAuthenticationRealmService(CnfLdapContextService ldapContextService) {
this.ldapContextService = ldapContextService;
}
public LdapAuthenticationRealm getByInstId(String instId) {
LdapAuthenticationRealm authenticationRealm = ldapRealmStore.getIfPresent(instId);
if(authenticationRealm == null) {
List<LdapContext> ldapContexts =
List<CnfLdapContext> ldapContexts =
ldapContextService.find("where instid = ? and status = 1 ", new Object[]{instId}, new int[]{Types.VARCHAR});
authenticationRealm = new LdapAuthenticationRealm(false);
if(ldapContexts != null && ldapContexts.size()>0) {
authenticationRealm.setLdapSupport(true);
List<IAuthenticationServer> ldapAuthenticationServers = new ArrayList<IAuthenticationServer>();
for(LdapContext ldapContext : ldapContexts) {
for(CnfLdapContext ldapContext : ldapContexts) {
if(ldapContext.getProduct().equalsIgnoreCase("ActiveDirectory")) {
ActiveDirectoryServer ldapServer = new ActiveDirectoryServer();
ActiveDirectoryUtils ldapUtils = new ActiveDirectoryUtils(

View File

@@ -24,7 +24,7 @@ import org.dromara.maxkey.authn.SignPrincipal;
import org.dromara.maxkey.authn.jwt.AuthTokenService;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.dromara.maxkey.crypto.jwt.HMAC512Service;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.util.DateUtils;
import org.dromara.maxkey.web.WebContext;
import org.joda.time.DateTime;

View File

@@ -29,7 +29,7 @@ import org.dromara.maxkey.constants.ConstsLoginType;
import org.dromara.maxkey.entity.Message;
import org.dromara.maxkey.entity.SocialsAssociate;
import org.dromara.maxkey.entity.SocialsProvider;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.uuid.UUID;
import org.dromara.maxkey.web.WebContext;
import org.slf4j.Logger;

View File

@@ -28,8 +28,8 @@ import jakarta.persistence.Table;
import org.dromara.maxkey.entity.apps.Apps;
@Entity
@Table(name = "mxk_group_permissions")
public class GroupPermissions extends Apps implements Serializable{
@Table(name = "mxk_access")
public class Access extends Apps implements Serializable{
/**
*
@@ -54,7 +54,7 @@ public class GroupPermissions extends Apps implements Serializable{
private String instName;
public GroupPermissions(){
public Access(){
super();
}
@@ -63,7 +63,7 @@ public class GroupPermissions extends Apps implements Serializable{
* @param groupId
* @param appId
*/
public GroupPermissions(String groupId, String appId, String instId) {
public Access(String groupId, String appId, String instId) {
super();
this.groupId = groupId;
this.appId = appId;
@@ -150,7 +150,7 @@ public class GroupPermissions extends Apps implements Serializable{
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GroupPermissions [id=");
builder.append("Access [id=");
builder.append(id);
builder.append(", groupId=");
builder.append(groupId);

View File

@@ -21,6 +21,7 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.mybatis.jpa.entity.JpaEntity;
import org.hibernate.validator.constraints.Length;

View File

@@ -19,6 +19,7 @@ package org.dromara.maxkey.entity;
import java.util.Date;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.mybatis.jpa.entity.JpaEntity;
public class ChangePassword extends JpaEntity{

View File

@@ -34,8 +34,7 @@ import jakarta.persistence.Table;
@Entity
@Table(name = "MXK_FILE_UPLOAD")
public class FileUpload extends JpaEntity {
private static final long serialVersionUID = -4338400992411166457L;
@Id
@Column
@GeneratedValue

View File

@@ -77,9 +77,6 @@ public class Institutions extends JpaEntity implements Serializable {
@Column
private String consoleTitle;
@Column
private String captcha;
@Column
private String defaultUri;
@@ -249,15 +246,6 @@ public class Institutions extends JpaEntity implements Serializable {
this.description = description;
}
public String getCaptcha() {
return captcha;
}
public void setCaptcha(String captcha) {
this.captcha = captcha;
}
public String getDefaultUri() {
return defaultUri;
}
@@ -309,8 +297,6 @@ public class Institutions extends JpaEntity implements Serializable {
builder.append(consoleDomain);
builder.append(", consoleTitle=");
builder.append(consoleTitle);
builder.append(", captcha=");
builder.append(captcha);
builder.append(", defaultUri=");
builder.append(defaultUri);
builder.append("]");

View File

@@ -1,142 +0,0 @@
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.maxkey.entity;
import java.io.Serializable;
import org.dromara.mybatis.jpa.entity.JpaEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "MXK_LOCALIZATION")
public class Localization extends JpaEntity implements Serializable {
/**
*
*/
private static final long serialVersionUID = -142504964446659847L;
@Id
@Column
@GeneratedValue
private String id;
@Column
private String property;
@Column
private String langZh;
@Column
private String langEn;
@Column
private String description;
@Column
private int status;
@Column
private String instId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
public String getLangZh() {
return langZh;
}
public void setLangZh(String langZh) {
this.langZh = langZh;
}
public String getLangEn() {
return langEn;
}
public void setLangEn(String langEn) {
this.langEn = langEn;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getInstId() {
return instId;
}
public void setInstId(String instId) {
this.instId = instId;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Localization [id=");
builder.append(id);
builder.append(", property=");
builder.append(property);
builder.append(", langZh=");
builder.append(langZh);
builder.append(", langEn=");
builder.append(langEn);
builder.append(", description=");
builder.append(description);
builder.append(", status=");
builder.append(status);
builder.append(", instId=");
builder.append(instId);
builder.append("]");
return builder.toString();
}
}

View File

@@ -20,12 +20,6 @@ package org.dromara.maxkey.entity;
import java.io.Serializable;
import org.dromara.mybatis.jpa.entity.JpaEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
/**
* Saml20Metadata.
* @author Crystal.Sea

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.cnf;
@@ -31,8 +31,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "MXK_EMAIL_SENDERS")
public class EmailSenders extends JpaEntity implements Serializable {
@Table(name = "MXK_CNF_EMAIL_SENDERS")
public class CnfEmailSenders extends JpaEntity implements Serializable {
/**
*
@@ -91,7 +91,7 @@ public class EmailSenders extends JpaEntity implements Serializable {
@Column
private Date modifiedDate;
public EmailSenders() {
public CnfEmailSenders() {
super();
}

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.cnf;
import java.io.Serializable;
import java.util.Date;
@@ -29,8 +29,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "MXK_LDAP_CONTEXT")
public class LdapContext extends JpaEntity implements Serializable {
@Table(name = "MXK_CNF_LDAP_CONTEXT")
public class CnfLdapContext extends JpaEntity implements Serializable {
/**
@@ -81,7 +81,7 @@ public class LdapContext extends JpaEntity implements Serializable {
private String instName;
public LdapContext() {
public CnfLdapContext() {
}
public String getId() {

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.cnf;
import org.dromara.mybatis.jpa.entity.JpaEntity;
@@ -39,8 +39,8 @@ import java.util.List;
*/
@Entity
@Table(name = "MXK_PASSWORD_POLICY")
public class PasswordPolicy extends JpaEntity implements java.io.Serializable {
@Table(name = "MXK_CNF_PASSWORD_POLICY")
public class CnfPasswordPolicy extends JpaEntity implements java.io.Serializable {
private static final long serialVersionUID = -4797776994287829182L;
@Id

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.cnf;
import java.io.Serializable;
import java.util.Date;
@@ -29,8 +29,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "MXK_SMS_PROVIDER")
public class SmsProvider extends JpaEntity implements Serializable {
@Table(name = "MXK_CNF_SMS_PROVIDER")
public class CnfSmsProvider extends JpaEntity implements Serializable {
/**
@@ -75,7 +75,7 @@ public class SmsProvider extends JpaEntity implements Serializable {
private String instName;
public SmsProvider() {
public CnfSmsProvider() {
}
public String getId() {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.history;
import java.io.Serializable;
import java.util.Date;

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.history;
import java.io.Serializable;
import java.util.Date;

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.history;
import java.io.Serializable;
import java.util.Date;

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.history;
import java.io.Serializable;
import java.util.Date;

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.history;
import java.io.Serializable;
import java.util.Date;

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.idm;
import java.io.Serializable;

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.idm;
import java.io.Serializable;
import java.util.Date;

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.idm;
import java.io.Serializable;
import java.util.Date;

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.idm;
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -34,7 +34,6 @@ import jakarta.persistence.Table;
import org.apache.commons.lang3.StringUtils;
import org.dromara.maxkey.crypto.Base64Utils;
import org.dromara.maxkey.util.StrUtils;
/**
* .
@@ -175,10 +174,12 @@ public class UserInfo extends JpaEntity implements Serializable {
// for work
@Column
protected String workCountry;
// province
@Column
protected String workRegion;// province;
protected String workRegion;
// city
@Column
protected String workLocality;// city;
protected String workLocality;
@Column
protected String workStreetAddress;
@Column
@@ -196,10 +197,12 @@ public class UserInfo extends JpaEntity implements Serializable {
// for home
@Column
protected String homeCountry;
// province
@Column
protected String homeRegion;// province;
protected String homeRegion;
// city
@Column
protected String homeLocality;// city;
protected String homeLocality;
@Column
protected String homeStreetAddress;
@Column
@@ -443,7 +446,7 @@ public class UserInfo extends JpaEntity implements Serializable {
*/
public HashMap<String, String> getProtectedAppsMap() {
if (protectedAppsMap == null) {
protectedAppsMap = new HashMap<String, String>();
protectedAppsMap = new HashMap<>();
}
if (StringUtils.isNotEmpty(protectedApps)) {
String[] apps = protectedApps.split(",");

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.permissions;
import java.io.Serializable;
import org.dromara.mybatis.jpa.entity.JpaEntity;
@@ -29,8 +29,8 @@ import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.web.WebContext;
@Entity
@Table(name = "MXK_GROUP_PRIVILEGES")
public class GroupPrivileges extends JpaEntity implements Serializable {
@Table(name = "MXK_PERMISSION")
public class Permission extends JpaEntity implements Serializable {
private static final long serialVersionUID = -8783585691243853899L;
@Id
@@ -50,10 +50,10 @@ public class GroupPrivileges extends JpaEntity implements Serializable {
private String instName;
public GroupPrivileges() {
public Permission() {
}
public GroupPrivileges(String appId, String groupId, String instId) {
public Permission(String appId, String groupId, String instId) {
this.appId = appId;
this.groupId = groupId;
this.instId = instId;
@@ -65,7 +65,7 @@ public class GroupPrivileges extends JpaEntity implements Serializable {
* @param groupId String
* @param resourceId String
*/
public GroupPrivileges(String appId, String groupId, String resourceId , String instId) {
public Permission(String appId, String groupId, String resourceId , String instId) {
this.id = WebContext.genId();
this.appId = appId;
this.groupId = groupId;

View File

@@ -0,0 +1,168 @@
package org.dromara.maxkey.entity.permissions;
import java.io.Serializable;
import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.web.WebContext;
import org.dromara.mybatis.jpa.entity.JpaEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "MXK_PERMISSION_ROLE")
public class PermissionRole extends JpaEntity implements Serializable {
private static final long serialVersionUID = -8783585691243853899L;
@Id
@Column
@GeneratedValue
String id;
@Column
String appId;
@Column
String roleId;
@Column
String resourceId;
@Column
String createdBy;
@Column
String createdDate;
int status = ConstsStatus.ACTIVE;
@Column
private String instId;
private String instName;
public PermissionRole() {
}
public PermissionRole(String appId, String roleId, String instId) {
this.appId = appId;
this.roleId = roleId;
this.instId = instId;
}
/**
* .
* @param appId String
* @param roleId String
* @param resourceId String
*/
public PermissionRole(String appId, String roleId, String resourceId , String createdBy,String instId) {
this.id = WebContext.genId();
this.appId = appId;
this.roleId = roleId;
this.resourceId = resourceId;
this.createdBy = createdBy;
this.instId = instId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
public String getResourceId() {
return resourceId;
}
public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getUniqueId() {
return appId + "_" + roleId + "_" + resourceId;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getCreatedDate() {
return createdDate;
}
public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}
public String getInstId() {
return instId;
}
public void setInstId(String instId) {
this.instId = instId;
}
public String getInstName() {
return instName;
}
public void setInstName(String instName) {
this.instName = instName;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PermissionRole [id=");
builder.append(id);
builder.append(", appId=");
builder.append(appId);
builder.append(", roleId=");
builder.append(roleId);
builder.append(", resourceId=");
builder.append(resourceId);
builder.append(", createdBy=");
builder.append(createdBy);
builder.append(", createdDate=");
builder.append(createdDate);
builder.append(", status=");
builder.append(status);
builder.append(", instId=");
builder.append(instId);
builder.append(", instName=");
builder.append(instName);
builder.append("]");
return builder.toString();
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.permissions;
import java.io.Serializable;
import java.util.Date;

View File

@@ -15,11 +15,11 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.permissions;
import java.io.Serializable;
import org.dromara.mybatis.jpa.entity.JpaEntity;
import org.dromara.maxkey.entity.idm.UserInfo;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@@ -48,6 +48,8 @@ public class RoleMember extends UserInfo implements Serializable{
private String memberName;
@Column
private String type;//User or Group
private String createdBy;
@Column
private String instId;
@@ -73,14 +75,14 @@ public class RoleMember extends UserInfo implements Serializable{
}
public RoleMember(String roleId, String roleName, String memberId,
String memberName, String type , String instId) {
public RoleMember(String roleId, String roleName, String memberId,String memberName, String type , String createdBy, String instId) {
super();
this.roleId = roleId;
this.roleName = roleName;
this.memberId = memberId;
this.memberName = memberName;
this.type = type;
this.createdBy = createdBy;
this.instId = instId;
}
@@ -164,6 +166,13 @@ public class RoleMember extends UserInfo implements Serializable{
this.category = category;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getInstId() {
return instId;

View File

@@ -15,7 +15,7 @@
*/
package org.dromara.maxkey.entity;
package org.dromara.maxkey.entity.permissions;
import java.io.Serializable;
import java.util.Date;
@@ -43,7 +43,6 @@ public class Roles extends JpaEntity implements Serializable {
public static final String APP = "app";
}
@Id
@Column
@GeneratedValue
@@ -85,6 +84,9 @@ public class Roles extends JpaEntity implements Serializable {
@Column
int status;
@Column
String appId;
@Column
private String instId;
@@ -103,12 +105,13 @@ public class Roles extends JpaEntity implements Serializable {
* @param name String
* @param isdefault int
*/
public Roles(String id,String roleCode, String roleName, int isdefault) {
public Roles(String id,String roleCode, String roleName, int isdefault,String appId) {
super();
this.id = id;
this.roleCode = roleCode;
this.roleName = roleName;
this.isdefault = isdefault;
this.appId = appId;
}
public String getId() {
@@ -198,7 +201,7 @@ public class Roles extends JpaEntity implements Serializable {
* 3, not filters
*/
public void setDefaultAllUser() {
this.category = "dynamic";
this.category = Category.DYNAMIC;
this.orgIdsList ="";
this.filters ="";
}
@@ -243,7 +246,15 @@ public class Roles extends JpaEntity implements Serializable {
this.suspendTime = suspendTime;
}
public String getInstId() {
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getInstId() {
return instId;
}

View File

@@ -22,7 +22,7 @@ package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.GroupPermissions;
import org.dromara.maxkey.entity.Access;
import org.dromara.mybatis.jpa.IJpaMapper;
/**
@@ -30,12 +30,12 @@ import org.dromara.mybatis.jpa.IJpaMapper;
*
*/
public interface GroupPermissionsMapper extends IJpaMapper<GroupPermissions> {
public interface AccessMapper extends IJpaMapper<Access> {
public List<GroupPermissions>appsInGroup(GroupPermissions entity);
public List<Access>appsInGroup(Access entity);
public List<GroupPermissions> appsNotInGroup(GroupPermissions entity);
public List<Access> appsNotInGroup(Access entity);
}

View File

@@ -27,7 +27,7 @@ import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.dromara.maxkey.entity.Accounts;
import org.dromara.maxkey.entity.AccountsStrategy;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -23,7 +23,7 @@ package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.AccountsStrategy;
import org.dromara.maxkey.entity.Roles;
import org.dromara.maxkey.entity.permissions.Roles;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -16,9 +16,9 @@
package org.dromara.maxkey.persistence.mapper;
import org.dromara.maxkey.entity.LdapContext;
import org.dromara.maxkey.entity.cnf.CnfEmailSenders;
import org.dromara.mybatis.jpa.IJpaMapper;
public interface LdapContextMapper extends IJpaMapper<LdapContext> {
public interface CnfEmailSendersMapper extends IJpaMapper<CnfEmailSenders> {
}

View File

@@ -16,9 +16,9 @@
package org.dromara.maxkey.persistence.mapper;
import org.dromara.maxkey.entity.EmailSenders;
import org.dromara.maxkey.entity.cnf.CnfLdapContext;
import org.dromara.mybatis.jpa.IJpaMapper;
public interface EmailSendersMapper extends IJpaMapper<EmailSenders> {
public interface CnfLdapContextMapper extends IJpaMapper<CnfLdapContext> {
}

View File

@@ -20,14 +20,14 @@
*/
package org.dromara.maxkey.persistence.mapper;
import org.dromara.maxkey.entity.PasswordPolicy;
import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
import org.dromara.mybatis.jpa.IJpaMapper;
/**
* @author Crystal.sea
*
*/
public interface PasswordPolicyMapper extends IJpaMapper<PasswordPolicy> {
public interface CnfPasswordPolicyMapper extends IJpaMapper<CnfPasswordPolicy> {
}

View File

@@ -17,9 +17,9 @@
package org.dromara.maxkey.persistence.mapper;
import org.dromara.maxkey.entity.SmsProvider;
import org.dromara.maxkey.entity.cnf.CnfSmsProvider;
import org.dromara.mybatis.jpa.IJpaMapper;
public interface SmsProviderMapper extends IJpaMapper<SmsProvider> {
public interface CnfSmsProviderMapper extends IJpaMapper<CnfSmsProvider> {
}

View File

@@ -22,11 +22,11 @@ package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.GroupMember;
import org.dromara.maxkey.entity.Groups;
import org.dromara.maxkey.entity.RoleMember;
import org.dromara.maxkey.entity.Roles;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.GroupMember;
import org.dromara.maxkey.entity.idm.Groups;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.entity.permissions.RoleMember;
import org.dromara.maxkey.entity.permissions.Roles;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -22,7 +22,7 @@ package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.Groups;
import org.dromara.maxkey.entity.idm.Groups;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -18,7 +18,7 @@
package org.dromara.maxkey.persistence.mapper;
import org.dromara.maxkey.entity.HistoryConnector;
import org.dromara.maxkey.entity.history.HistoryConnector;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -17,7 +17,7 @@
package org.dromara.maxkey.persistence.mapper;
import org.dromara.maxkey.entity.HistoryLoginApps;
import org.dromara.maxkey.entity.history.HistoryLoginApps;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -20,7 +20,7 @@ package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.HistoryLogin;
import org.dromara.maxkey.entity.history.HistoryLogin;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -18,7 +18,7 @@
package org.dromara.maxkey.persistence.mapper;
import org.dromara.maxkey.entity.HistorySynchronizer;
import org.dromara.maxkey.entity.history.HistorySynchronizer;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -20,7 +20,7 @@
*/
package org.dromara.maxkey.persistence.mapper;
import org.dromara.maxkey.entity.HistorySystemLogs;
import org.dromara.maxkey.entity.history.HistorySystemLogs;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -18,8 +18,8 @@
package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.Organizations;
import org.dromara.maxkey.entity.OrganizationsCast;
import org.dromara.maxkey.entity.idm.Organizations;
import org.dromara.mybatis.jpa.IJpaMapper;
public interface OrganizationsCastMapper extends IJpaMapper<OrganizationsCast> {

View File

@@ -19,7 +19,7 @@ package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Update;
import org.dromara.maxkey.entity.Organizations;
import org.dromara.maxkey.entity.idm.Organizations;
import org.dromara.mybatis.jpa.IJpaMapper;
public interface OrganizationsMapper extends IJpaMapper<Organizations> {

View File

@@ -22,7 +22,7 @@ package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.GroupPrivileges;
import org.dromara.maxkey.entity.permissions.Permission;
import org.dromara.mybatis.jpa.IJpaMapper;
/**
@@ -30,12 +30,12 @@ import org.dromara.mybatis.jpa.IJpaMapper;
*
*/
public interface GroupPrivilegesMapper extends IJpaMapper<GroupPrivileges> {
public interface PermissionMapper extends IJpaMapper<Permission> {
public int insertGroupPrivileges(List<GroupPrivileges> groupPrivilegesList);
public int insertGroupPrivileges(List<Permission> groupPrivilegesList);
public int deleteGroupPrivileges(List<GroupPrivileges> groupPrivilegesList);
public int deleteGroupPrivileges(List<Permission> groupPrivilegesList);
public List<GroupPrivileges> queryGroupPrivileges(GroupPrivileges groupPrivileges);
public List<Permission> queryGroupPrivileges(Permission groupPrivileges);
}

View File

@@ -0,0 +1,22 @@
package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.permissions.PermissionRole;
import org.dromara.mybatis.jpa.IJpaMapper;
/**
* @author Crystal.sea
*
*/
public interface PermissionRoleMapper extends IJpaMapper<PermissionRole> {
public int insertPermissionRoles(List<PermissionRole> permissionRolesList);
public int deletePermissionRoles(List<PermissionRole> permissionRolesList);
public List<PermissionRole> queryPermissionRoles(PermissionRole permissionRole);
}

View File

@@ -23,7 +23,7 @@ package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.Register;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -20,7 +20,7 @@
*/
package org.dromara.maxkey.persistence.mapper;
import org.dromara.maxkey.entity.Resources;
import org.dromara.maxkey.entity.permissions.Resources;
import org.dromara.mybatis.jpa.IJpaMapper;
/**

View File

@@ -0,0 +1,35 @@
package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.entity.permissions.RoleMember;
import org.dromara.maxkey.entity.permissions.Roles;
import org.dromara.mybatis.jpa.IJpaMapper;
/**
* @author Crystal.sea
*
*/
public interface RoleMemberMapper extends IJpaMapper<RoleMember> {
public List<RoleMember> memberInRole(RoleMember entity);
public List<RoleMember> memberNotInRole(RoleMember entity);
public List<RoleMember> memberPostNotInRole(RoleMember entity);
public List<Roles> rolesNoMember(RoleMember entity);
public int addDynamicRoleMember(Roles dynamicRole);
public int deleteDynamicRoleMember(Roles dynamicRole);
public int deleteByRoleId(String roleId);
public List<UserInfo> queryMemberByRoleId(String roleId);
}

View File

@@ -0,0 +1,18 @@
package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.permissions.Roles;
import org.dromara.mybatis.jpa.IJpaMapper;
/**
* @author Crystal.sea
*
*/
public interface RolesMapper extends IJpaMapper<Roles> {
public List<Roles> queryDynamicRoles(Roles groups);
public List<Roles> queryRolesByUserId(String userId);
}

View File

@@ -19,7 +19,7 @@ package org.dromara.maxkey.persistence.mapper;
import java.util.List;
import org.dromara.maxkey.entity.SocialsAssociate;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.mybatis.jpa.IJpaMapper;
public interface SocialsAssociateMapper extends IJpaMapper<SocialsAssociate> {

View File

@@ -23,8 +23,8 @@ import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.entity.ChangePassword;
import org.dromara.maxkey.entity.Organizations;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.Organizations;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.mybatis.jpa.IJpaMapper;

View File

@@ -29,11 +29,12 @@ import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
public class InstitutionsRepository {
private static Logger _logger = LoggerFactory.getLogger(InstitutionsRepository.class);
static final Logger _logger = LoggerFactory.getLogger(InstitutionsRepository.class);
private static final String SELECT_STATEMENT =
"select * from mxk_institutions where id = ? or domain = ? or consoledomain = ?" ;
@@ -46,7 +47,7 @@ public class InstitutionsRepository {
.build();
//id domain mapping
protected static final ConcurrentHashMap<String,String> mapper = new ConcurrentHashMap<String,String>();
protected static final ConcurrentHashMap<String,String> mapper = new ConcurrentHashMap<>();
protected JdbcTemplate jdbcTemplate;
@@ -71,7 +72,7 @@ public class InstitutionsRepository {
List<Institutions> institutions =
jdbcTemplate.query(SELECT_STATEMENT,new InstitutionsRowMapper(),instIdOrDomain,instIdOrDomain,instIdOrDomain);
if (institutions != null && institutions.size() > 0) {
if (CollectionUtils.isNotEmpty(institutions)) {
inst = institutions.get(0);
}
if(inst != null ) {
@@ -96,7 +97,6 @@ public class InstitutionsRepository {
institution.setFrontTitle(rs.getString("fronttitle"));
institution.setConsoleDomain(rs.getString("consoledomain"));
institution.setConsoleTitle(rs.getString("consoletitle"));
institution.setCaptcha(rs.getString("captcha"));
institution.setDefaultUri(rs.getString("defaultUri"));
return institution;
}

View File

@@ -1,156 +0,0 @@
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.maxkey.persistence.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.dromara.maxkey.constants.ConstsTimeInterval;
import org.dromara.maxkey.entity.Localization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
public class LocalizationRepository {
private static Logger _logger = LoggerFactory.getLogger(LocalizationRepository.class);
private static final String INSERT_STATEMENT ="insert into mxk_localization (id, property,langzh,langen,status,description,instid)values(?,?,?,?,?,?,?)";
private static final String UPDATE_STATEMENT ="update mxk_localization set langzh = ? , langen =? where id = ?";
private static final String DELETE_STATEMENT ="delete from mxk_localization where id = ?";
private static final String SELECT_STATEMENT ="select * from mxk_localization where ( id = ? ) or (property = ? and instid = ?)";
private static final Pattern PATTERN_HTML = Pattern.compile("<[^>]+>", Pattern.CASE_INSENSITIVE);
protected InstitutionsRepository institutionService;
JdbcTemplate jdbcTemplate;
protected static final Cache<String, String> localizationStore =
Caffeine.newBuilder()
.expireAfterWrite(ConstsTimeInterval.ONE_HOUR, TimeUnit.SECONDS)
.build();
public LocalizationRepository() {
}
public String getLocale(String code,String htmlTag,Locale locale,String inst) {
String message = "";
htmlTag = (htmlTag == null ||htmlTag.equalsIgnoreCase("true")) ? "tag" : "rtag";
if(code.equals("global.logo")) {
message = institutionService.get(inst).getLogo();
}else if(code.equals("global.title")) {
message = getFromStore(code, htmlTag, locale, inst);
if(message == null) {
message = institutionService.get(inst).getFrontTitle();
}
}else if(code.equals("global.consoleTitle")) {
message = getFromStore(code, htmlTag, locale, inst);
if(message == null) {
message = institutionService.get(inst).getConsoleTitle();
}
}else {
message = getFromStore(code, htmlTag, locale, inst);
}
if(htmlTag.equalsIgnoreCase("rtag")) {
message = clearHTMLToString(message);
}
_logger.trace("{} = {}" , code , message);
return message == null ? "" : message;
}
public String clearHTMLToString(String message) {
return PATTERN_HTML.matcher(message).replaceAll("");
}
public String getFromStore(String code,String htmlTag,Locale locale,String inst) {
String message = localizationStore.getIfPresent(code+"_"+locale.getLanguage()+"_"+inst);
if(message != null) return message;
Localization localization = get(code,inst);
if(localization != null) {
localizationStore.put(code+"_en_"+inst, localization.getLangEn());
localizationStore.put(code+"_zh_"+inst, localization.getLangZh());
if(locale.getLanguage().equals("en")) {
message = localization.getLangEn();
}else {
message = localization.getLangZh();
}
if(message != null) return message;
}
return message;
}
public void setInstitutionService(InstitutionsRepository institutionService) {
this.institutionService = institutionService;
}
public boolean insert(Localization localization) {
return jdbcTemplate.update(INSERT_STATEMENT,
new Object[] {localization.getId(),localization.getProperty(),
localization.getLangZh(),localization.getLangEn(),
localization.getStatus(),localization.getDescription(),
localization.getInstId()},
new int[] {Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER,
Types.VARCHAR, Types.VARCHAR,}) > 0;
}
public boolean update(Localization localization) {
jdbcTemplate.update(UPDATE_STATEMENT,localization.getLangZh(),localization.getLangEn(),localization.getId());
return true;
}
public boolean remove(String id) {
return jdbcTemplate.update(DELETE_STATEMENT,id) > 0;
}
public Localization get(String property,String instId) {
_logger.debug("load property from database , property {} ,instId {}",property, instId);
List<Localization> localizations =
jdbcTemplate.query(
SELECT_STATEMENT,new LocalizationRowMapper(),property,property,instId);
return (localizations==null || localizations.size()==0) ? null : localizations.get(0);
}
public LocalizationRepository(JdbcTemplate jdbcTemplate,InstitutionsRepository institutionService) {
super();
this.institutionService = institutionService;
this.jdbcTemplate = jdbcTemplate;
}
public class LocalizationRowMapper implements RowMapper<Localization> {
@Override
public Localization mapRow(ResultSet rs, int rowNum) throws SQLException {
Localization localization = new Localization();
localization.setId(rs.getString("id"));
localization.setProperty(rs.getString("property"));
localization.setLangZh(rs.getString("langzh"));
localization.setLangEn(rs.getString("langen"));
localization.setStatus(rs.getInt("status"));
localization.setDescription(rs.getString("description"));
localization.setInstId(rs.getString("instid"));
return localization;
}
}
}

View File

@@ -19,7 +19,7 @@ package org.dromara.maxkey.persistence.repository;
import java.sql.Types;
import org.dromara.maxkey.entity.HistoryLogin;
import org.dromara.maxkey.entity.history.HistoryLogin;
import org.dromara.maxkey.web.WebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -28,8 +28,8 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.dromara.maxkey.constants.ConstsRoles;
import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.entity.Groups;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.Groups;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.util.StrUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,7 +62,7 @@ public class LoginRepository {
private static final String DEFAULT_USERINFO_SELECT_STATEMENT_USERNAME_MOBILE_EMAIL = "select * from mxk_userinfo where (username = ? or mobile = ? or email = ?) ";
private static final String DEFAULT_MYAPPS_SELECT_STATEMENT = "select distinct app.id,app.appname from mxk_apps app,mxk_group_permissions gp,mxk_groups g where app.id=gp.appid and app.status = 1 and gp.groupid=g.id and g.id in(%s)";
private static final String DEFAULT_MYAPPS_SELECT_STATEMENT = "select distinct app.id,app.appname from mxk_apps app,mxk_access gp,mxk_groups g where app.id=gp.appid and app.status = 1 and gp.groupid=g.id and g.id in(%s)";
protected JdbcTemplate jdbcTemplate;

View File

@@ -21,10 +21,11 @@ import java.io.InputStreamReader;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.dromara.maxkey.constants.ConstsProperties;
import org.dromara.maxkey.entity.PasswordPolicy;
import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
import org.passay.CharacterOccurrencesRule;
import org.passay.CharacterRule;
import org.passay.DictionaryRule;
@@ -46,19 +47,18 @@ import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
public class PasswordPolicyRepository {
private static Logger _logger = LoggerFactory.getLogger(PasswordPolicyRepository.class);
static final Logger _logger = LoggerFactory.getLogger(PasswordPolicyRepository.class);
//Dictionary topWeakPassword Source
public static final String topWeakPasswordPropertySource =
"classpath:/top_weak_password.txt";
public static final String TOPWEAKPASSWORD_PROPERTYSOURCE = "classpath:/top_weak_password.txt";
//Cache PasswordPolicy in memory ONE_HOUR
protected static final Cache<String, PasswordPolicy> passwordPolicyStore =
protected static final Cache<String, CnfPasswordPolicy> passwordPolicyStore =
Caffeine.newBuilder()
.expireAfterWrite(60, TimeUnit.MINUTES)
.build();
protected PasswordPolicy passwordPolicy;
protected CnfPasswordPolicy passwordPolicy;
protected JdbcTemplate jdbcTemplate;
@@ -66,7 +66,7 @@ public class PasswordPolicyRepository {
private static final String PASSWORD_POLICY_KEY = "PASSWORD_POLICY_KEY";
private static final String PASSWORD_POLICY_SELECT_STATEMENT = "select * from mxk_password_policy ";
private static final String PASSWORD_POLICY_SELECT_STATEMENT = "select * from mxk_cnf_password_policy ";
public PasswordPolicyRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
@@ -76,13 +76,13 @@ public class PasswordPolicyRepository {
* init PasswordPolicy and load Rules
* @return
*/
public PasswordPolicy getPasswordPolicy() {
public CnfPasswordPolicy getPasswordPolicy() {
passwordPolicy = passwordPolicyStore.getIfPresent(PASSWORD_POLICY_KEY);
if (passwordPolicy == null) {
passwordPolicy = jdbcTemplate.queryForObject(PASSWORD_POLICY_SELECT_STATEMENT,
new PasswordPolicyRowMapper());
_logger.debug("query PasswordPolicy : " + passwordPolicy);
_logger.debug("query PasswordPolicy : {}" , passwordPolicy);
passwordPolicyStore.put(PASSWORD_POLICY_KEY,passwordPolicy);
//RandomPasswordLength =(MaxLength +MinLength)/2
@@ -95,7 +95,7 @@ public class PasswordPolicyRepository {
)
);
passwordPolicyRuleList = new ArrayList<Rule>();
passwordPolicyRuleList = new ArrayList<>();
passwordPolicyRuleList.add(new WhitespaceRule());
passwordPolicyRuleList.add(new LengthRule(passwordPolicy.getMinLength(), passwordPolicy.getMaxLength()));
@@ -139,7 +139,7 @@ public class PasswordPolicyRepository {
try {
ClassPathResource dictFile=
new ClassPathResource(
ConstsProperties.classPathResource(topWeakPasswordPropertySource));
ConstsProperties.classPathResource(TOPWEAKPASSWORD_PROPERTYSOURCE));
Dictionary dictionary =new DictionaryBuilder().addReader(new InputStreamReader(dictFile.getInputStream())).build();
passwordPolicyRuleList.add(new DictionaryRule(dictionary));
}catch(Exception e) {
@@ -151,35 +151,35 @@ public class PasswordPolicyRepository {
}
public ArrayList<Rule> getPasswordPolicyRuleList() {
public List<Rule> getPasswordPolicyRuleList() {
getPasswordPolicy();
return passwordPolicyRuleList;
}
public class PasswordPolicyRowMapper implements RowMapper<PasswordPolicy> {
public class PasswordPolicyRowMapper implements RowMapper<CnfPasswordPolicy> {
@Override
public PasswordPolicy mapRow(ResultSet rs, int rowNum) throws SQLException {
PasswordPolicy passwordPolicy = new PasswordPolicy();
passwordPolicy.setId(rs.getString("id"));
passwordPolicy.setMinLength(rs.getInt("minlength"));
passwordPolicy.setMaxLength(rs.getInt("maxlength"));
passwordPolicy.setLowerCase(rs.getInt("lowercase"));
passwordPolicy.setUpperCase(rs.getInt("uppercase"));
passwordPolicy.setDigits(rs.getInt("digits"));
passwordPolicy.setSpecialChar(rs.getInt("specialchar"));
passwordPolicy.setAttempts(rs.getInt("attempts"));
passwordPolicy.setDuration(rs.getInt("duration"));
passwordPolicy.setExpiration(rs.getInt("expiration"));
passwordPolicy.setUsername(rs.getInt("username"));
passwordPolicy.setHistory(rs.getInt("history"));
passwordPolicy.setDictionary(rs.getInt("dictionary"));
passwordPolicy.setAlphabetical(rs.getInt("alphabetical"));
passwordPolicy.setNumerical(rs.getInt("numerical"));
passwordPolicy.setQwerty(rs.getInt("qwerty"));
passwordPolicy.setOccurances(rs.getInt("occurances"));
return passwordPolicy;
public CnfPasswordPolicy mapRow(ResultSet rs, int rowNum) throws SQLException {
CnfPasswordPolicy newPasswordPolicy = new CnfPasswordPolicy();
newPasswordPolicy.setId(rs.getString("id"));
newPasswordPolicy.setMinLength(rs.getInt("minlength"));
newPasswordPolicy.setMaxLength(rs.getInt("maxlength"));
newPasswordPolicy.setLowerCase(rs.getInt("lowercase"));
newPasswordPolicy.setUpperCase(rs.getInt("uppercase"));
newPasswordPolicy.setDigits(rs.getInt("digits"));
newPasswordPolicy.setSpecialChar(rs.getInt("specialchar"));
newPasswordPolicy.setAttempts(rs.getInt("attempts"));
newPasswordPolicy.setDuration(rs.getInt("duration"));
newPasswordPolicy.setExpiration(rs.getInt("expiration"));
newPasswordPolicy.setUsername(rs.getInt("username"));
newPasswordPolicy.setHistory(rs.getInt("history"));
newPasswordPolicy.setDictionary(rs.getInt("dictionary"));
newPasswordPolicy.setAlphabetical(rs.getInt("alphabetical"));
newPasswordPolicy.setNumerical(rs.getInt("numerical"));
newPasswordPolicy.setQwerty(rs.getInt("qwerty"));
newPasswordPolicy.setOccurances(rs.getInt("occurances"));
return newPasswordPolicy;
}
}

View File

@@ -25,8 +25,8 @@ import org.dromara.maxkey.constants.ConstsPasswordSetType;
import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.crypto.password.PasswordGen;
import org.dromara.maxkey.entity.ChangePassword;
import org.dromara.maxkey.entity.PasswordPolicy;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.web.WebConstants;
import org.dromara.maxkey.web.WebContext;
import org.joda.time.DateTime;
@@ -41,7 +41,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.authentication.BadCredentialsException;
public class PasswordPolicyValidator {
private static Logger _logger = LoggerFactory.getLogger(PasswordPolicyValidator.class);
static final Logger _logger = LoggerFactory.getLogger(PasswordPolicyValidator.class);
PasswordPolicyRepository passwordPolicyRepository;
@@ -80,7 +80,12 @@ public class PasswordPolicyValidator {
String password = changePassword.getPassword();
String username = changePassword.getUsername();
if(password.equals("") || password==null){
if(StringUtils.isBlank(username)){
_logger.debug("username is Empty ");
return false;
}
if(StringUtils.isBlank(password)){
_logger.debug("password is Empty ");
return false;
}
@@ -113,7 +118,7 @@ public class PasswordPolicyValidator {
*/
public boolean passwordPolicyValid(UserInfo userInfo) {
PasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy();
CnfPasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy();
DateTime currentdateTime = new DateTime();
/*
@@ -163,7 +168,7 @@ public class PasswordPolicyValidator {
}
public void applyPasswordPolicy(UserInfo userInfo) {
PasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy();
CnfPasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy();
DateTime currentdateTime = new DateTime();
//initial password need change
@@ -282,7 +287,7 @@ public class PasswordPolicyValidator {
if (userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
userInfo.setBadPasswordCount(userInfo.getBadPasswordCount() + 1);
setBadPasswordCount(userInfo.getId(),userInfo.getBadPasswordCount());
PasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy();
CnfPasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy();
if(userInfo.getBadPasswordCount() >= passwordPolicy.getAttempts()) {
_logger.debug("Bad Password Count {} , Max Attempts {}",
userInfo.getBadPasswordCount() + 1,passwordPolicy.getAttempts());
@@ -300,7 +305,7 @@ public class PasswordPolicyValidator {
}
public String generateRandomPassword() {
PasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy();
CnfPasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy();
PasswordGen passwordGen = new PasswordGen(
passwordPolicy.getRandomPasswordLength()

View File

@@ -17,24 +17,26 @@
package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.PasswordPolicy;
import org.dromara.maxkey.persistence.mapper.PasswordPolicyMapper;
import org.dromara.maxkey.entity.Access;
import org.dromara.maxkey.persistence.mapper.AccessMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;
@Repository
public class PasswordPolicyService extends JpaService<PasswordPolicy>{
public PasswordPolicyService() {
super(PasswordPolicyMapper.class);
public class AccessService extends JpaService<Access>{
public AccessService() {
super(AccessMapper.class);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public PasswordPolicyMapper getMapper() {
return (PasswordPolicyMapper)super.getMapper();
public AccessMapper getMapper() {
return (AccessMapper)super.getMapper();
}
}

View File

@@ -25,7 +25,7 @@ import org.dromara.maxkey.crypto.password.PasswordReciprocal;
import org.dromara.maxkey.entity.Accounts;
import org.dromara.maxkey.entity.AccountsStrategy;
import org.dromara.maxkey.entity.OrganizationsCast;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.persistence.mapper.AccountsMapper;
import org.dromara.maxkey.provision.ProvisionAction;
import org.dromara.maxkey.provision.ProvisionService;

View File

@@ -21,7 +21,7 @@ import java.io.Serializable;
import java.util.List;
import org.dromara.maxkey.entity.AccountsStrategy;
import org.dromara.maxkey.entity.Roles;
import org.dromara.maxkey.entity.permissions.Roles;
import org.dromara.maxkey.persistence.mapper.AccountsStrategyMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.slf4j.Logger;

View File

@@ -17,25 +17,26 @@
package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.LdapContext;
import org.dromara.maxkey.persistence.mapper.LdapContextMapper;
import org.dromara.maxkey.entity.cnf.CnfEmailSenders;
import org.dromara.maxkey.persistence.mapper.CnfEmailSendersMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;
@Repository
public class LdapContextService extends JpaService<LdapContext>{
public class CnfEmailSendersService extends JpaService<CnfEmailSenders>{
public LdapContextService() {
super(LdapContextMapper.class);
public CnfEmailSendersService() {
super(CnfEmailSendersMapper.class);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public LdapContextMapper getMapper() {
return (LdapContextMapper)super.getMapper();
public CnfEmailSendersMapper getMapper() {
return (CnfEmailSendersMapper)super.getMapper();
}

View File

@@ -17,25 +17,25 @@
package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.SmsProvider;
import org.dromara.maxkey.persistence.mapper.SmsProviderMapper;
import org.dromara.maxkey.entity.cnf.CnfLdapContext;
import org.dromara.maxkey.persistence.mapper.CnfLdapContextMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;
@Repository
public class SmsProviderService extends JpaService<SmsProvider>{
public class CnfLdapContextService extends JpaService<CnfLdapContext>{
public SmsProviderService() {
super(SmsProviderMapper.class);
public CnfLdapContextService() {
super(CnfLdapContextMapper.class);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public SmsProviderMapper getMapper() {
return (SmsProviderMapper)super.getMapper();
public CnfLdapContextMapper getMapper() {
return (CnfLdapContextMapper)super.getMapper();
}

View File

@@ -17,26 +17,24 @@
package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.GroupPermissions;
import org.dromara.maxkey.persistence.mapper.GroupPermissionsMapper;
import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
import org.dromara.maxkey.persistence.mapper.CnfPasswordPolicyMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;
@Repository
public class GroupPermissionssService extends JpaService<GroupPermissions>{
public GroupPermissionssService() {
super(GroupPermissionsMapper.class);
}
public class CnfPasswordPolicyService extends JpaService<CnfPasswordPolicy>{
public CnfPasswordPolicyService() {
super(CnfPasswordPolicyMapper.class);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public GroupPermissionsMapper getMapper() {
return (GroupPermissionsMapper)super.getMapper();
public CnfPasswordPolicyMapper getMapper() {
return (CnfPasswordPolicyMapper)super.getMapper();
}
}

View File

@@ -17,26 +17,25 @@
package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.EmailSenders;
import org.dromara.maxkey.persistence.mapper.EmailSendersMapper;
import org.dromara.maxkey.entity.cnf.CnfSmsProvider;
import org.dromara.maxkey.persistence.mapper.CnfSmsProviderMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;
@Repository
public class EmailSendersService extends JpaService<EmailSenders>{
public class CnfSmsProviderService extends JpaService<CnfSmsProvider>{
public EmailSendersService() {
super(EmailSendersMapper.class);
public CnfSmsProviderService() {
super(CnfSmsProviderMapper.class);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public EmailSendersMapper getMapper() {
return (EmailSendersMapper)super.getMapper();
public CnfSmsProviderMapper getMapper() {
return (CnfSmsProviderMapper)super.getMapper();
}

View File

@@ -19,9 +19,9 @@ package org.dromara.maxkey.persistence.service;
import java.util.List;
import org.dromara.maxkey.entity.GroupMember;
import org.dromara.maxkey.entity.Groups;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.GroupMember;
import org.dromara.maxkey.entity.idm.Groups;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.persistence.mapper.GroupMemberMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.dromara.mybatis.jpa.entity.JpaPageResults;

View File

@@ -25,9 +25,9 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.entity.Groups;
import org.dromara.maxkey.entity.Institutions;
import org.dromara.maxkey.entity.Roles;
import org.dromara.maxkey.entity.idm.Groups;
import org.dromara.maxkey.entity.permissions.Roles;
import org.dromara.maxkey.persistence.mapper.GroupsMapper;
import org.dromara.maxkey.util.StrUtils;
import org.dromara.mybatis.jpa.JpaService;

View File

@@ -17,7 +17,7 @@
package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.HistoryConnector;
import org.dromara.maxkey.entity.history.HistoryConnector;
import org.dromara.maxkey.persistence.mapper.HistoryConnectorMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;

View File

@@ -17,7 +17,7 @@
package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.HistoryLoginApps;
import org.dromara.maxkey.entity.history.HistoryLoginApps;
import org.dromara.maxkey.persistence.mapper.HistoryLoginAppsMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;

View File

@@ -17,7 +17,7 @@
package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.HistoryLogin;
import org.dromara.maxkey.entity.history.HistoryLogin;
import org.dromara.maxkey.persistence.mapper.HistoryLoginMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.dromara.mybatis.jpa.entity.JpaPageResults;

View File

@@ -17,7 +17,7 @@
package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.HistorySynchronizer;
import org.dromara.maxkey.entity.history.HistorySynchronizer;
import org.dromara.maxkey.persistence.mapper.HistorySynchronizerMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;

View File

@@ -19,16 +19,19 @@ package org.dromara.maxkey.persistence.service;
import org.dromara.maxkey.entity.Accounts;
import org.dromara.maxkey.entity.ChangePassword;
import org.dromara.maxkey.entity.HistorySystemLogs;
import org.dromara.maxkey.entity.Organizations;
import org.dromara.maxkey.entity.Resources;
import org.dromara.maxkey.entity.RoleMember;
import org.dromara.maxkey.entity.GroupPermissions;
import org.dromara.maxkey.entity.GroupPrivileges;
import org.dromara.maxkey.entity.Roles;
import java.util.Date;
import org.dromara.maxkey.entity.Access;
import org.dromara.maxkey.entity.SocialsProvider;
import org.dromara.maxkey.entity.Synchronizers;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.history.HistorySystemLogs;
import org.dromara.maxkey.entity.idm.Organizations;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.entity.permissions.Permission;
import org.dromara.maxkey.entity.permissions.Resources;
import org.dromara.maxkey.entity.permissions.RoleMember;
import org.dromara.maxkey.entity.permissions.Roles;
import org.dromara.maxkey.persistence.mapper.HistorySystemLogsMapper;
import org.dromara.maxkey.util.JsonUtils;
import org.dromara.mybatis.jpa.JpaService;
@@ -38,16 +41,13 @@ import org.springframework.stereotype.Repository;
@Repository
public class HistorySystemLogsService extends JpaService<HistorySystemLogs>{
final static Logger _logger = LoggerFactory.getLogger(HistorySystemLogsService.class);
static final Logger _logger = LoggerFactory.getLogger(HistorySystemLogsService.class);
public HistorySystemLogsService() {
super(HistorySystemLogsMapper.class);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public HistorySystemLogsMapper getMapper() {
return (HistorySystemLogsMapper)super.getMapper();
@@ -56,28 +56,28 @@ public class HistorySystemLogsService extends JpaService<HistorySystemLogs>{
public void insert(String topic,Object entity,String action,String result,UserInfo operator) {
String message = "";
if(entity != null) {
if(entity instanceof UserInfo) {
message = buildMsg((UserInfo)entity);
}else if(entity instanceof Organizations) {
message = buildMsg((Organizations)entity);
}else if(entity instanceof ChangePassword) {
message = buildMsg((ChangePassword)entity);
}else if(entity instanceof Accounts) {
message = buildMsg((Accounts)entity);
}else if(entity instanceof Roles) {
message = buildMsg((Roles)entity);
}else if(entity instanceof RoleMember) {
message = buildMsg((RoleMember)entity);
}else if(entity instanceof GroupPermissions) {
message = buildMsg((GroupPermissions)entity);
}else if(entity instanceof Resources) {
message = buildMsg((Resources)entity);
}else if(entity instanceof Synchronizers) {
message = buildMsg((Synchronizers)entity);
}else if(entity instanceof SocialsProvider) {
message = buildMsg((SocialsProvider)entity);
}else if(entity instanceof GroupPrivileges) {
message = buildMsg((GroupPrivileges)entity);
if(entity instanceof UserInfo userInfo) {
message = buildMsg(userInfo);
}else if(entity instanceof Organizations organization) {
message = buildMsg(organization);
}else if(entity instanceof ChangePassword changePassword) {
message = buildMsg(changePassword);
}else if(entity instanceof Accounts account) {
message = buildMsg(account);
}else if(entity instanceof Roles role) {
message = buildMsg(role);
}else if(entity instanceof RoleMember roleMember) {
message = buildMsg(roleMember);
}else if(entity instanceof Access access) {
message = buildMsg(access);
}else if(entity instanceof Resources resource) {
message = buildMsg(resource);
}else if(entity instanceof Synchronizers synchronizer) {
message = buildMsg(synchronizer);
}else if(entity instanceof SocialsProvider socialsProvider) {
message = buildMsg(socialsProvider);
}else if(entity instanceof Permission permission) {
message = buildMsg(permission);
}else if(entity instanceof String) {
message = entity.toString();
}
@@ -99,6 +99,7 @@ public class HistorySystemLogsService extends JpaService<HistorySystemLogs>{
systemLog.setDisplayName(operator.getDisplayName());
systemLog.setInstId(operator.getInstId());
systemLog.setJsonCotent(JsonUtils.gsonToString(entity));
systemLog.setExecuteTime(new Date());
_logger.trace("System Log {}" ,systemLog);
getMapper().insert(systemLog);
}
@@ -157,7 +158,7 @@ public class HistorySystemLogsService extends JpaService<HistorySystemLogs>{
.toString();
}
public String buildMsg(GroupPermissions permission) {
public String buildMsg(Access permission) {
return new StringBuilder()
.append(permission.getGroupName())
.append("[")
@@ -166,7 +167,7 @@ public class HistorySystemLogsService extends JpaService<HistorySystemLogs>{
.toString();
}
public String buildMsg(GroupPrivileges privilege) {
public String buildMsg(Permission privilege) {
return new StringBuilder()
.append(privilege.getGroupId())
.append("[")

View File

@@ -25,7 +25,7 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.dromara.maxkey.entity.Organizations;
import org.dromara.maxkey.entity.idm.Organizations;
import org.dromara.maxkey.persistence.mapper.OrganizationsMapper;
import org.dromara.maxkey.provision.ProvisionAction;
import org.dromara.maxkey.provision.ProvisionService;

View File

@@ -0,0 +1,39 @@
package org.dromara.maxkey.persistence.service;
import java.util.List;
import org.dromara.maxkey.entity.permissions.PermissionRole;
import org.dromara.maxkey.persistence.mapper.PermissionRoleMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
@Repository
public class PermissionRoleService extends JpaService<PermissionRole>{
static final Logger _logger = LoggerFactory.getLogger(PermissionRoleService.class);
public PermissionRoleService() {
super(PermissionRoleMapper.class);
}
@Override
public PermissionRoleMapper getMapper() {
return (PermissionRoleMapper)super.getMapper();
}
public boolean insertPermissionRoles(List<PermissionRole> permissionRolesList) {
return getMapper().insertPermissionRoles(permissionRolesList)>0;
}
public boolean deletePermissionRoles(List<PermissionRole> permissionRolesList) {
return getMapper().deletePermissionRoles(permissionRolesList)>=0;
}
public List<PermissionRole> queryPermissionRoles(PermissionRole permissionRole){
return getMapper().queryPermissionRoles(permissionRole);
}
}

View File

@@ -19,39 +19,39 @@ package org.dromara.maxkey.persistence.service;
import java.util.List;
import org.dromara.maxkey.entity.GroupPrivileges;
import org.dromara.maxkey.persistence.mapper.GroupPrivilegesMapper;
import org.dromara.maxkey.entity.permissions.Permission;
import org.dromara.maxkey.persistence.mapper.PermissionMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
@Repository
public class GroupPrivilegesService extends JpaService<GroupPrivileges>{
final static Logger _logger = LoggerFactory.getLogger(GroupPrivilegesService.class);
public class PermissionService extends JpaService<Permission>{
static final Logger _logger = LoggerFactory.getLogger(PermissionService.class);
public GroupPrivilegesService() {
super(GroupPrivilegesMapper.class);
public PermissionService() {
super(PermissionMapper.class);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public GroupPrivilegesMapper getMapper() {
return (GroupPrivilegesMapper)super.getMapper();
public PermissionMapper getMapper() {
return (PermissionMapper)super.getMapper();
}
public boolean insertGroupPrivileges(List<GroupPrivileges> rolePermissionsList) {
public boolean insertGroupPrivileges(List<Permission> rolePermissionsList) {
return getMapper().insertGroupPrivileges(rolePermissionsList)>0;
};
public boolean deleteGroupPrivileges(List<GroupPrivileges> rolePermissionsList) {
public boolean deleteGroupPrivileges(List<Permission> rolePermissionsList) {
return getMapper().deleteGroupPrivileges(rolePermissionsList)>=0;
}
public List<GroupPrivileges> queryGroupPrivileges(GroupPrivileges rolePermissions){
public List<Permission> queryGroupPrivileges(Permission rolePermissions){
return getMapper().queryGroupPrivileges(rolePermissions);
}

View File

@@ -20,7 +20,7 @@ package org.dromara.maxkey.persistence.service;
import java.util.List;
import org.dromara.maxkey.entity.Register;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.persistence.mapper.RegisterMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;

View File

@@ -19,7 +19,7 @@ package org.dromara.maxkey.persistence.service;
import java.util.List;
import org.dromara.maxkey.entity.Resources;
import org.dromara.maxkey.entity.permissions.Resources;
import org.dromara.maxkey.persistence.mapper.ResourcesMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;

View File

@@ -0,0 +1,70 @@
package org.dromara.maxkey.persistence.service;
import java.util.List;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.entity.permissions.RoleMember;
import org.dromara.maxkey.entity.permissions.Roles;
import org.dromara.maxkey.persistence.mapper.RoleMemberMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.dromara.mybatis.jpa.entity.JpaPageResults;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
@Repository
public class RoleMemberService extends JpaService<RoleMember>{
final static Logger _logger = LoggerFactory.getLogger(RoleMemberService.class);
public RoleMemberService() {
super(RoleMemberMapper.class);
}
@Override
public RoleMemberMapper getMapper() {
return (RoleMemberMapper)super.getMapper();
}
public int addDynamicRoleMember(Roles dynamicGroup) {
return getMapper().addDynamicRoleMember(dynamicGroup);
}
public int deleteDynamicRoleMember(Roles dynamicGroup) {
return getMapper().deleteDynamicRoleMember(dynamicGroup);
}
public int deleteByRoleId(String groupId) {
return getMapper().deleteByRoleId(groupId);
}
public List<UserInfo> queryMemberByRoleId(String groupId){
return getMapper().queryMemberByRoleId(groupId);
}
public JpaPageResults<Roles> rolesNoMember(RoleMember entity) {
entity.setPageSelectId(entity.generateId());
entity.setStartRow(calculateStartRow(entity.getPageNumber() ,entity.getPageSize()));
entity.setPageable(true);
List<Roles> resultslist = null;
try {
resultslist = getMapper().rolesNoMember(entity);
} catch (Exception e) {
_logger.error("fetchPageResults Exception " , e);
}
entity.setPageable(false);
Integer totalPage = resultslist.size();
Integer totalCount = 0;
if(entity.getPageNumber() == 1 && totalPage < entity.getPageSize()) {
totalCount = totalPage;
}else {
totalCount = parseCount(getMapper().fetchCount(entity));
}
return new JpaPageResults<Roles>(entity.getPageNumber(),entity.getPageSize(),totalPage,totalCount,resultslist);
}
}

View File

@@ -0,0 +1,144 @@
package org.dromara.maxkey.persistence.service;
import java.io.Serializable;
import java.sql.Types;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.entity.Institutions;
import org.dromara.maxkey.entity.permissions.Roles;
import org.dromara.maxkey.persistence.mapper.RolesMapper;
import org.dromara.maxkey.util.StrUtils;
import org.dromara.mybatis.jpa.JpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Repository
public class RolesService extends JpaService<Roles> implements Serializable {
/**
*
*/
private static final long serialVersionUID = -4156671926199393550L;
static final Logger _logger = LoggerFactory.getLogger(RolesService.class);
@JsonIgnore
@Autowired
RoleMemberService roleMemberService;
@Autowired
InstitutionsService institutionsService;
public RolesService() {
super(RolesMapper.class);
}
@Override
public RolesMapper getMapper() {
return (RolesMapper)super.getMapper();
}
public List<Roles> queryDynamicRoles(Roles groups){
return this.getMapper().queryDynamicRoles(groups);
}
public boolean deleteById(String groupId) {
this.delete(groupId);
roleMemberService.deleteByRoleId(groupId);
return true;
}
public List<Roles> queryRolesByUserId(String userId){
return this.getMapper().queryRolesByUserId(userId);
}
public void refreshDynamicRoles(Roles dynamicRole){
if(dynamicRole.getCategory().equals(Roles.Category.DYNAMIC)) {
boolean isDynamicTimeSupport = false;
boolean isBetweenEffectiveTime = false;
if(StringUtils.isNotBlank(dynamicRole.getResumeTime())
&&StringUtils.isNotBlank(dynamicRole.getSuspendTime())
&&!dynamicRole.getSuspendTime().equals("00:00")) {
LocalTime currentTime = LocalDateTime.now().toLocalTime();
LocalTime resumeTime = LocalTime.parse(dynamicRole.getResumeTime());
LocalTime suspendTime = LocalTime.parse(dynamicRole.getSuspendTime());
_logger.info("currentTime: {} , resumeTime : {} , suspendTime: {}" ,
currentTime , resumeTime , suspendTime);
isDynamicTimeSupport = true;
if(resumeTime.isBefore(currentTime) && currentTime.isBefore(suspendTime)) {
isBetweenEffectiveTime = true;
}
}
if(StringUtils.isNotBlank(dynamicRole.getOrgIdsList())) {
String []orgIds = dynamicRole.getOrgIdsList().split(",");
StringBuffer orgIdFilters = new StringBuffer();
for(String orgId : orgIds) {
if(StringUtils.isNotBlank(orgId)) {
if(orgIdFilters.length() > 0) {
orgIdFilters.append(",");
}
orgIdFilters.append("'").append(orgId).append("'");
}
}
if(orgIdFilters.length() > 0) {
dynamicRole.setOrgIdsList(orgIdFilters.toString());
}
}
String filters = dynamicRole.getFilters();
_logger.debug("filters {}" , filters);
if(StringUtils.isNotBlank(filters)) {
if(StrUtils.filtersSQLInjection(filters.toLowerCase())) {
_logger.info("filters include SQL Injection Attack Risk.");
return;
}
filters = filters.replace("&", " AND ");
filters = filters.replaceAll("\\|", " OR ");
_logger.debug("set filters {}" , filters);
dynamicRole.setFilters(filters);
}
if(isDynamicTimeSupport) {
if(isBetweenEffectiveTime) {
roleMemberService.deleteDynamicRoleMember(dynamicRole);
roleMemberService.addDynamicRoleMember(dynamicRole);
}else {
roleMemberService.deleteDynamicRoleMember(dynamicRole);
}
}else{
roleMemberService.deleteDynamicRoleMember(dynamicRole);
roleMemberService.addDynamicRoleMember(dynamicRole);
}
}
}
public void refreshAllDynamicRoles(){
List<Institutions> instList =
institutionsService.find("where status = ? ", new Object[]{ConstsStatus.ACTIVE}, new int[]{Types.INTEGER});
for(Institutions inst : instList) {
Roles role = new Roles();
role.setInstId(inst.getId());
List<Roles> rolesList = queryDynamicRoles(role);
for(Roles r : rolesList) {
_logger.debug("role {}" , r);
refreshDynamicRoles(r);
}
}
}
}

View File

@@ -20,7 +20,7 @@ package org.dromara.maxkey.persistence.service;
import java.util.List;
import org.dromara.maxkey.entity.SocialsAssociate;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.persistence.mapper.SocialsAssociateMapper;
import org.dromara.mybatis.jpa.JpaService;
import org.springframework.stereotype.Repository;

View File

@@ -21,9 +21,9 @@ import java.sql.Types;
import java.util.Date;
import java.util.List;
import org.dromara.maxkey.entity.Organizations;
import org.dromara.maxkey.entity.SynchroRelated;
import org.dromara.maxkey.entity.Synchronizers;
import org.dromara.maxkey.entity.idm.Organizations;
import org.dromara.maxkey.persistence.mapper.SynchroRelatedMapper;
import org.dromara.maxkey.util.DateUtils;
import org.dromara.mybatis.jpa.JpaService;

View File

@@ -26,7 +26,7 @@ import org.dromara.maxkey.constants.ConstsStatus;
import org.dromara.maxkey.crypto.password.PasswordReciprocal;
import org.dromara.maxkey.entity.Accounts;
import org.dromara.maxkey.entity.ChangePassword;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.persistence.mapper.UserInfoMapper;
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
import org.dromara.maxkey.provision.ProvisionAction;

View File

@@ -25,8 +25,8 @@ import org.dromara.maxkey.crypto.password.PasswordReciprocal;
import org.dromara.maxkey.entity.ChangePassword;
import org.dromara.maxkey.entity.Connectors;
import org.dromara.maxkey.entity.Message;
import org.dromara.maxkey.entity.Organizations;
import org.dromara.maxkey.entity.UserInfo;
import org.dromara.maxkey.entity.idm.Organizations;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.persistence.service.ConnectorsService;
import org.dromara.maxkey.provision.ProvisionAction;
import org.dromara.maxkey.provision.ProvisionMessage;

Some files were not shown because too many files have changed in this diff Show More