CongressService & MomentaryService

This commit is contained in:
MaxKey
2022-04-17 07:04:28 +08:00
parent 5e4923d6b4
commit d9af91de4a
82 changed files with 732 additions and 3665 deletions

View File

@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.maxkey.constants.ConstsPersistence;
import org.maxkey.crypto.keystore.KeyStoreLoader;
import org.maxkey.crypto.password.LdapShaPasswordEncoder;
import org.maxkey.crypto.password.Md4PasswordEncoder;
@@ -29,6 +30,10 @@ import org.maxkey.crypto.password.MessageDigestPasswordEncoder;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.maxkey.crypto.password.SM3PasswordEncoder;
import org.maxkey.crypto.password.StandardPasswordEncoder;
import org.maxkey.persistence.InMemoryMomentaryService;
import org.maxkey.persistence.MomentaryService;
import org.maxkey.persistence.RedisMomentaryService;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.maxkey.persistence.repository.InstitutionsRepository;
import org.maxkey.persistence.repository.LocalizationRepository;
import org.maxkey.util.IdGenerator;
@@ -50,6 +55,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
import com.nimbusds.jose.JOSEException;
@Configuration
public class ApplicationAutoConfiguration implements InitializingBean {
private static final Logger _logger =
@@ -174,6 +181,21 @@ public class ApplicationAutoConfiguration implements InitializingBean {
return idGenerator;
}
@Bean(name = "momentaryService")
public MomentaryService momentaryService(
RedisConnectionFactory redisConnFactory,
@Value("${maxkey.server.persistence}") int persistence) throws JOSEException {
MomentaryService momentaryService;
if (persistence == ConstsPersistence.REDIS) {
momentaryService = new RedisMomentaryService(redisConnFactory);
}else {
momentaryService = new InMemoryMomentaryService();
}
return momentaryService;
}
@Override
public void afterPropertiesSet() throws Exception {

View File

@@ -26,8 +26,6 @@ import javax.servlet.Filter;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstsTimeInterval;
import org.maxkey.persistence.repository.InstitutionsRepository;
import org.maxkey.persistence.repository.LoginHistoryRepository;
import org.maxkey.persistence.repository.LoginRepository;
import org.maxkey.web.WebXssRequestFilter;
import org.maxkey.web.WebInstRequestFilter;
import org.slf4j.Logger;

View File

@@ -1,61 +0,0 @@
/*
* Copyright [2020] [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.maxkey.autoconfigure;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;
@Configuration
@ConditionalOnProperty(value = "spring.session.store-type", havingValue = "redis", matchIfMissing = false)
@EnableRedisHttpSession
public class SessionRedisAutoConfiguration implements InitializingBean {
private static final Logger _logger = LoggerFactory.getLogger(SessionRedisAutoConfiguration.class);
private final RedisConnectionFactory redisConnectionFactory;
public SessionRedisAutoConfiguration(ObjectProvider<RedisConnectionFactory> redisConnectionFactory) {
this.redisConnectionFactory = redisConnectionFactory.getIfAvailable();
}
@Bean
public CookieSerializer cookieSerializer() {
_logger.debug("CookieSerializer Default .");
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setCookieName("JSESSIONID");
serializer.setCookiePath("/");
serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
return serializer;
}
@Override
public void afterPropertiesSet() throws Exception {
}
}

View File

@@ -66,6 +66,9 @@ public class ApplicationConfig {
@Value("${maxkey.server.authz.uri}")
private String authzUri;
@Value("${maxkey.server.frontend.uri:http://sso.maxkey.top:4200}")
private String frontendUri;
@Value("${server.port:8080}")
private int port;
@@ -132,7 +135,15 @@ public class ApplicationConfig {
this.serverPrefix = serverPrefix;
}
/**
public String getFrontendUri() {
return frontendUri;
}
public void setFrontendUri(String frontendUri) {
this.frontendUri = frontendUri;
}
/**
* @return the domainName
*/
public String getDomainName() {

View File

@@ -30,6 +30,8 @@ import javax.persistence.Table;
import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
import org.hibernate.validator.constraints.Length;
import com.fasterxml.jackson.annotation.JsonIgnore;
/*
ID varchar(40) not null,
UID varchar(40) null,
@@ -82,6 +84,7 @@ public class Accounts extends JpaBaseEntity implements Serializable {
UserInfo userInfo;
@JsonIgnore
private HashMap<String,OrganizationsCast> orgCast =new HashMap<String,OrganizationsCast>();
public Accounts() {

View File

@@ -0,0 +1,62 @@
/*
* Copyright [2020] [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.maxkey.persistence;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
public class InMemoryMomentaryService implements MomentaryService{
private static final Logger _logger = LoggerFactory.getLogger(InMemoryMomentaryService.class);
protected static Cache<String, Object> momentaryStore =
Caffeine.newBuilder()
.expireAfterWrite(3, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public InMemoryMomentaryService() {
super();
}
@Override
public void put(String ticket , String name, Object value){
momentaryStore.put(getKey(ticket,name), value);
}
@Override
public Object remove(String ticket , String name) {
Object value = momentaryStore.getIfPresent(getKey(ticket,name));
momentaryStore.invalidate(getKey(ticket,name));
return value;
}
@Override
public Object get(String ticket , String name) {
return momentaryStore.getIfPresent(getKey(ticket,name));
}
private String getKey(String ticket , String name) {
return ticket +"_"+ name;
}
}

View File

@@ -0,0 +1,28 @@
/*
* 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.maxkey.persistence;
public interface MomentaryService {
public void put(String ticket , String name, Object value);
public Object get(String ticket , String name);
public Object remove(String ticket , String name);
}

View File

@@ -0,0 +1,86 @@
/*
* 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.maxkey.persistence;
import org.maxkey.persistence.redis.RedisConnection;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RedisMomentaryService implements MomentaryService {
private static final Logger _logger = LoggerFactory.getLogger(RedisMomentaryService.class);
protected int validitySeconds = 60 * 3; //default 3 minutes.
RedisConnectionFactory connectionFactory;
public static String PREFIX="REDIS_MOMENTARY_";
/**
* @param connectionFactory
*/
public RedisMomentaryService(
RedisConnectionFactory connectionFactory) {
super();
this.connectionFactory = connectionFactory;
}
/**
*
*/
public RedisMomentaryService() {
}
public void setConnectionFactory(RedisConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
@Override
public void put(String ticket , String name, Object value){
RedisConnection conn = connectionFactory.getConnection();
conn.setexObject(getKey(ticket , name), validitySeconds, value);
conn.close();
}
@Override
public Object get(String ticket , String name) {
RedisConnection conn = connectionFactory.getConnection();
Object value = conn.getObject(getKey(ticket , name));
conn.close();
return value;
}
@Override
public Object remove(String ticket, String name) {
RedisConnection conn = connectionFactory.getConnection();
Object value = conn.getObject(getKey(ticket , name));
conn.delete(getKey(ticket , name));
conn.close();
return value;
}
private String getKey(String ticket , String name) {
return PREFIX + ticket + name;
}
}

View File

@@ -21,12 +21,15 @@ import java.io.Serializable;
import java.util.List;
import org.maxkey.util.ObjectTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;
public class RedisConnection {
private static final Logger _logger = LoggerFactory.getLogger(RedisConnection.class);
Jedis conn ;
RedisConnectionFactory connectionFactory;
@@ -54,12 +57,20 @@ public class RedisConnection {
* @param key
* @param value
*/
public void setObject(String key, Serializable object){
set(key, ObjectTransformer.serialize(object));
public void setObject(String key, Object value){
if(value instanceof Serializable) {
set(key, ObjectTransformer.serialize((Serializable)value));
}else {
_logger.error("value must implements of Serializable .");
}
}
public void setexObject(String key,int seconds, Serializable object){
setex(key, seconds, ObjectTransformer.serialize(object));
public void setexObject(String key,int seconds, Object value){
if(value instanceof Serializable) {
setex(key, seconds, ObjectTransformer.serialize((Serializable)value));
}else {
_logger.error("value must implements of Serializable .");
}
}
/**