authentications

This commit is contained in:
MaxKey
2021-02-15 11:40:58 +08:00
parent 6375e38c3d
commit 2ce5c1828b
8 changed files with 112 additions and 29 deletions

View File

@@ -32,8 +32,6 @@ import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
@@ -50,24 +48,14 @@ public abstract class AbstractAuthenticationProvider {
private static final Logger _logger =
LoggerFactory.getLogger(AbstractAuthenticationProvider.class);
@Autowired
@Qualifier("applicationConfig")
protected ApplicationConfig applicationConfig;
@Autowired
@Qualifier("authenticationRealm")
protected AbstractAuthenticationRealm authenticationRealm;
@Autowired
@Qualifier("tfaOptAuthn")
protected AbstractOtpAuthn tfaOptAuthn;
@Autowired
@Qualifier("remeberMeService")
protected AbstractRemeberMeService remeberMeService;
@Autowired
@Qualifier("onlineTicketServices")
protected OnlineTicketServices onlineTicketServices;
public static ArrayList<GrantedAuthority> grantedAdministratorsAuthoritys = new ArrayList<GrantedAuthority>();

View File

@@ -20,6 +20,11 @@ package org.maxkey.authn;
import java.util.ArrayList;
import org.maxkey.authn.online.OnlineTicket;
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.crypto.password.otp.AbstractOtpAuthn;
import org.maxkey.domain.UserInfo;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
@@ -46,8 +51,27 @@ public class RealmAuthenticationProvider extends AbstractAuthenticationProvider
protected String getProviderName() {
return "RealmAuthenticationProvider";
}
@Override
public RealmAuthenticationProvider() {
super();
}
public RealmAuthenticationProvider(
AbstractAuthenticationRealm authenticationRealm,
ApplicationConfig applicationConfig,
AbstractOtpAuthn tfaOptAuthn,
AbstractRemeberMeService remeberMeService,
OnlineTicketServices onlineTicketServices) {
this.authenticationRealm = authenticationRealm;
this.applicationConfig = applicationConfig;
this.tfaOptAuthn = tfaOptAuthn;
this.remeberMeService = remeberMeService;
this.onlineTicketServices = onlineTicketServices;
}
@Override
protected Authentication doInternalAuthenticate(LoginCredential loginCredential) {
_logger.debug("authentication " + loginCredential);

View File

@@ -49,17 +49,12 @@ public abstract class AbstractAuthenticationRealm {
protected boolean provisioning;
@Autowired
protected PasswordPolicyValidator passwordPolicyValidator;
@Autowired
protected LoginService loginService;
@Autowired
protected LoginHistoryService loginHistoryService;
@Autowired
@Qualifier("remeberMeService")
protected AbstractRemeberMeService remeberMeService;
/**

View File

@@ -24,7 +24,6 @@ import org.maxkey.domain.UserInfo;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.crypto.password.PasswordEncoder;
@@ -38,8 +37,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
public class DefaultJdbcAuthenticationRealm extends AbstractAuthenticationRealm {
private static Logger _logger = LoggerFactory.getLogger(DefaultJdbcAuthenticationRealm.class);
@Autowired
private PasswordEncoder passwordEncoder;
protected PasswordEncoder passwordEncoder;
public DefaultJdbcAuthenticationRealm() {

View File

@@ -17,9 +17,14 @@
package org.maxkey.authn.realm.jdbc;
import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
import org.maxkey.persistence.db.LoginHistoryService;
import org.maxkey.persistence.db.LoginService;
import org.maxkey.persistence.db.PasswordPolicyValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
/**
* JdbcAuthenticationRealm.
@@ -36,5 +41,23 @@ public class JdbcAuthenticationRealm extends DefaultJdbcAuthenticationRealm {
public JdbcAuthenticationRealm(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public JdbcAuthenticationRealm(
PasswordEncoder passwordEncoder,
PasswordPolicyValidator passwordPolicyValidator,
LoginService loginService,
LoginHistoryService loginHistoryService,
AbstractRemeberMeService remeberMeService,
JdbcTemplate jdbcTemplate) {
this.passwordEncoder =passwordEncoder;
this.passwordPolicyValidator=passwordPolicyValidator;
this.loginService = loginService;
this.loginHistoryService = loginHistoryService;
this.remeberMeService = remeberMeService;
this.jdbcTemplate = jdbcTemplate;
}
}

View File

@@ -26,9 +26,11 @@ 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.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.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsPersistence;
import org.maxkey.constants.ConstantsProperties;
import org.maxkey.crypto.password.LdapShaPasswordEncoder;
@@ -37,6 +39,7 @@ import org.maxkey.crypto.password.NoOpPasswordEncoder;
import org.maxkey.crypto.password.MessageDigestPasswordEncoder;
import org.maxkey.crypto.password.SM3PasswordEncoder;
import org.maxkey.crypto.password.StandardPasswordEncoder;
import org.maxkey.crypto.password.otp.AbstractOtpAuthn;
import org.maxkey.persistence.db.PasswordPolicyValidator;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;
@@ -74,8 +77,22 @@ public class AuthenticationAutoConfiguration implements InitializingBean {
}
@Bean(name = "authenticationProvider")
public AbstractAuthenticationProvider authenticationProvider() {
return new RealmAuthenticationProvider();
public AbstractAuthenticationProvider authenticationProvider(
AbstractAuthenticationRealm authenticationRealm,
ApplicationConfig applicationConfig,
AbstractOtpAuthn tfaOptAuthn,
AbstractRemeberMeService remeberMeService,
OnlineTicketServices onlineTicketServices
) {
return new RealmAuthenticationProvider(
authenticationRealm,
applicationConfig,
tfaOptAuthn,
remeberMeService,
onlineTicketServices
);
}
@Bean(name = "transactionManager")