This commit is contained in:
MaxKey
2022-01-18 14:21:49 +08:00
parent d4a8c19c6e
commit ff2cf5b82f
137 changed files with 872 additions and 912 deletions
@@ -24,10 +24,11 @@ import org.maxkey.authn.online.OnlineTicketServices;
import org.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsLoginType;
import org.maxkey.constants.ConstantsStatus;
import org.maxkey.constants.ConstsLoginType;
import org.maxkey.constants.ConstsStatus;
import org.maxkey.entity.UserInfo;
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
import org.maxkey.password.onetimepwd.OtpAuthnService;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -59,7 +60,7 @@ public abstract class AbstractAuthenticationProvider {
protected AbstractOtpAuthn tfaOtpAuthn;
protected AbstractOtpAuthn smsOtpAuthn;
protected OtpAuthnService otpAuthnService;
protected AbstractRemeberMeService remeberMeService;
@@ -118,7 +119,7 @@ public abstract class AbstractAuthenticationProvider {
changeSession(authentication);
authenticationRealm.insertLoginHistory( WebContext.getUserInfo(),
ConstantsLoginType.LOCAL,
ConstsLoginType.LOCAL,
"",
"xe00000004",
WebConstants.LOGIN_RESULT.SUCCESS);
@@ -255,6 +256,7 @@ public abstract class AbstractAuthenticationProvider {
UserInfo validUserInfo = new UserInfo();
validUserInfo.setUsername(userInfo.getUsername());
validUserInfo.setId(userInfo.getId());
AbstractOtpAuthn smsOtpAuthn = otpAuthnService.getByInstId(userInfo.getInstId());
if (password == null || !smsOtpAuthn.validate(validUserInfo, password)) {
String message = WebContext.getI18nValue("login.error.captcha");
_logger.debug("login captcha valid error.");
@@ -336,13 +338,13 @@ public abstract class AbstractAuthenticationProvider {
loginUser.setLoginCount(0);
authenticationRealm.insertLoginHistory(
loginUser,
ConstantsLoginType.LOCAL,
ConstsLoginType.LOCAL,
"",
i18nMessage,
WebConstants.LOGIN_RESULT.USER_NOT_EXIST);
throw new BadCredentialsException(i18nMessage);
}else {
if(userInfo.getIsLocked()==ConstantsStatus.LOCK) {
if(userInfo.getIsLocked()==ConstsStatus.LOCK) {
authenticationRealm.insertLoginHistory(
userInfo,
loginCredential.getAuthType(),
@@ -350,7 +352,7 @@ public abstract class AbstractAuthenticationProvider {
loginCredential.getCode(),
WebConstants.LOGIN_RESULT.USER_LOCKED
);
}else if(userInfo.getStatus()!=ConstantsStatus.ACTIVE) {
}else if(userInfo.getStatus()!=ConstsStatus.ACTIVE) {
authenticationRealm.insertLoginHistory(
userInfo,
loginCredential.getAuthType(),
@@ -383,7 +385,8 @@ public abstract class AbstractAuthenticationProvider {
this.onlineTicketServices = onlineTicketServices;
}
public void setSmsOtpAuthn(AbstractOtpAuthn smsOtpAuthn) {
this.smsOtpAuthn = smsOtpAuthn;
public void setOtpAuthnService(OtpAuthnService otpAuthnService) {
this.otpAuthnService = otpAuthnService;
}
}
@@ -26,6 +26,7 @@ import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.entity.UserInfo;
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
import org.maxkey.password.onetimepwd.OtpAuthnService;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -62,13 +63,13 @@ public class RealmAuthenticationProvider extends AbstractAuthenticationProvider
AbstractAuthenticationRealm authenticationRealm,
ApplicationConfig applicationConfig,
AbstractOtpAuthn tfaOtpAuthn,
AbstractOtpAuthn smsOtpAuthn,
OtpAuthnService otpAuthnService,
AbstractRemeberMeService remeberMeService,
OnlineTicketServices onlineTicketServices) {
this.authenticationRealm = authenticationRealm;
this.applicationConfig = applicationConfig;
this.tfaOtpAuthn = tfaOtpAuthn;
this.smsOtpAuthn = smsOtpAuthn;
this.otpAuthnService = otpAuthnService;
this.remeberMeService = remeberMeService;
this.onlineTicketServices = onlineTicketServices;
}
@@ -17,7 +17,7 @@
package org.maxkey.authn.online;
import org.maxkey.constants.ConstantsPersistence;
import org.maxkey.constants.ConstsPersistence;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,12 +33,12 @@ public class OnlineTicketServicesFactory {
RedisConnectionFactory redisConnFactory){
OnlineTicketServices onlineTicketServices = null;
if (persistence == ConstantsPersistence.INMEMORY) {
if (persistence == ConstsPersistence.INMEMORY) {
onlineTicketServices = new InMemoryOnlineTicketServices();
_logger.debug("InMemoryOnlineTicketServices");
} else if (persistence == ConstantsPersistence.JDBC) {
} else if (persistence == ConstsPersistence.JDBC) {
_logger.debug("OnlineTicketServices not support ");
} else if (persistence == ConstantsPersistence.REDIS) {
} else if (persistence == ConstsPersistence.REDIS) {
onlineTicketServices = new RedisOnlineTicketServices(redisConnFactory);
_logger.debug("RedisOnlineTicketServices");
}
@@ -22,6 +22,7 @@ import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.authn.realm.ldap.LdapAuthenticationRealmService;
import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
import org.maxkey.entity.Groups;
import org.maxkey.entity.HistoryLogin;
@@ -58,12 +59,9 @@ public abstract class AbstractAuthenticationRealm {
protected AbstractRemeberMeService remeberMeService;
protected boolean ldapSupport;
protected AbstractAuthenticationRealm ldapAuthenticationRealm;
protected UserInfoService userInfoService;
protected LdapAuthenticationRealmService ldapAuthenticationRealmService;
/**
@@ -1,74 +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.authn.realm.activedirectory;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.maxkey.authn.realm.IAuthenticationServer;
import org.maxkey.entity.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
public class ActiveDirectoryAuthenticationRealm extends AbstractAuthenticationRealm{
private final static Logger _logger = LoggerFactory.getLogger(ActiveDirectoryAuthenticationRealm.class);
@NotNull
@Size(min=1)
private List<IAuthenticationServer> activeDirectoryServers;
/**
*
*/
public ActiveDirectoryAuthenticationRealm() {
super();
}
/**
* @param jdbcTemplate
*/
public ActiveDirectoryAuthenticationRealm(JdbcTemplate jdbcTemplate) {
super(jdbcTemplate);
}
@Override
public boolean passwordMatches(UserInfo userInfo, String password) {
boolean isAuthenticated=false;
for (final IAuthenticationServer activeDirectoryServer : this.activeDirectoryServers) {
_logger.debug("Attempting to authenticate {} at {}", userInfo.getUsername(), activeDirectoryServer);
isAuthenticated= activeDirectoryServer.authenticate(userInfo.getUsername(), password);
if (isAuthenticated ) {
return true;
}
}
return false;
}
public void setActiveDirectoryServers(
List<IAuthenticationServer> activeDirectoryServers) {
this.activeDirectoryServers = activeDirectoryServers;
}
}
@@ -18,8 +18,10 @@
package org.maxkey.authn.realm.jdbc;
import org.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.maxkey.authn.realm.ldap.LdapAuthenticationRealm;
import org.maxkey.authn.realm.ldap.LdapAuthenticationRealmService;
import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
import org.maxkey.constants.ConstantsLoginType;
import org.maxkey.constants.ConstsLoginType;
import org.maxkey.entity.PasswordPolicy;
import org.maxkey.entity.UserInfo;
import org.maxkey.persistence.repository.LoginHistoryRepository;
@@ -66,11 +68,10 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
this.loginRepository = loginRepository;
this.loginHistoryRepository = loginHistoryRepository;
this.remeberMeService = remeberMeService;
this.userInfoService = userInfoService;
this.userInfoService = userInfoService;
this.jdbcTemplate = jdbcTemplate;
}
public JdbcAuthenticationRealm(
PasswordEncoder passwordEncoder,
PasswordPolicyValidator passwordPolicyValidator,
@@ -79,19 +80,15 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
AbstractRemeberMeService remeberMeService,
UserInfoService userInfoService,
JdbcTemplate jdbcTemplate,
AbstractAuthenticationRealm ldapAuthenticationRealm,
boolean ldapSupport
) {
this.passwordEncoder =passwordEncoder;
this.passwordPolicyValidator=passwordPolicyValidator;
this.loginRepository = loginRepository;
this.loginHistoryRepository = loginHistoryRepository;
this.remeberMeService = remeberMeService;
this.jdbcTemplate = jdbcTemplate;
this.ldapAuthenticationRealm = ldapAuthenticationRealm;
this.userInfoService = userInfoService;
this.ldapSupport = ldapSupport;
LdapAuthenticationRealmService ldapAuthenticationRealmService) {
this.passwordEncoder = passwordEncoder;
this.passwordPolicyValidator = passwordPolicyValidator;
this.loginRepository = loginRepository;
this.loginHistoryRepository = loginHistoryRepository;
this.remeberMeService = remeberMeService;
this.userInfoService = userInfoService;
this.jdbcTemplate = jdbcTemplate;
this.ldapAuthenticationRealmService = ldapAuthenticationRealmService;
}
/**
@@ -104,24 +101,26 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
// + PasswordReciprocal.getInstance().rawPassword(userInfo.getUsername(), password));
passwordMatches = passwordEncoder.matches(password,userInfo.getPassword());
//passwordMatches == false and ldapSupport ==true
//validate password with LDAP
if(!passwordMatches && ldapSupport) {
passwordMatches =this.ldapAuthenticationRealm.passwordMatches(userInfo, password);
if(passwordMatches) {
//init password to local Realm
UserInfo changePasswordUser = new UserInfo();
changePasswordUser.setId(userInfo.getId());
changePasswordUser.setUsername(userInfo.getUsername());
changePasswordUser.setPassword(password);
userInfoService.changePassword(changePasswordUser, false);
}
if(ldapAuthenticationRealmService != null) {
//passwordMatches == false and ldapSupport ==true
//validate password with LDAP
LdapAuthenticationRealm ldapRealm = ldapAuthenticationRealmService.getByInstId(userInfo.getInstId());
if(!passwordMatches && ldapRealm != null && ldapRealm.isLdapSupport()) {
passwordMatches = ldapRealm.passwordMatches(userInfo, password);
if(passwordMatches) {
//write password to database Realm
UserInfo changePasswordUser = new UserInfo();
changePasswordUser.setId(userInfo.getId());
changePasswordUser.setUsername(userInfo.getUsername());
changePasswordUser.setPassword(password);
userInfoService.changePassword(changePasswordUser, false);
}
}
}
_logger.debug("passwordvalid : {}" , passwordMatches);
if (!passwordMatches) {
passwordPolicyValidator.plusBadPasswordCount(userInfo);
insertLoginHistory(userInfo, ConstantsLoginType.LOCAL, "", "xe00000004", WebConstants.LOGIN_RESULT.PASSWORD_ERROE);
insertLoginHistory(userInfo, ConstsLoginType.LOCAL, "", "xe00000004", WebConstants.LOGIN_RESULT.PASSWORD_ERROE);
PasswordPolicy passwordPolicy = passwordPolicyValidator.getPasswordPolicyRepository().getPasswordPolicy();
if(userInfo.getBadPasswordCount()>=(passwordPolicy.getAttempts()/2)) {
throw new BadCredentialsException(
@@ -18,7 +18,7 @@
/**
*
*/
package org.maxkey.authn.realm.activedirectory;
package org.maxkey.authn.realm.ldap;
import org.maxkey.authn.realm.IAuthenticationServer;
import org.maxkey.persistence.ldap.ActiveDirectoryUtils;
@@ -36,6 +36,8 @@ public class LdapAuthenticationRealm extends AbstractAuthenticationRealm{
@Size(min=1)
private List<IAuthenticationServer> ldapServers;
private boolean ldapSupport;
/**
*
*/
@@ -43,6 +45,10 @@ public class LdapAuthenticationRealm extends AbstractAuthenticationRealm{
}
public LdapAuthenticationRealm(boolean ldapSupport) {
this.ldapSupport = ldapSupport;
}
/**
* @param jdbcTemplate
*/
@@ -68,5 +74,13 @@ public class LdapAuthenticationRealm extends AbstractAuthenticationRealm{
this.ldapServers = ldapServers;
}
public boolean isLdapSupport() {
return ldapSupport;
}
public void setLdapSupport(boolean ldapSupport) {
this.ldapSupport = ldapSupport;
}
}
@@ -0,0 +1,84 @@
/*
* 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.authn.realm.ldap;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.maxkey.authn.realm.IAuthenticationServer;
import org.maxkey.entity.LdapContext;
import org.maxkey.persistence.ldap.ActiveDirectoryUtils;
import org.maxkey.persistence.ldap.LdapUtils;
import org.maxkey.persistence.service.LdapContextService;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
public class LdapAuthenticationRealmService {
protected static final Cache<String, LdapAuthenticationRealm> ldapRealmStore =
Caffeine.newBuilder()
.expireAfterWrite(60, TimeUnit.MINUTES)
.build();
LdapContextService ldapContextService;
public LdapAuthenticationRealmService(LdapContextService ldapContextService) {
this.ldapContextService = ldapContextService;
}
public LdapAuthenticationRealm getByInstId(String instId) {
LdapAuthenticationRealm authenticationRealm = ldapRealmStore.getIfPresent(instId);
if(authenticationRealm == null) {
List<LdapContext> ldapContexts =
ldapContextService.find("where instid = ? ", 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) {
if(ldapContext.getProduct().equalsIgnoreCase("ActiveDirectory")) {
ActiveDirectoryServer ldapServer = new ActiveDirectoryServer();
ActiveDirectoryUtils ldapUtils = new ActiveDirectoryUtils(
ldapContext.getProviderUrl(),
ldapContext.getPrincipal(),
ldapContext.getCredentials(),
ldapContext.getMsadDomain());
ldapServer.setActiveDirectoryUtils(ldapUtils);
ldapAuthenticationServers.add(ldapServer);
}else {
StandardLdapServer standardLdapServer=new StandardLdapServer();
LdapUtils ldapUtils = new LdapUtils(
ldapContext.getProviderUrl(),
ldapContext.getPrincipal(),
ldapContext.getCredentials(),
ldapContext.getBasedn());
standardLdapServer.setLdapUtils(ldapUtils);
standardLdapServer.setFilterAttribute(ldapContext.getFilters());
ldapAuthenticationServers.add(standardLdapServer);
}
}
authenticationRealm.setLdapServers(ldapAuthenticationServers);
}
ldapRealmStore.put(instId, authenticationRealm);
}
return authenticationRealm;
}
}
@@ -34,8 +34,8 @@ import org.slf4j.LoggerFactory;
* @author Crystal.Sea
*
*/
public final class LdapServer implements IAuthenticationServer {
private final static Logger _logger = LoggerFactory.getLogger(LdapServer.class);
public final class StandardLdapServer implements IAuthenticationServer {
private final static Logger _logger = LoggerFactory.getLogger(StandardLdapServer.class);
LdapUtils ldapUtils;
@@ -22,7 +22,7 @@ import javax.servlet.http.HttpServletResponse;
import org.maxkey.authn.AbstractAuthenticationProvider;
import org.maxkey.authn.LoginCredential;
import org.maxkey.constants.ConstantsLoginType;
import org.maxkey.constants.ConstsLoginType;
import org.maxkey.util.AuthorizationHeaderCredential;
import org.maxkey.util.AuthorizationHeaderUtils;
import org.slf4j.Logger;
@@ -130,7 +130,7 @@ public class BasicEntryPoint implements AsyncHandlerInterceptor {
}
if(!isAuthenticated){
LoginCredential loginCredential =new LoginCredential(headerCredential.getUsername(),"",ConstantsLoginType.BASIC);
LoginCredential loginCredential =new LoginCredential(headerCredential.getUsername(),"",ConstsLoginType.BASIC);
authenticationProvider.authentication(loginCredential,true);
_logger.info("Authentication "+headerCredential.getUsername()+" successful .");
}
@@ -22,7 +22,7 @@ import javax.servlet.http.HttpServletResponse;
import org.maxkey.authn.AbstractAuthenticationProvider;
import org.maxkey.authn.LoginCredential;
import org.maxkey.constants.ConstantsLoginType;
import org.maxkey.constants.ConstsLoginType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -109,7 +109,7 @@ public class HttpHeaderEntryPoint implements AsyncHandlerInterceptor {
}
if(!isAuthenticated){
LoginCredential loginCredential =new LoginCredential(httpHeaderUsername,"",ConstantsLoginType.HTTPHEADER);
LoginCredential loginCredential =new LoginCredential(httpHeaderUsername,"",ConstsLoginType.HTTPHEADER);
authenticationProvider.authentication(loginCredential,true);
_logger.info("Authentication "+httpHeaderUsername+" successful .");
}
@@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletResponse;
import org.maxkey.authn.AbstractAuthenticationProvider;
import org.maxkey.authn.LoginCredential;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsLoginType;
import org.maxkey.constants.ConstsLoginType;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -78,7 +78,7 @@ public class HttpJwtEntryPoint implements AsyncHandlerInterceptor {
SignedJWT signedJWT = jwtLoginService.jwtTokenValidation(jwt);
if(signedJWT != null) {
String username =signedJWT.getJWTClaimsSet().getSubject();
LoginCredential loginCredential =new LoginCredential(username,"",ConstantsLoginType.JWT);
LoginCredential loginCredential =new LoginCredential(username,"",ConstsLoginType.JWT);
authenticationProvider.authentication(loginCredential,true);
_logger.debug("JWT Logined in , username " + username);
}
@@ -23,7 +23,7 @@ import org.joda.time.DateTime;
import org.maxkey.authn.AbstractAuthenticationProvider;
import org.maxkey.authn.LoginCredential;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsLoginType;
import org.maxkey.constants.ConstsLoginType;
import org.maxkey.crypto.ReciprocalUtils;
import org.maxkey.util.DateUtils;
import org.maxkey.util.JsonUtils;
@@ -95,7 +95,7 @@ public class HttpKerberosEntryPoint implements AsyncHandlerInterceptor {
_logger.debug("Kerberos Token is After Now "+notOnOrAfter.isAfterNow());
if(notOnOrAfter.isAfterNow()){
LoginCredential loginCredential =new LoginCredential(kerberosToken.getPrincipal(),"",ConstantsLoginType.KERBEROS);
LoginCredential loginCredential =new LoginCredential(kerberosToken.getPrincipal(),"",ConstsLoginType.KERBEROS);
loginCredential.setProvider(kerberosUserDomain);
authenticationProvider.authentication(loginCredential,true);
_logger.debug("Kerberos Logined in , username " + kerberosToken.getPrincipal());
@@ -23,7 +23,7 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsTimeInterval;
import org.maxkey.constants.ConstsTimeInterval;
import org.maxkey.crypto.Base64Utils;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.maxkey.util.JsonUtils;
@@ -37,7 +37,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
public abstract class AbstractRemeberMeService {
private static final Logger _logger = LoggerFactory.getLogger(AbstractRemeberMeService.class);
protected Integer remeberMeValidity = ConstantsTimeInterval.TWO_WEEK;
protected Integer remeberMeValidity = ConstsTimeInterval.TWO_WEEK;
protected String validity;
@@ -152,13 +152,13 @@ public abstract class AbstractRemeberMeService {
if (Pattern.matches("[0-9]+", validity)) {
remeberMeValidity = Integer.parseInt(validity);
} else if (validity.equalsIgnoreCase("ONE_DAY")) {
remeberMeValidity = ConstantsTimeInterval.ONE_DAY;
remeberMeValidity = ConstsTimeInterval.ONE_DAY;
} else if (validity.equalsIgnoreCase("ONE_WEEK")) {
remeberMeValidity = ConstantsTimeInterval.ONE_WEEK;
remeberMeValidity = ConstsTimeInterval.ONE_WEEK;
} else if (validity.equalsIgnoreCase("TWO_WEEK")) {
remeberMeValidity = ConstantsTimeInterval.TWO_WEEK;
remeberMeValidity = ConstsTimeInterval.TWO_WEEK;
} else if (validity.equalsIgnoreCase("ONE_YEAR")) {
remeberMeValidity = ConstantsTimeInterval.ONE_YEAR;
remeberMeValidity = ConstsTimeInterval.ONE_YEAR;
}
_logger.debug("Remeber Me Validity : " + remeberMeValidity);
@@ -25,7 +25,7 @@ import org.joda.time.DateTime;
import org.maxkey.authn.AbstractAuthenticationProvider;
import org.maxkey.authn.LoginCredential;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsLoginType;
import org.maxkey.constants.ConstsLoginType;
import org.maxkey.crypto.Base64Utils;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.maxkey.util.JsonUtils;
@@ -96,7 +96,7 @@ public class HttpRemeberMeEntryPoint implements AsyncHandlerInterceptor {
DateTime now = new DateTime();
if (now.isBefore(expiryDate)) {
LoginCredential loginCredential =
new LoginCredential(storeRemeberMe.getUsername(),"",ConstantsLoginType.REMEBER_ME);
new LoginCredential(storeRemeberMe.getUsername(),"",ConstsLoginType.REMEBER_ME);
authenticationProvider.authentication(loginCredential,true);
remeberMeService.updateRemeberMe(remeberMeCookie, response);
_logger.debug("RemeberMe Logined in , username " + storeRemeberMe.getUsername());
@@ -19,7 +19,7 @@ package org.maxkey.authn.support.rememberme;
import java.util.concurrent.TimeUnit;
import org.maxkey.constants.ConstantsTimeInterval;
import org.maxkey.constants.ConstsTimeInterval;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@@ -28,7 +28,7 @@ public class InMemoryRemeberMeService extends AbstractRemeberMeService {
protected static final Cache<String, RemeberMe> remeberMeStore =
Caffeine.newBuilder()
.expireAfterWrite(ConstantsTimeInterval.TWO_WEEK, TimeUnit.MINUTES)
.expireAfterWrite(ConstsTimeInterval.TWO_WEEK, TimeUnit.MINUTES)
.build();
@Override
@@ -17,13 +17,13 @@
package org.maxkey.authn.support.rememberme;
import org.maxkey.constants.ConstantsTimeInterval;
import org.maxkey.constants.ConstsTimeInterval;
import org.maxkey.persistence.redis.RedisConnection;
import org.maxkey.persistence.redis.RedisConnectionFactory;
public class RedisRemeberMeService extends AbstractRemeberMeService {
protected int serviceTicketValiditySeconds = ConstantsTimeInterval.TWO_WEEK;
protected int serviceTicketValiditySeconds = ConstsTimeInterval.TWO_WEEK;
RedisConnectionFactory connectionFactory;
@@ -17,7 +17,7 @@
package org.maxkey.authn.support.rememberme;
import org.maxkey.constants.ConstantsPersistence;
import org.maxkey.constants.ConstsPersistence;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,13 +33,13 @@ public class RemeberMeServiceFactory {
RedisConnectionFactory redisConnFactory){
AbstractRemeberMeService remeberMeService = null;
if (persistence == ConstantsPersistence.INMEMORY) {
if (persistence == ConstsPersistence.INMEMORY) {
remeberMeService = new InMemoryRemeberMeService();
_logger.debug("InMemoryRemeberMeService");
} else if (persistence == ConstantsPersistence.JDBC) {
} else if (persistence == ConstsPersistence.JDBC) {
//remeberMeService = new JdbcRemeberMeService(jdbcTemplate);
_logger.debug("JdbcRemeberMeService not support ");
} else if (persistence == ConstantsPersistence.REDIS) {
} else if (persistence == ConstsPersistence.REDIS) {
remeberMeService = new RedisRemeberMeService(redisConnFactory);
_logger.debug("RedisRemeberMeService");
}
@@ -22,7 +22,7 @@ import javax.servlet.http.HttpServletResponse;
import org.maxkey.authn.AbstractAuthenticationProvider;
import org.maxkey.authn.LoginCredential;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsLoginType;
import org.maxkey.constants.ConstsLoginType;
import org.maxkey.util.StringUtils;
import org.maxkey.web.WebContext;
import org.opensaml.saml1.core.impl.AssertionImpl;
@@ -99,7 +99,7 @@ public class HttpWsFederationEntryPoint implements AsyncHandlerInterceptor {
wsFederationService.getWsFederationConfiguration().getUpnSuffix());
}
LoginCredential loginCredential =new LoginCredential(
wsFederationCredential.getAttributes().get("").toString(),"",ConstantsLoginType.WSFEDERATION);
wsFederationCredential.getAttributes().get("").toString(),"",ConstsLoginType.WSFEDERATION);
authenticationProvider.authentication(loginCredential,true);
return true;
} else {
@@ -26,11 +26,16 @@ import org.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
import org.maxkey.authn.support.rememberme.RemeberMeServiceFactory;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstsPersistence;
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
import org.maxkey.password.onetimepwd.OtpAuthnService;
import org.maxkey.password.onetimepwd.token.RedisOtpTokenStore;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.maxkey.persistence.repository.LoginHistoryRepository;
import org.maxkey.persistence.repository.LoginRepository;
import org.maxkey.persistence.repository.PasswordPolicyValidator;
import org.maxkey.persistence.service.EmailSendersService;
import org.maxkey.persistence.service.SmsProviderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
@@ -58,7 +63,7 @@ public class AuthenticationAutoConfiguration implements InitializingBean {
AbstractAuthenticationRealm authenticationRealm,
ApplicationConfig applicationConfig,
AbstractOtpAuthn tfaOtpAuthn,
AbstractOtpAuthn smsOtpAuthn,
OtpAuthnService otpAuthnService,
AbstractRemeberMeService remeberMeService,
OnlineTicketServices onlineTicketServices
) {
@@ -68,13 +73,33 @@ public class AuthenticationAutoConfiguration implements InitializingBean {
authenticationRealm,
applicationConfig,
tfaOtpAuthn,
smsOtpAuthn,
otpAuthnService,
remeberMeService,
onlineTicketServices
);
}
@Bean(name = "otpAuthnService")
public OtpAuthnService otpAuthnService(
@Value("${maxkey.server.persistence}") int persistence,
SmsProviderService smsProviderService,
EmailSendersService emailSendersService,
RedisConnectionFactory redisConnFactory) {
OtpAuthnService otpAuthnService =
new OtpAuthnService(smsProviderService,emailSendersService);
if (persistence == ConstsPersistence.REDIS) {
RedisOtpTokenStore redisOptTokenStore = new RedisOtpTokenStore(redisConnFactory);
otpAuthnService.setRedisOptTokenStore(redisOptTokenStore);
}
_logger.debug("OneTimePasswordService {} inited." ,
persistence == ConstsPersistence.REDIS ? "Redis" : "InMemory");
return otpAuthnService;
}
@Bean(name = "passwordPolicyValidator")
public PasswordPolicyValidator passwordPolicyValidator(JdbcTemplate jdbcTemplate,MessageSource messageSource) {
return new PasswordPolicyValidator(jdbcTemplate,messageSource);
@@ -8,5 +8,6 @@ dependencies {
implementation project(":maxkey-common")
implementation project(":maxkey-core")
implementation project(":maxkey-persistence")
}
@@ -0,0 +1,113 @@
package org.maxkey.password.onetimepwd;
import java.sql.Types;
import java.util.concurrent.TimeUnit;
import org.maxkey.configuration.EmailConfig;
import org.maxkey.constants.ConstsBoolean;
import org.maxkey.entity.EmailSenders;
import org.maxkey.entity.SmsProvider;
import org.maxkey.password.onetimepwd.impl.MailOtpAuthn;
import org.maxkey.password.onetimepwd.impl.sms.SmsOtpAuthnAliyun;
import org.maxkey.password.onetimepwd.impl.sms.SmsOtpAuthnTencentCloud;
import org.maxkey.password.onetimepwd.impl.sms.SmsOtpAuthnYunxin;
import org.maxkey.password.onetimepwd.token.RedisOtpTokenStore;
import org.maxkey.persistence.service.EmailSendersService;
import org.maxkey.persistence.service.SmsProviderService;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
public class OtpAuthnService {
protected static final Cache<String, AbstractOtpAuthn> otpAuthnStore =
Caffeine.newBuilder()
.expireAfterWrite(60, TimeUnit.MINUTES)
.build();
SmsProviderService smsProviderService;
EmailSendersService emailSendersService;
RedisOtpTokenStore redisOptTokenStore;
public OtpAuthnService(SmsProviderService smsProviderService, EmailSendersService emailSendersService) {
this.smsProviderService = smsProviderService;
this.emailSendersService = emailSendersService;
}
public OtpAuthnService(SmsProviderService smsProviderService,RedisOtpTokenStore redisOptTokenStore) {
this.smsProviderService = smsProviderService;
this.redisOptTokenStore = redisOptTokenStore;
}
public AbstractOtpAuthn getByInstId(String instId) {
AbstractOtpAuthn otpAuthn = otpAuthnStore.getIfPresent(instId);
if(otpAuthn == null) {
SmsProvider smsProvider =
smsProviderService.findOne("where instid = ? ", new Object[]{instId}, new int[]{Types.VARCHAR});
if(smsProvider != null ) {
if(smsProvider.getProvider().equalsIgnoreCase("aliyun")) {
SmsOtpAuthnAliyun aliyun = new SmsOtpAuthnAliyun(
smsProvider.getAppKey(),
smsProvider.getAppSecret(),
smsProvider.getTemplateId(),
smsProvider.getSignName()
);
if(redisOptTokenStore != null) {
aliyun.setOptTokenStore(redisOptTokenStore);
}
otpAuthn = aliyun;
}else if(smsProvider.getProvider().equalsIgnoreCase("tencentcloud")) {
SmsOtpAuthnTencentCloud tencentCloud = new SmsOtpAuthnTencentCloud(
smsProvider.getAppKey(),
smsProvider.getAppSecret(),
smsProvider.getSmsSdkAppId(),
smsProvider.getTemplateId(),
smsProvider.getSignName()
);
if(redisOptTokenStore != null) {
tencentCloud.setOptTokenStore(redisOptTokenStore);
}
otpAuthn = tencentCloud;
}else if(smsProvider.getProvider().equalsIgnoreCase("neteasesms")) {
SmsOtpAuthnYunxin yunxin = new SmsOtpAuthnYunxin(
smsProvider.getAppKey(),
smsProvider.getAppSecret(),
smsProvider.getTemplateId()
);
if(redisOptTokenStore != null) {
yunxin.setOptTokenStore(redisOptTokenStore);
}
otpAuthn = yunxin;
}else if(smsProvider.getProvider().equalsIgnoreCase("email")) {
EmailSenders emailSender =
emailSendersService.findOne("where instid = ? ", new Object[]{instId}, new int[]{Types.VARCHAR});
EmailConfig emailConfig =
new EmailConfig(
emailSender.getAccount(),
emailSender.getCredentials(),
emailSender.getSmtpHost(),
emailSender.getPort(),
ConstsBoolean.isTrue(emailSender.getSslSwitch()),
emailSender.getSender());
MailOtpAuthn mailOtpAuthn = new MailOtpAuthn(emailConfig);
if(redisOptTokenStore != null) {
mailOtpAuthn.setOptTokenStore(redisOptTokenStore);
}
otpAuthn = mailOtpAuthn;
}
otpAuthnStore.put(instId, otpAuthn);
}
}
return otpAuthn;
}
public void setRedisOptTokenStore(RedisOtpTokenStore redisOptTokenStore) {
this.redisOptTokenStore = redisOptTokenStore;
}
}
@@ -26,12 +26,10 @@ import org.maxkey.entity.UserInfo;
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
public class MailOtpAuthn extends AbstractOtpAuthn {
private static final Logger _logger = LoggerFactory.getLogger(MailOtpAuthn.class);
@Autowired
EmailConfig emailConfig;
String subject = "One Time PassWord";
@@ -40,8 +38,22 @@ public class MailOtpAuthn extends AbstractOtpAuthn {
public MailOtpAuthn() {
otpType = OtpTypes.EMAIL;
}
public MailOtpAuthn(EmailConfig emailConfig) {
otpType = OtpTypes.EMAIL;
this.emailConfig = emailConfig;
}
@Override
public MailOtpAuthn(EmailConfig emailConfig, String subject, String messageTemplate) {
otpType = OtpTypes.EMAIL;
this.emailConfig = emailConfig;
this.subject = subject;
this.messageTemplate = messageTemplate;
}
@Override
public boolean produce(UserInfo userInfo) {
try {
String token = this.genToken(userInfo);
@@ -24,15 +24,11 @@ import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.io.IOException;
import org.maxkey.entity.UserInfo;
import org.maxkey.password.onetimepwd.impl.SmsOtpAuthn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 阿里云短信验证.
* @author shimingxy
@@ -45,6 +41,14 @@ public class SmsOtpAuthnAliyun extends SmsOtpAuthn {
otpType = OtpTypes.SMS;
}
public SmsOtpAuthnAliyun(String accessKeyId, String accessSecret, String templateCode, String signName) {
otpType = OtpTypes.SMS;
this.accessKeyId = accessKeyId;
this.accessSecret = accessSecret;
this.templateCode = templateCode;
this.signName = signName;
}
//请替换你在管理后台应用下申请的accessKeyId
private String accessKeyId = "94395d754eb55693043f5d6a2b772ef3";
//请替换你在管理后台应用下申请的accessSecret
@@ -54,7 +58,9 @@ public class SmsOtpAuthnAliyun extends SmsOtpAuthn {
private String signName = "MaxKey";
@Override
@Override
public boolean produce(UserInfo userInfo) {
// 手机号
String mobile = userInfo.getMobile();
@@ -130,18 +136,4 @@ public class SmsOtpAuthnAliyun extends SmsOtpAuthn {
this.signName = signName;
}
@Override
public void initPropertys() {
try {
this.loadProperties();
} catch (IOException e) {
e.printStackTrace();
}
this.accessKeyId = properties.getProperty("maxkey.otp.sms.aliyun.accesskeyid");
this.accessSecret = properties.getProperty("maxkey.otp.sms.aliyun.accesssecret");
this.templateCode = properties.getProperty("maxkey.otp.sms.aliyun.templatecode");
this.signName = properties.getProperty("maxkey.otp.sms.aliyun.signname");
}
}
@@ -24,8 +24,6 @@ import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import java.io.IOException;
import org.maxkey.entity.UserInfo;
import org.maxkey.password.onetimepwd.impl.SmsOtpAuthn;
import org.slf4j.Logger;
@@ -39,7 +37,7 @@ import org.slf4j.LoggerFactory;
*/
public class SmsOtpAuthnTencentCloud extends SmsOtpAuthn {
private static final Logger logger = LoggerFactory.getLogger(SmsOtpAuthnTencentCloud.class);
//
String secretId;
//
@@ -55,9 +53,17 @@ public class SmsOtpAuthnTencentCloud extends SmsOtpAuthn {
otpType = OtpTypes.SMS;
}
@Override
public SmsOtpAuthnTencentCloud(String secretId, String secretKey, String smsSdkAppid, String templateId,
String sign) {
otpType = OtpTypes.SMS;
this.secretId = secretId;
this.secretKey = secretKey;
this.smsSdkAppid = smsSdkAppid;
this.templateId = templateId;
this.sign = sign;
}
@Override
public boolean produce(UserInfo userInfo) {
// 手机号
String mobile = userInfo.getMobile();
@@ -104,87 +110,46 @@ public class SmsOtpAuthnTencentCloud extends SmsOtpAuthn {
return this.optTokenStore.validate(userInfo, token, OtpTypes.SMS, interval);
}
public String getSecretId() {
return secretId;
}
public void setSecretId(String secretId) {
this.secretId = secretId;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public String getSmsSdkAppid() {
return smsSdkAppid;
}
public void setSmsSdkAppid(String smsSdkAppid) {
this.smsSdkAppid = smsSdkAppid;
}
public String getTemplateId() {
return templateId;
}
public void setTemplateId(String templateId) {
this.templateId = templateId;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
@Override
public void initPropertys() {
try {
this.loadProperties();
} catch (IOException e) {
e.printStackTrace();
}
this.secretId = properties.getProperty("maxkey.otp.sms.tencentcloud.secretid");
this.secretKey = properties.getProperty("maxkey.otp.sms.tencentcloud.secretkey");
this.smsSdkAppid = properties.getProperty("maxkey.otp.sms.tencentcloud.smssdkappid");
this.templateId = properties.getProperty("maxkey.otp.sms.tencentcloud.templateid");
this.sign = properties.getProperty("maxkey.otp.sms.tencentcloud.sign");
}
}
@@ -17,7 +17,7 @@
package org.maxkey.password.onetimepwd.impl.sms;
import java.io.IOException;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -48,7 +48,14 @@ public class SmsOtpAuthnYunxin extends SmsOtpAuthn {
otpType = OtpTypes.SMS;
}
//发送验证码的请求路径URL
public SmsOtpAuthnYunxin(String appKey, String appSecret, String templateId) {
otpType = OtpTypes.SMS;
this.appKey = appKey;
this.appSecret = appSecret;
this.templateId = templateId;
}
//发送验证码的请求路径URL
private static final String
SERVER_URL = "https://api.netease.im/sms/sendcode.action";
//网易云信分配的账号,请替换你在管理后台应用下申请的Appkey
@@ -59,6 +66,7 @@ public class SmsOtpAuthnYunxin extends SmsOtpAuthn {
// 短信模板ID
private String templateId = "14860099";
@Override
public boolean produce(UserInfo userInfo) {
HttpPost httpPost = null;
@@ -201,22 +209,11 @@ public class SmsOtpAuthnYunxin extends SmsOtpAuthn {
public void setObj(String obj) {
this.obj = obj;
}
}
@Override
public void initPropertys() {
try {
this.loadProperties();
} catch (IOException e) {
e.printStackTrace();
}
this.appKey = properties.getProperty("maxkey.otp.sms.yunxin.appkey");
this.appSecret = properties.getProperty("maxkey.otp.sms.yunxin.appsecret");
this.templateId = properties.getProperty("maxkey.otp.sms.yunxin.templateid");
}
/**
* main.
* @param args String
@@ -234,3 +231,40 @@ public class SmsOtpAuthnYunxin extends SmsOtpAuthn {
}
}
class SmsOtpAuthnYunxinCheckSumBuilder {
// 计算并获取CheckSum
public static String getCheckSum(String appSecret, String nonce, String curTime) {
return encode("sha1", appSecret + nonce + curTime);
}
// 计算并获取md5值
public static String getMD5(String requestBody) {
return encode("md5", requestBody);
}
private static String encode(String algorithm, String value) {
if (value == null) {
return null;
}
try {
MessageDigest messageDigest
= MessageDigest.getInstance(algorithm);
messageDigest.update(value.getBytes());
return getFormattedText(messageDigest.digest());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static String getFormattedText(byte[] bytes) {
int len = bytes.length;
StringBuilder buf = new StringBuilder(len * 2);
for (int j = 0; j < len; j++) {
buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.toString();
}
private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
}
@@ -1,57 +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.password.onetimepwd.impl.sms;
import java.security.MessageDigest;
public class SmsOtpAuthnYunxinCheckSumBuilder {
// 计算并获取CheckSum
public static String getCheckSum(String appSecret, String nonce, String curTime) {
return encode("sha1", appSecret + nonce + curTime);
}
// 计算并获取md5值
public static String getMD5(String requestBody) {
return encode("md5", requestBody);
}
private static String encode(String algorithm, String value) {
if (value == null) {
return null;
}
try {
MessageDigest messageDigest
= MessageDigest.getInstance(algorithm);
messageDigest.update(value.getBytes());
return getFormattedText(messageDigest.digest());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static String getFormattedText(byte[] bytes) {
int len = bytes.length;
StringBuilder buf = new StringBuilder(len * 2);
for (int j = 0; j < len; j++) {
buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.toString();
}
private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
}
@@ -18,7 +18,7 @@
package org.maxkey.password.onetimepwd.token;
import org.joda.time.DateTime;
import org.maxkey.constants.ConstantsTimeInterval;
import org.maxkey.constants.ConstsTimeInterval;
import org.maxkey.entity.UserInfo;
import org.maxkey.password.onetimepwd.OneTimePassword;
import org.maxkey.persistence.redis.RedisConnection;
@@ -26,7 +26,7 @@ import org.maxkey.persistence.redis.RedisConnectionFactory;
public class RedisOtpTokenStore extends AbstractOtpTokenStore {
protected int validitySeconds = ConstantsTimeInterval.ONE_MINUTE * 5;
protected int validitySeconds = ConstsTimeInterval.ONE_MINUTE * 5;
RedisConnectionFactory connectionFactory;
@@ -24,7 +24,7 @@ import javax.servlet.http.HttpServletRequest;
import org.maxkey.authn.LoginCredential;
import org.maxkey.authn.support.socialsignon.service.SocialsAssociate;
import org.maxkey.constants.ConstantsLoginType;
import org.maxkey.constants.ConstsLoginType;
import org.maxkey.entity.SocialsProvider;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -205,7 +205,7 @@ public class SocialSignOnEndpoint extends AbstractSocialSignOnEndpoint{
socialsAssociate.getProvider(),socialsAssociate.getUsername());
LoginCredential loginCredential =new LoginCredential(
socialsAssociate.getUsername(),"",ConstantsLoginType.SOCIALSIGNON);
socialsAssociate.getUsername(),"",ConstsLoginType.SOCIALSIGNON);
loginCredential.setProvider(this.socialSignOnProvider.getProviderName());
authenticationProvider.authentication(loginCredential,true);
//socialsAssociate.setAccessToken(JsonUtils.object2Json(this.accessToken));
@@ -23,7 +23,7 @@ import java.sql.Types;
import java.util.Date;
import java.util.List;
import org.maxkey.constants.ConstantsDatabase;
import org.maxkey.constants.ConstsDatabase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -54,7 +54,7 @@ public class JdbcSocialsAssociateService implements SocialsAssociateService{
public boolean insert(SocialsAssociate socialsAssociate) {
socialsAssociate.setId(socialsAssociate.generateId());
jdbcTemplate.update(
ConstantsDatabase.compare(ConstantsDatabase.ORACLE)?
ConstsDatabase.compare(ConstsDatabase.ORACLE)?
DEFAULT_DEFAULT_INSERT_STATEMENT_ORACLE:DEFAULT_DEFAULT_INSERT_STATEMENT,
new Object[] {
socialsAssociate.getId(),
@@ -25,7 +25,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsTimeInterval;
import org.maxkey.constants.ConstsTimeInterval;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.maxkey.entity.SocialsProvider;
import org.maxkey.entity.SocialsProviderLogin;
@@ -49,7 +49,7 @@ public class SocialSignOnProviderService{
protected static final Cache<String, SocialsProviderLogin> socialSignOnProvidersStore =
Caffeine.newBuilder()
.expireAfterWrite(ConstantsTimeInterval.ONE_HOUR, TimeUnit.MINUTES)
.expireAfterWrite(ConstsTimeInterval.ONE_HOUR, TimeUnit.MINUTES)
.build();
HashMap<String ,SocialsProvider>socialSignOnProviderMaps=new HashMap<String ,SocialsProvider>();