This commit is contained in:
MaxKey
2021-02-17 09:55:03 +08:00
parent 3bee9b5896
commit aad4e7e878
12 changed files with 209 additions and 91 deletions

View File

@@ -0,0 +1,31 @@
package org.maxkey.authn.online;
import org.maxkey.constants.ConstantsPersistence;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
public class OnlineTicketServicesFactory {
private static final Logger _logger =
LoggerFactory.getLogger(OnlineTicketServicesFactory.class);
public OnlineTicketServices getService(
int persistence,
JdbcTemplate jdbcTemplate,
RedisConnectionFactory redisConnFactory){
OnlineTicketServices onlineTicketServices = null;
if (persistence == ConstantsPersistence.INMEMORY) {
onlineTicketServices = new InMemoryOnlineTicketServices();
_logger.debug("InMemoryOnlineTicketServices");
} else if (persistence == ConstantsPersistence.JDBC) {
_logger.debug("OnlineTicketServices not support ");
} else if (persistence == ConstantsPersistence.REDIS) {
onlineTicketServices = new RedisOnlineTicketServices(redisConnFactory);
_logger.debug("RedisOnlineTicketServices");
}
return onlineTicketServices;
}
}

View File

@@ -0,0 +1,31 @@
package org.maxkey.authn.support.rememberme;
import org.maxkey.constants.ConstantsPersistence;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
public class RemeberMeServiceFactory {
private static final Logger _logger =
LoggerFactory.getLogger(RemeberMeServiceFactory.class);
public AbstractRemeberMeService getService(
int persistence,
JdbcTemplate jdbcTemplate,
RedisConnectionFactory redisConnFactory){
AbstractRemeberMeService remeberMeService = null;
if (persistence == ConstantsPersistence.INMEMORY) {
remeberMeService = new InMemoryRemeberMeService();
_logger.debug("InMemoryRemeberMeService");
} else if (persistence == ConstantsPersistence.JDBC) {
//remeberMeService = new JdbcRemeberMeService(jdbcTemplate);
_logger.debug("JdbcRemeberMeService not support ");
} else if (persistence == ConstantsPersistence.REDIS) {
remeberMeService = new RedisRemeberMeService(redisConnFactory);
_logger.debug("RedisRemeberMeService");
}
return remeberMeService;
}
}

View File

@@ -23,15 +23,12 @@ import javax.sql.DataSource;
import org.maxkey.authn.AbstractAuthenticationProvider;
import org.maxkey.authn.RealmAuthenticationProvider;
import org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler;
import org.maxkey.authn.online.InMemoryOnlineTicketServices;
import org.maxkey.authn.online.OnlineTicketServices;
import org.maxkey.authn.online.RedisOnlineTicketServices;
import org.maxkey.authn.online.OnlineTicketServicesFactory;
import org.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
import org.maxkey.authn.support.rememberme.InMemoryRemeberMeService;
import org.maxkey.authn.support.rememberme.RedisRemeberMeService;
import org.maxkey.authn.support.rememberme.RemeberMeServiceFactory;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsPersistence;
import org.maxkey.constants.ConstantsProperties;
import org.maxkey.crypto.password.LdapShaPasswordEncoder;
import org.maxkey.crypto.password.Md4PasswordEncoder;
@@ -84,7 +81,7 @@ public class AuthenticationAutoConfiguration implements InitializingBean {
AbstractRemeberMeService remeberMeService,
OnlineTicketServices onlineTicketServices
) {
_logger.debug("init authenticationProvider .");
return new RealmAuthenticationProvider(
authenticationRealm,
applicationConfig,
@@ -121,6 +118,7 @@ public class AuthenticationAutoConfiguration implements InitializingBean {
*/
@Bean(name = "passwordEncoder")
public PasswordEncoder passwordEncoder() {
_logger.debug("init passwordEncoder .");
String idForEncode = "bcrypt";
Map<String ,PasswordEncoder > encoders = new HashMap<String ,PasswordEncoder>();
encoders.put(idForEncode, new BCryptPasswordEncoder());
@@ -157,18 +155,7 @@ public class AuthenticationAutoConfiguration implements InitializingBean {
@Value("${config.login.remeberme.validity}") int validity,
JdbcTemplate jdbcTemplate,
RedisConnectionFactory redisConnFactory) {
AbstractRemeberMeService remeberMeService = null;
if (persistence == ConstantsPersistence.INMEMORY) {
remeberMeService = new InMemoryRemeberMeService();
_logger.debug("InMemoryRemeberMeService");
} else if (persistence == ConstantsPersistence.JDBC) {
//remeberMeService = new JdbcRemeberMeService(jdbcTemplate);
_logger.debug("JdbcRemeberMeService not support ");
} else if (persistence == ConstantsPersistence.REDIS) {
remeberMeService = new RedisRemeberMeService(redisConnFactory);
_logger.debug("RedisRemeberMeService");
}
return remeberMeService;
return new RemeberMeServiceFactory().getService(persistence, jdbcTemplate, redisConnFactory);
}
@Bean(name = "onlineTicketServices")
@@ -176,17 +163,7 @@ public class AuthenticationAutoConfiguration implements InitializingBean {
@Value("${config.server.persistence}") int persistence,
JdbcTemplate jdbcTemplate,
RedisConnectionFactory redisConnFactory) {
OnlineTicketServices onlineTicketServices = null;
if (persistence == ConstantsPersistence.INMEMORY) {
onlineTicketServices = new InMemoryOnlineTicketServices();
_logger.debug("InMemoryOnlineTicketServices");
} else if (persistence == ConstantsPersistence.JDBC) {
_logger.debug("OnlineTicketServices not support ");
} else if (persistence == ConstantsPersistence.REDIS) {
onlineTicketServices = new RedisOnlineTicketServices(redisConnFactory);
_logger.debug("RedisOnlineTicketServices");
}
return onlineTicketServices;
return new OnlineTicketServicesFactory().getService(persistence, jdbcTemplate, redisConnFactory);
}
@Override

View File

@@ -8,6 +8,5 @@ dependencies {
compile project(":maxkey-common")
compile project(":maxkey-core")
compile project(":maxkey-persistence")
}