AbstractAuthenticationProvider
This commit is contained in:
@@ -64,7 +64,16 @@ public abstract class AbstractAuthenticationProvider {
|
||||
protected abstract String getProviderName();
|
||||
|
||||
protected abstract Authentication doInternalAuthenticate(Authentication authentication);
|
||||
|
||||
public abstract Authentication basicAuthenticate(Authentication authentication) ;
|
||||
|
||||
public abstract Authentication trustAuthentication(
|
||||
String username,
|
||||
String type,
|
||||
String provider,
|
||||
String code,
|
||||
String message);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public boolean supports(Class authentication) {
|
||||
return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
|
||||
|
||||
@@ -105,6 +105,7 @@ public class RealmAuthenticationProvider extends AbstractAuthenticationProvider
|
||||
return usernamePasswordAuthenticationToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authentication basicAuthenticate(Authentication authentication) {
|
||||
BasicAuthentication basicAuth = (BasicAuthentication) authentication;
|
||||
UserInfo loadeduserInfo = loadUserInfo(basicAuth.getUsername(), "");
|
||||
@@ -142,6 +143,7 @@ public class RealmAuthenticationProvider extends AbstractAuthenticationProvider
|
||||
* @param message String
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public Authentication trustAuthentication(String username,
|
||||
String type,
|
||||
String provider,
|
||||
|
||||
@@ -30,8 +30,7 @@ import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.joda.time.DateTime;
|
||||
import org.maxkey.authn.RealmAuthenticationProvider;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.authn.AbstractAuthenticationProvider;
|
||||
import org.maxkey.configuration.oidc.OIDCProviderMetadataDetails;
|
||||
import org.maxkey.constants.ConstantsLoginType;
|
||||
import org.maxkey.crypto.jwt.signer.service.impl.DefaultJwtSigningAndValidationService;
|
||||
@@ -43,14 +42,23 @@ import org.slf4j.LoggerFactory;
|
||||
public class JwtLoginService {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(JwtLoginService.class);
|
||||
|
||||
protected ApplicationConfig applicationConfig;
|
||||
|
||||
OIDCProviderMetadataDetails jwtProviderMetadata;
|
||||
|
||||
DefaultJwtSigningAndValidationService jwtSignerValidationService;
|
||||
|
||||
RealmAuthenticationProvider authenticationProvider ;
|
||||
AbstractAuthenticationProvider authenticationProvider ;
|
||||
|
||||
|
||||
public JwtLoginService(AbstractAuthenticationProvider authenticationProvider,
|
||||
OIDCProviderMetadataDetails jwtProviderMetadata,
|
||||
DefaultJwtSigningAndValidationService jwtSignerValidationService
|
||||
) {
|
||||
this.authenticationProvider = authenticationProvider;
|
||||
this.jwtProviderMetadata = jwtProviderMetadata;
|
||||
this.jwtSignerValidationService = jwtSignerValidationService;
|
||||
|
||||
}
|
||||
public boolean login(String jwt, HttpServletResponse response) {
|
||||
_logger.debug("jwt : " + jwt);
|
||||
|
||||
@@ -188,9 +196,6 @@ public class JwtLoginService {
|
||||
return loginResult;
|
||||
}
|
||||
|
||||
public void setApplicationConfig(ApplicationConfig applicationConfig) {
|
||||
this.applicationConfig = applicationConfig;
|
||||
}
|
||||
|
||||
public void setJwtProviderMetadata(OIDCProviderMetadataDetails jwtProviderMetadata) {
|
||||
this.jwtProviderMetadata = jwtProviderMetadata;
|
||||
@@ -200,7 +205,7 @@ public class JwtLoginService {
|
||||
this.jwtSignerValidationService = jwtSignerValidationService;
|
||||
}
|
||||
|
||||
public void setAuthenticationProvider(RealmAuthenticationProvider authenticationProvider) {
|
||||
public void setAuthenticationProvider(AbstractAuthenticationProvider authenticationProvider) {
|
||||
this.authenticationProvider = authenticationProvider;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.joda.time.DateTime;
|
||||
import org.maxkey.authn.RealmAuthenticationProvider;
|
||||
import org.maxkey.authn.AbstractAuthenticationProvider;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.constants.ConstantsLoginType;
|
||||
import org.maxkey.constants.ConstantsTimeInterval;
|
||||
@@ -50,7 +50,7 @@ public abstract class AbstractRemeberMeService {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("authenticationProvider")
|
||||
RealmAuthenticationProvider authenticationProvider ;
|
||||
AbstractAuthenticationProvider authenticationProvider ;
|
||||
|
||||
// follow function is for persist
|
||||
public abstract void save(RemeberMe remeberMe);
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.maxkey.authn.AbstractAuthenticationProvider;
|
||||
import org.maxkey.authn.RealmAuthenticationProvider;
|
||||
import org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler;
|
||||
import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
|
||||
@@ -117,7 +119,7 @@ public class ApplicationAutoConfiguration implements InitializingBean {
|
||||
}
|
||||
|
||||
@Bean(name = "authenticationProvider")
|
||||
public RealmAuthenticationProvider authenticationProvider() {
|
||||
public AbstractAuthenticationProvider authenticationProvider() {
|
||||
return new RealmAuthenticationProvider();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.net.URI;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
|
||||
import org.maxkey.authn.RealmAuthenticationProvider;
|
||||
import org.maxkey.authn.AbstractAuthenticationProvider;
|
||||
import org.maxkey.authn.support.jwt.JwtLoginService;
|
||||
import org.maxkey.configuration.oidc.OIDCProviderMetadataDetails;
|
||||
import org.maxkey.constants.ConstantsProperties;
|
||||
@@ -127,11 +127,14 @@ public class JwtAuthnAutoConfiguration implements InitializingBean {
|
||||
public JwtLoginService jwtLoginService(
|
||||
DefaultJwtSigningAndValidationService jwtSignerValidationService,
|
||||
OIDCProviderMetadataDetails oidcProviderMetadata,
|
||||
RealmAuthenticationProvider authenticationProvider) {
|
||||
JwtLoginService jwtLoginService = new JwtLoginService();
|
||||
jwtLoginService.setJwtSignerValidationService(jwtSignerValidationService);
|
||||
jwtLoginService.setJwtProviderMetadata(oidcProviderMetadata);
|
||||
jwtLoginService.setAuthenticationProvider(authenticationProvider);
|
||||
AbstractAuthenticationProvider authenticationProvider) {
|
||||
|
||||
JwtLoginService jwtLoginService = new JwtLoginService(
|
||||
authenticationProvider,
|
||||
oidcProviderMetadata,
|
||||
jwtSignerValidationService
|
||||
);
|
||||
|
||||
return jwtLoginService;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,28 +104,6 @@ public final class WebContext {
|
||||
removeAttribute(WebConstants.CURRENT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* setAuthentication.
|
||||
* @param username String
|
||||
* @param type String
|
||||
* @param provider String
|
||||
* @param code String
|
||||
* @param message String
|
||||
* @return boolean
|
||||
|
||||
public static boolean setAuthentication(String username,
|
||||
String type,
|
||||
String provider,
|
||||
String code,
|
||||
String message) {
|
||||
|
||||
RealmAuthenticationProvider authenticationProvider =
|
||||
(RealmAuthenticationProvider) getBean("authenticationProvider");
|
||||
authenticationProvider.trustAuthentication(username, type, provider, code, message);
|
||||
|
||||
return isAuthenticated();
|
||||
}*/
|
||||
|
||||
public static void setAuthentication(Authentication authentication) {
|
||||
setAttribute(WebConstants.AUTHENTICATION, authentication);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user