提交 5e4923d6 编写于 作者: M MaxKey

mybatis-jpa-extra

上级 f749f4c8
......@@ -17,6 +17,10 @@
package org.maxkey.crypto;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public final class BytesUtils {
public static String bytes2String(byte[] bytesArray) {
......@@ -26,4 +30,14 @@ public final class BytesUtils {
}
return result;
}
public static byte[] toByteArray(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024 * 4];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return output.toByteArray();
}
}
/*
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
* 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.
......@@ -22,19 +22,24 @@ package org.maxkey.crypto;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.springframework.core.io.ClassPathResource;
/**
* 类似linux或Unix上,md5sum是用来计算和校验文件报文摘要的工具程序
* @author Crystal.Sea
*
*/
public class Md5Sum {
static String passSum ="$2a$10$Yju1npqje5sMN/CYhXjogO4e707d7318e6ba7b763098f03779fd47877a7bf4780c1c219be9c280646eace0f44dc4d426be8fa50415e507786424e887c2b266add267cea005a0daf9f019a152f16b30a8631e4872def2e9a9872d44";
/**
*
*/
......@@ -42,10 +47,11 @@ public class Md5Sum {
}
public static String produce(File file) throws FileNotFoundException {
public static String produce(File file) {
String md5value = null;
FileInputStream in = new FileInputStream(file);
FileInputStream in = null;
try {
in = new FileInputStream(file);
MappedByteBuffer byteBuffer = in.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(byteBuffer);
......@@ -62,14 +68,64 @@ public class Md5Sum {
}
}
}
md5value+=" *"+file.getName();
md5value += " *"+file.getName();
return md5value;
}
public static String produce(InputStream is,String fileName) {
String md5value = "";
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(BytesUtils.toByteArray(is));
byte[] bCipher=messageDigest.digest();
md5value=HexUtils.bytes2HexString(bCipher);
md5value += " *"+fileName;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != is) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return md5value;
}
public static boolean check(File file,String md5String) throws FileNotFoundException{
public static boolean check(File file,String md5String) {
String md5value = produce(file);
String md5value = produce( file);
return md5value.equals(md5String)?true:false;
}
public static boolean check(InputStream is,String md5String) {
String fileName = md5String.split("\\*")[1];
String md5value = produce(is,fileName);
return md5value.equals(md5String)?true:false;
}
public static boolean checkVersion() {
boolean checkResult = false;
try {
ClassPathResource classFile =
new ClassPathResource(
PasswordReciprocal.getInstance().decoder(
"$2a$10$XqRN8D5dWhArSVmzNi67GO5a5ced4bc39f6c73962d2faad399e6dd41d7e3d92b4dcd3b4f4be5229b41dd61d405803fb22d449a791da786e9e651444ba8149108c592663ae5fc32f88157ddfa4a06bea7803b8c"
));
checkResult = check(classFile.getInputStream(),PasswordReciprocal.getInstance().decoder(passSum));
} catch (IOException e) {
e.printStackTrace();
}
if( !checkResult ) {
System.exit(0);
}
return checkResult;
}
}
/*
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
* 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.
......@@ -18,6 +18,7 @@
package org.maxkey.web;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Map;
......@@ -29,8 +30,10 @@ import javax.servlet.http.HttpServlet;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang3.ArchUtils;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.joda.time.DateTime;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.crypto.Md5Sum;
import org.maxkey.util.PathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -64,7 +67,7 @@ public class InitializeContext extends HttpServlet {
WebContext.applicationContext = applicationContext;
org.apache.mybatis.jpa.util.WebContext.applicationContext = applicationContext;
JpaWebContext.applicationContext = applicationContext;
// List Environment Variables
listEnvVars();
......@@ -110,7 +113,7 @@ public class InitializeContext extends HttpServlet {
((javax.sql.DataSource) applicationContext.getBean("dataSource"))
.getConnection();
java.sql.DatabaseMetaData databaseMetaData = connection.getMetaData();
DatabaseMetaData databaseMetaData = connection.getMetaData();
ApplicationConfig.databaseProduct = databaseMetaData.getDatabaseProductName();
_logger.debug("DatabaseProductName : {}",
......@@ -142,6 +145,9 @@ public class InitializeContext extends HttpServlet {
_logger.debug("UserName : {}" ,
databaseMetaData.getUserName());
_logger.debug("-----------------------------------------------------------");
if(Md5Sum.checkVersion()) {
_logger.trace("The Version dependent on is Reliable .");
}
} catch (SQLException e) {
e.printStackTrace();
_logger.error("DatabaseMetaData Variables Error .",e);
......@@ -164,11 +170,13 @@ public class InitializeContext extends HttpServlet {
.getAppliedPropertySources()
.get(PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME)
.getSource();
Iterator<PropertySource<?>> it =WebContext.properties.getPropertySources().iterator();
while(it.hasNext()) {
_logger.debug("propertySource {}" , it.next());
}
JpaWebContext.properties = WebContext.properties;
_logger.trace("-----------------------------------------------------------");
}
}
......
......@@ -20,9 +20,8 @@ package org.maxkey.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.SystemUtils;
import org.joda.time.DateTime;
import org.maxkey.constants.ContentType;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -34,32 +33,6 @@ public class MetadataEndpoint {
@RequestMapping(value = "/metadata/version",produces = ContentType.TEXT_PLAIN_UTF8, method={RequestMethod.GET})
@ResponseBody
public String metadata(HttpServletRequest request,HttpServletResponse response) {
StringBuffer version =
new StringBuffer("---------------------------------------------------------------------------------\n");
version.append("+ MaxKey \n");
version.append("+ Single Sign On ( SSO ) \n");
version.append("+ Version ");
version.append(WebContext.properties.getProperty("application.formatted-version")+"\n");
version.append("+\n");
version.append(String.format("+ %sCopyright 2018 - %s https://www.maxkey.top/\n",
(char)0xA9 , new DateTime().getYear()
));
version.append("+ Licensed under the Apache License, Version 2.0 \n");
version.append("---------------------------------------------------------------------------------\n");
version.append("+ JAVA \n");
version.append(String.format("+ %s java version %s, class %s\n",
SystemUtils.JAVA_VENDOR,
SystemUtils.JAVA_VERSION,
SystemUtils.JAVA_CLASS_VERSION
));
version.append(String.format("+ %s (build %s, %s)\n",
SystemUtils.JAVA_VM_NAME,
SystemUtils.JAVA_VM_VERSION,
SystemUtils.JAVA_VM_INFO
));
version.append("---------------------------------------------------------------------------------\n");
return version.toString();
return JpaWebContext.version();
}
}
......@@ -19,7 +19,7 @@ package org.apache.mybatis.jpa.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.mybatis.jpa.util.WebContext;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.junit.Before;
import org.junit.Test;
import org.maxkey.entity.Accounts;
......@@ -38,7 +38,7 @@ public class AccountsServiceTest {
public static AccountsService service;
public AccountsService getservice() {
service=(AccountsService)WebContext.getBean("accountsService");
service=(AccountsService)JpaWebContext.getBean("accountsService");
return service;
}
......@@ -93,7 +93,7 @@ public class AccountsServiceTest {
_logger.info("Application dir "+System.getProperty("user.dir"));
context = new ClassPathXmlApplicationContext(new String[] {"spring/applicationContext.xml"});
WebContext.applicationContext=context;
JpaWebContext.applicationContext=context;
getservice();
System.out.println("init ...");
......
......@@ -19,7 +19,7 @@ package org.apache.mybatis.jpa.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.mybatis.jpa.util.WebContext;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.junit.Before;
import org.junit.Test;
import org.maxkey.entity.apps.Apps;
......@@ -38,7 +38,7 @@ public class AppsServiceTest {
public static AppsService service;
public AppsService getservice() {
service=(AppsService)WebContext.getBean("appsService");
service=(AppsService)JpaWebContext.getBean("appsService");
return service;
}
......@@ -81,7 +81,7 @@ public class AppsServiceTest {
_logger.info("Application dir "+System.getProperty("user.dir"));
context = new ClassPathXmlApplicationContext(new String[] {"spring/applicationContext.xml"});
WebContext.applicationContext=context;
JpaWebContext.applicationContext=context;
getservice();
System.out.println("init ...");
......
......@@ -22,7 +22,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.mybatis.jpa.util.WebContext;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.junit.Before;
import org.junit.Test;
import org.maxkey.entity.apps.AppsFormBasedDetails;
......@@ -41,7 +41,7 @@ public class FormBasedDetailsServiceTest {
public static AppsFormBasedDetailsService service;
public AppsFormBasedDetailsService getservice() {
service=(AppsFormBasedDetailsService)WebContext.getBean("appsFormBasedDetailsService");
service=(AppsFormBasedDetailsService)JpaWebContext.getBean("appsFormBasedDetailsService");
return service;
}
......@@ -142,7 +142,7 @@ public class FormBasedDetailsServiceTest {
_logger.info("Application dir "+System.getProperty("user.dir"));
context = new ClassPathXmlApplicationContext(new String[] {"spring/applicationContext.xml"});
WebContext.applicationContext=context;
JpaWebContext.applicationContext=context;
getservice();
System.out.println("init ...");
......
/*
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
* 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.
......@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.maxkey.authn.annotation.CurrentUser;
import org.maxkey.authn.web.AuthorizationUtils;
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
......@@ -172,6 +173,6 @@ public class JwtAuthorizeEndpoint extends AuthorizeBaseEndpoint{
return jwkSetKeyStore.toString(mediaType);
}
return appId + " not exist.";
return appId + " not exist. \n" + JpaWebContext.version();
}
}
......@@ -23,6 +23,7 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.maxkey.authn.web.AuthorizationUtils;
import org.maxkey.authz.oauth2.common.OAuth2AccessToken;
import org.maxkey.authz.oauth2.common.OAuth2Constants;
......@@ -90,6 +91,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
*
* @author Dave Syer
* @author Vladimir Kryachko
* @author Crystal.sea 2022-04-14
*
*/
@Tag(name = "2-1-OAuth v2.0 API文档模块")
......@@ -326,7 +328,7 @@ public class AuthorizationEndpoint extends AbstractEndpoint {
return jwkSetKeyStore.toString(mediaType);
}
return appId + " not exist.";
return appId + " not exist . \n" + JpaWebContext.version();
}
// We need explicit approval from the user.
......
/*
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
* 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.
......@@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.Validate;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.maxkey.authz.saml.common.TrustResolver;
import org.maxkey.authz.saml20.metadata.MetadataGenerator;
import org.maxkey.constants.ContentType;
......@@ -167,7 +168,8 @@ public class SamlMetadataEndpoint {
}
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<root>" + JpaWebContext.version() + "</root>";
}
/**
......
......@@ -19,9 +19,9 @@ package org.maxkey.synchronizer;
import java.util.HashMap;
import org.apache.mybatis.jpa.util.WebContext;
import org.maxkey.entity.Synchronizers;
import org.maxkey.persistence.service.SynchronizersService;
import org.maxkey.web.WebContext;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册