From d254e8a27dc1a18aea653f33da18c25101a8996c Mon Sep 17 00:00:00 2001 From: shimingxy Date: Thu, 2 Apr 2020 00:22:31 +0800 Subject: [PATCH] v1.3 RC --- .../config/CharacterEncodingConfig.java | 143 ++++----- .../org/maxkey/config/DataSoruceConfig.java | 286 +++++++++--------- .../java/org/maxkey/config/EmailConfig.java | 178 ++++++----- .../java/org/maxkey/config/LoginConfig.java | 14 +- .../oidc/OIDCProviderMetadataDetails.java | 122 ++++---- .../maxkey/web/InitApplicationContext.java | 22 +- 6 files changed, 375 insertions(+), 390 deletions(-) diff --git a/maxkey-core/src/main/java/org/maxkey/config/CharacterEncodingConfig.java b/maxkey-core/src/main/java/org/maxkey/config/CharacterEncodingConfig.java index 994dc0c2b..6bfaf4e73 100644 --- a/maxkey-core/src/main/java/org/maxkey/config/CharacterEncodingConfig.java +++ b/maxkey-core/src/main/java/org/maxkey/config/CharacterEncodingConfig.java @@ -1,104 +1,83 @@ -/** - * - */ package org.maxkey.config; import java.io.UnsupportedEncodingException; - import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; /** - * 字符集转换及转换配置 + * 字符集转换及转换配置. + * * @author Crystal.Sea * */ @Configuration @PropertySource("classpath:/config/applicationConfig.properties") public class CharacterEncodingConfig { - - /** - * 源字符集 - */ - @Value("${config.characterencoding.charset.from}") - String fromCharSet; - - /** - * 目标字符集 - */ - @Value("${config.characterencoding.charset.to}") - String toCharSet; - - /** - * 转换标志 - */ - @Value("${config.characterencoding.encoding}") - boolean encoding = false; - - public CharacterEncodingConfig() { - - } + /** + * 源字符集. + */ + @Value("${config.characterencoding.charset.from}") + String fromCharSet; - /** - * @return the fromCharSet - */ - public String getFromCharSet() { - return fromCharSet; - } + /** + * 目标字符集. + */ + @Value("${config.characterencoding.charset.to}") + String toCharSet; - /** - * @param fromCharSet the fromCharSet to set - */ - public void setFromCharSet(String fromCharSet) { - this.fromCharSet = fromCharSet; - } + /** + * 转换标志. + */ + @Value("${config.characterencoding.encoding}") + boolean encoding = false; - /** - * @return the toCharSet - */ - public String getToCharSet() { - return toCharSet; - } + public CharacterEncodingConfig() { - /** - * @param toCharSet the toCharSet to set - */ - public void setToCharSet(String toCharSet) { - this.toCharSet = toCharSet; - } + } - /** - * @return the encoding - */ - public boolean isEncoding() { - return encoding; - } + public String getFromCharSet() { + return fromCharSet; + } + + public void setFromCharSet(String fromCharSet) { + this.fromCharSet = fromCharSet; + } + + public String getToCharSet() { + return toCharSet; + } + + public void setToCharSet(String toCharSet) { + this.toCharSet = toCharSet; + } + + public boolean isEncoding() { + return encoding; + } + + public void setEncoding(boolean encoding) { + this.encoding = encoding; + } + + /** + * 字符集转换. + * + * @param encodingString 源字符串 + * @return encoded目标字符串 + */ + public String encoding(String encodingString) { + if (!this.encoding || encodingString == null) { + return encodingString; + } + + try { + return new String(encodingString.getBytes(this.fromCharSet), this.toCharSet); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return null; + } - /** - * @param encoding the encoding to set - */ - public void setEncoding(boolean encoding) { - this.encoding = encoding; - } - - /** - * 字符集转换 - * @param encodingString 源字符串 - * @return encoded目标字符串 - */ - public String encoding(String encodingString){ - if(!this.encoding||encodingString==null) { - return encodingString; - } - - try { - return new String(encodingString.getBytes(this.fromCharSet),this.toCharSet); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return null; - } - } diff --git a/maxkey-core/src/main/java/org/maxkey/config/DataSoruceConfig.java b/maxkey-core/src/main/java/org/maxkey/config/DataSoruceConfig.java index 517fba6a7..bbc0419e1 100644 --- a/maxkey-core/src/main/java/org/maxkey/config/DataSoruceConfig.java +++ b/maxkey-core/src/main/java/org/maxkey/config/DataSoruceConfig.java @@ -7,177 +7,171 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -/** - * 数据源配置 +/* + * 数据源配置. * - * @author Crystal.Sea - * dataSource.driverClassName=com.mysql.jdbc.Driver - * dataSource.url=jdbc:mysql://192.168.1.49/parasecdb?autoReconnect=true&characterEncoding=UTF-8 - * dataSource.username=root - * dataSource.password=connsec - * dataSource.type=mysql - * - */ -/** - * @author Crystal.Sea + * @author Crystal.Sea + * dataSource.driverClassName=com.mysql.jdbc.Driver + * dataSource.url=jdbc:mysql://192.168.1.49/parasecdb?autoReconnect=true&characterEncoding=UTF-8 + * dataSource.username=root + * dataSource.password=connsec + * dataSource.type=mysql * */ @Configuration @PropertySource("classpath:/config/applicationConfig.properties") public class DataSoruceConfig { - - /** - * 数据库类型 - */ - @Value("${config.datasource.database:mysql}") - String database; - /** - * jdbc驱动类 - */ - @Value("${config.datasource.driverclass:com.mysql.jdbc.Driver}") - String driverClass; - /** - * jdbc连接地址 - */ - @Value("${config.datasource.url:jdbc:mysql://localhost/maxkey?autoReconnect=true&characterEncoding=UTF-8}") - String url; - /** - * 数据库用户名 - */ - @Value("${config.datasource.username:root}") - String username; - /** - * 数据库密码 - */ - @Value("${config.datasource.password:maxkey}") - String password; - - /** - * 数据库密码是否加密 - */ - @Value("${config.datasource.password.encrypt}") - boolean encrypt=false; - - /** - * 数据库dialect for mybatis - */ - String dialect; - - - public DataSoruceConfig() { - super(); - } - + /* + * 数据库类型 + */ + @Value("${config.datasource.database:mysql}") + String database; + /* + * jdbc驱动类 + */ + @Value("${config.datasource.driverclass:com.mysql.jdbc.Driver}") + String driverClass; + /* + * jdbc连接地址 + */ + @Value("${config.datasource.url:" + + "jdbc:mysql://localhost/maxkey?autoReconnect=true&characterEncoding=UTF-8}") + String url; + /* + * 数据库用户名 + */ + @Value("${config.datasource.username:root}") + String username; + /* + * 数据库密码 + */ + @Value("${config.datasource.password:maxkey}") + String password; - public String getUrl() { - return url; - } - public void setUrl(String url) { - this.url = url; - } - public String getUsername() { - return username; - } - public void setUsername(String username) { - this.username = username; - } - - /** - * 取得数据库密码 - * 如果是加密密码(encrypt==true),则进行解密 - * @return decodePassword - */ - public String getPassword() { - String decodePassword=""; - LogFactory.getLog(DataSoruceConfig.class).debug("password is "+password); - if(encrypt){ - decodePassword = PasswordReciprocal.getInstance().decoder(password); - }else{ - decodePassword= password; - } - LogFactory.getLog(DataSoruceConfig.class).debug("password is "+password+" , decodePassword is "+decodePassword); - return decodePassword; - } - - public void setPassword(String password) { - this.password = password; - } + /* + * 数据库密码是否加密 + */ + @Value("${config.datasource.password.encrypt}") + boolean encrypt = false; + /* + * 数据库dialect for mybatis + */ + String dialect; - /** - * @return the database - */ - public String getDatabase() { - return database; - } + public DataSoruceConfig() { + super(); + } + public String getUrl() { + return url; + } - /** - * @param database the database to set - */ - public void setDatabase(String database) { - this.database = database; + public void setUrl(String url) { + this.url = url; + } - } + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } - /** - * @return the driverClass - */ - public String getDriverClass() { - return driverClass; - } + /** + * 取得数据库密码 如果是加密密码(encrypt==true),则进行解密. + * + * @return decodePassword + */ + public String getPassword() { + String decodePassword = ""; + LogFactory.getLog(DataSoruceConfig.class).debug("password is " + password); + if (encrypt) { + decodePassword = PasswordReciprocal.getInstance().decoder(password); + } else { + decodePassword = password; + } + LogFactory.getLog(DataSoruceConfig.class) + .debug("password is " + password + " , decodePassword is " + decodePassword); + return decodePassword; + } + public void setPassword(String password) { + this.password = password; + } - /** - * @param driverClass the driverClass to set - */ - public void setDriverClass(String driverClass) { - this.driverClass = driverClass; - } + /* + * + * @return the database + */ + public String getDatabase() { + return database; + } + /* + * @param database the database to set + */ + public void setDatabase(String database) { + this.database = database; - public boolean isEncrypt() { - return encrypt; - } + } - public void setEncrypt(boolean encrypt) { - this.encrypt = encrypt; - } + /* + * @return the driverClass + */ + public String getDriverClass() { + return driverClass; + } - + /* + * @param driverClass the driverClass to set + */ + public void setDriverClass(String driverClass) { + this.driverClass = driverClass; + } - /** - * @return the dialect - */ - public String getDialect() { - if(this.dialect==null) { - this.dialect=Dialect.getDialectMap().get(database); - } - return dialect; - } + public boolean isEncrypt() { + return encrypt; + } + public void setEncrypt(boolean encrypt) { + this.encrypt = encrypt; + } - /** - * @param dialect the dialect to set - */ - public void setDialect(String dialect) { - this.dialect = dialect; - } + /** + * getDialect. + * @return the dialect + */ + public String getDialect() { + if (this.dialect == null) { + this.dialect = Dialect.getDialectMap().get(database); + } + return dialect; + } + /* + * @param dialect the dialect to set + */ + public void setDialect(String dialect) { + this.dialect = dialect; + } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "DataSoruceConfig [database=" + database + ", driverClass=" - + driverClass + ", url=" + url + ", username=" + username - + ", password=" + password + ", encrypt=" + encrypt + "]"; - } + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "DataSoruceConfig [database=" + database + + ", driverClass=" + driverClass + + ", url=" + url + + ", username=" + username + + ", password=" + password + + ", encrypt=" + encrypt + + "]"; + } - - - } diff --git a/maxkey-core/src/main/java/org/maxkey/config/EmailConfig.java b/maxkey-core/src/main/java/org/maxkey/config/EmailConfig.java index 793dc9b1c..d078398f9 100644 --- a/maxkey-core/src/main/java/org/maxkey/config/EmailConfig.java +++ b/maxkey-core/src/main/java/org/maxkey/config/EmailConfig.java @@ -8,109 +8,105 @@ import org.springframework.context.annotation.PropertySource; @PropertySource("classpath:/config/applicationConfig.properties") public class EmailConfig { - @Value("${config.email.username}") - private String username; - @Value("${config.email.password}") - private String password; - @Value("${config.email.smtpHost}") - private String smtpHost; - @Value("${config.email.senderMail}") - private String senderMail; - @Value("${config.email.port}") - private Integer port; - @Value("${config.email.ssl}") - private boolean ssl; - - + @Value("${config.email.username}") + private String username; + @Value("${config.email.password}") + private String password; + @Value("${config.email.smtpHost}") + private String smtpHost; + @Value("${config.email.senderMail}") + private String senderMail; + @Value("${config.email.port}") + private Integer port; + @Value("${config.email.ssl}") + private boolean ssl; - public EmailConfig() { - // TODO Auto-generated constructor stub - } + public EmailConfig() { + // TODO Auto-generated constructor stub + } - /** - * @return the username - */ - public String getUsername() { - return username; - } + /* + * @return the username + */ + public String getUsername() { + return username; + } - /** - * @param username the username to set - */ - public void setUsername(String username) { - this.username = username; - } + /* + * @param username the username to set + */ + public void setUsername(String username) { + this.username = username; + } - /** - * @return the password - */ - public String getPassword() { - return password; - } + /* + * @return the password + */ + public String getPassword() { + return password; + } - /** - * @param password the password to set - */ - public void setPassword(String password) { - this.password = password; - } + /* + * @param password the password to set + */ + public void setPassword(String password) { + this.password = password; + } + /* + * @return the smtpHost + */ + public String getSmtpHost() { + return smtpHost; + } - /** - * @return the smtpHost - */ - public String getSmtpHost() { - return smtpHost; - } + /* + * @param smtpHost the smtpHost to set + */ + public void setSmtpHost(String smtpHost) { + this.smtpHost = smtpHost; + } - /** - * @param smtpHost the smtpHost to set - */ - public void setSmtpHost(String smtpHost) { - this.smtpHost = smtpHost; - } + /* + * @return the senderMail + */ + public String getSenderMail() { + return senderMail; + } - /** - * @return the senderMail - */ - public String getSenderMail() { - return senderMail; - } + /* + * @param senderMail the senderMail to set + */ + public void setSenderMail(String senderMail) { + this.senderMail = senderMail; + } - /** - * @param senderMail the senderMail to set - */ - public void setSenderMail(String senderMail) { - this.senderMail = senderMail; - } + /* + * @return the port + */ + public Integer getPort() { + return port; + } - /** - * @return the port - */ - public Integer getPort() { - return port; - } + /* + * @param port the port to set + */ + public void setPort(Integer port) { + this.port = port; + } - /** - * @param port the port to set - */ - public void setPort(Integer port) { - this.port = port; - } + /* + * @return the ssl + */ + public boolean isSsl() { + return ssl; + } - /** - * @return the ssl - */ - public boolean isSsl() { - return ssl; - } + /* + * @param ssl the ssl to set + */ + public void setSsl(boolean ssl) { + this.ssl = ssl; + } - /** - * @param ssl the ssl to set - */ - public void setSsl(boolean ssl) { - this.ssl = ssl; - } - - } diff --git a/maxkey-core/src/main/java/org/maxkey/config/LoginConfig.java b/maxkey-core/src/main/java/org/maxkey/config/LoginConfig.java index 035b32770..d2d8057cc 100644 --- a/maxkey-core/src/main/java/org/maxkey/config/LoginConfig.java +++ b/maxkey-core/src/main/java/org/maxkey/config/LoginConfig.java @@ -87,8 +87,16 @@ public class LoginConfig { @Override public String toString() { - return "LoginConfig [captcha=" + captcha + ", oneTimePwd=" + oneTimePwd + ", socialSignOn=" + socialSignOn - + ", kerberos=" + kerberos + ", remeberMe=" + remeberMe + ", wsFederation=" + wsFederation - + ", defaultUri=" + defaultUri + "]"; + StringBuilder builder = new StringBuilder(); + builder + .append("LoginConfig [captcha=").append(captcha) + .append(", oneTimePwd=").append(oneTimePwd) + .append(", socialSignOn=").append(socialSignOn) + .append(", kerberos=").append(kerberos) + .append(", remeberMe=").append(remeberMe) + .append(", wsFederation=").append(wsFederation) + .append(", defaultUri=").append(defaultUri).append("]"); + return builder.toString(); } + } diff --git a/maxkey-core/src/main/java/org/maxkey/config/oidc/OIDCProviderMetadataDetails.java b/maxkey-core/src/main/java/org/maxkey/config/oidc/OIDCProviderMetadataDetails.java index f565c215e..be01a63d7 100644 --- a/maxkey-core/src/main/java/org/maxkey/config/oidc/OIDCProviderMetadataDetails.java +++ b/maxkey-core/src/main/java/org/maxkey/config/oidc/OIDCProviderMetadataDetails.java @@ -1,96 +1,94 @@ -/** - * - */ package org.maxkey.config.oidc; import java.net.URI; import java.util.Set; /** - * @author Hiro + * OIDCProviderMetadataDetails. + * @author cm * */ public class OIDCProviderMetadataDetails implements OIDCProviderMetadata { - protected String issuer; + protected String issuer; - protected URI authorizationEndpoint; + protected URI authorizationEndpoint; - protected URI tokenEndpoint; + protected URI tokenEndpoint; - protected URI userinfoEndpoint; + protected URI userinfoEndpoint; - protected URI jwksUri; + protected URI jwksUri; - protected URI registrationEndpoint; + protected URI registrationEndpoint; - protected Set scopesSupported; + protected Set scopesSupported; - protected Set responseTypesSupported; + protected Set responseTypesSupported; - public String getIssuer() { - return issuer; - } + public String getIssuer() { + return issuer; + } - public void setIssuer(String issuer) { - this.issuer = issuer; - } + public void setIssuer(String issuer) { + this.issuer = issuer; + } - public URI getAuthorizationEndpoint() { - return authorizationEndpoint; - } + public URI getAuthorizationEndpoint() { + return authorizationEndpoint; + } - public void setAuthorizationEndpoint(URI authorizationEndpoint) { - this.authorizationEndpoint = authorizationEndpoint; - } + public void setAuthorizationEndpoint(URI authorizationEndpoint) { + this.authorizationEndpoint = authorizationEndpoint; + } - public URI getTokenEndpoint() { - return tokenEndpoint; - } + public URI getTokenEndpoint() { + return tokenEndpoint; + } - public void setTokenEndpoint(URI tokenEndpoint) { - this.tokenEndpoint = tokenEndpoint; - } + public void setTokenEndpoint(URI tokenEndpoint) { + this.tokenEndpoint = tokenEndpoint; + } - public URI getUserinfoEndpoint() { - return userinfoEndpoint; - } + public URI getUserinfoEndpoint() { + return userinfoEndpoint; + } - public void setUserinfoEndpoint(URI userinfoEndpoint) { - this.userinfoEndpoint = userinfoEndpoint; - } + public void setUserinfoEndpoint(URI userinfoEndpoint) { + this.userinfoEndpoint = userinfoEndpoint; + } - public URI getJwksUri() { - return jwksUri; - } + public URI getJwksUri() { + return jwksUri; + } - public void setJwksUri(URI jwksUri) { - this.jwksUri = jwksUri; - } + public void setJwksUri(URI jwksUri) { + this.jwksUri = jwksUri; + } - public URI getRegistrationEndpoint() { - return registrationEndpoint; - } + public URI getRegistrationEndpoint() { + return registrationEndpoint; + } - public void setRegistrationEndpoint(URI registrationEndpoint) { - this.registrationEndpoint = registrationEndpoint; - } + public void setRegistrationEndpoint(URI registrationEndpoint) { + this.registrationEndpoint = registrationEndpoint; + } - public Set getScopesSupported() { - return scopesSupported; - } + public Set getScopesSupported() { + return scopesSupported; + } - public void setScopesSupported(Set scopesSupported) { - this.scopesSupported = scopesSupported; - } + public void setScopesSupported(Set scopesSupported) { + this.scopesSupported = scopesSupported; + } - public Set getResponseTypesSupported() { - return responseTypesSupported; - } + public Set getResponseTypesSupported() { + return responseTypesSupported; + } - public void setResponseTypesSupported(Set responseTypesSupported) { - this.responseTypesSupported = responseTypesSupported; - } + public void setResponseTypesSupported(Set responseTypesSupported) { + this.responseTypesSupported = responseTypesSupported; + } - // TODO: Complete remaining properties from - // http://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata + // TODO: Complete remaining properties from + // http://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata } diff --git a/maxkey-core/src/main/java/org/maxkey/web/InitApplicationContext.java b/maxkey-core/src/main/java/org/maxkey/web/InitApplicationContext.java index 42c1171c6..a9c5f0a2b 100644 --- a/maxkey-core/src/main/java/org/maxkey/web/InitApplicationContext.java +++ b/maxkey-core/src/main/java/org/maxkey/web/InitApplicationContext.java @@ -1,6 +1,3 @@ -/** - * - */ package org.maxkey.web; import java.sql.Connection; @@ -11,11 +8,9 @@ import java.util.Properties; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; - import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; - import org.maxkey.cache.CacheFactory; import org.maxkey.util.PathUtils; import org.slf4j.Logger; @@ -27,6 +22,7 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.web.context.support.WebApplicationContextUtils; /** + * InitApplicationContext . * @author Crystal.Sea * */ @@ -71,6 +67,9 @@ public class InitApplicationContext extends HttpServlet { this.applicationContext = applicationContext; } + /** + * loadCaches. + */ public void loadCaches() { _logger.info( "----------------------------------------------------------------------------------------------------"); @@ -89,6 +88,9 @@ public class InitApplicationContext extends HttpServlet { } + /** + * listDataBaseVariables. + */ public void listDataBaseVariables() { if (applicationContext.containsBean("dataSource")) { try { @@ -122,7 +124,9 @@ public class InitApplicationContext extends HttpServlet { } } - // propertySourcesPlaceholderConfigurer + /** + * propertySourcesPlaceholderConfigurer. + */ public void listProperties() { if (applicationContext.containsBean("propertySourcesPlaceholderConfigurer")) { _logger.debug( @@ -149,6 +153,9 @@ public class InitApplicationContext extends HttpServlet { } } + /** + * listEnvVars. + */ public void listEnvVars() { _logger.debug( "----------------------------------------------------------------------------------------------------"); @@ -169,6 +176,9 @@ public class InitApplicationContext extends HttpServlet { "----------------------------------------------------------------------------------------------------"); } + /** + * showLicense. + */ public void showLicense() { _logger.info( "----------------------------------------------------------------------------------------------------");