mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-15 21:02:09 +08:00
trustAuthentication
This commit is contained in:
@@ -30,6 +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.configuration.oidc.OIDCProviderMetadataDetails;
|
||||
import org.maxkey.constants.ConstantsLoginType;
|
||||
@@ -47,6 +48,8 @@ public class JwtLoginService {
|
||||
OIDCProviderMetadataDetails jwtProviderMetadata;
|
||||
|
||||
DefaultJwtSigningAndValidationService jwtSignerValidationService;
|
||||
|
||||
RealmAuthenticationProvider authenticationProvider ;
|
||||
|
||||
public boolean login(String jwt, HttpServletResponse response) {
|
||||
_logger.debug("jwt : " + jwt);
|
||||
@@ -93,9 +96,8 @@ public class JwtLoginService {
|
||||
DateTime now = new DateTime();
|
||||
|
||||
if (loginResult && now.isBefore(jwtClaimsSet.getExpirationTime().getTime())) {
|
||||
if (WebContext.setAuthentication(username, ConstantsLoginType.JWT, "", "", "success")) {
|
||||
return true;
|
||||
}
|
||||
authenticationProvider.trustAuthentication(username, ConstantsLoginType.JWT, "", "", "success");
|
||||
return true;
|
||||
}
|
||||
} catch (java.text.ParseException e) {
|
||||
// Invalid signed JWT encoding
|
||||
@@ -198,4 +200,8 @@ public class JwtLoginService {
|
||||
this.jwtSignerValidationService = jwtSignerValidationService;
|
||||
}
|
||||
|
||||
public void setAuthenticationProvider(RealmAuthenticationProvider authenticationProvider) {
|
||||
this.authenticationProvider = authenticationProvider;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +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.configuration.ApplicationConfig;
|
||||
import org.maxkey.constants.ConstantsLoginType;
|
||||
import org.maxkey.constants.ConstantsTimeInterval;
|
||||
@@ -46,6 +47,10 @@ public abstract class AbstractRemeberMeService {
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
protected ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("authenticationProvider")
|
||||
RealmAuthenticationProvider authenticationProvider ;
|
||||
|
||||
// follow function is for persist
|
||||
public abstract void save(RemeberMe remeberMe);
|
||||
@@ -112,15 +117,14 @@ public abstract class AbstractRemeberMeService {
|
||||
DateTime expiryDate = loginDate.plusSeconds(getRemeberMeValidity());
|
||||
DateTime now = new DateTime();
|
||||
if (now.isBefore(expiryDate)) {
|
||||
if (WebContext.setAuthentication(
|
||||
authenticationProvider.trustAuthentication(
|
||||
storeRemeberMe.getUsername(),
|
||||
ConstantsLoginType.REMEBER_ME,
|
||||
"",
|
||||
"",
|
||||
"success")
|
||||
) {
|
||||
return updateRemeberMe(remeberMeCookie, response);
|
||||
}
|
||||
"success");
|
||||
return updateRemeberMe(remeberMeCookie, response);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.nimbusds.jose.JWEAlgorithm;
|
||||
import java.net.URI;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
|
||||
import org.maxkey.authn.RealmAuthenticationProvider;
|
||||
import org.maxkey.authn.support.jwt.JwtLoginService;
|
||||
import org.maxkey.configuration.oidc.OIDCProviderMetadataDetails;
|
||||
import org.maxkey.constants.ConstantsProperties;
|
||||
@@ -124,11 +126,13 @@ public class JwtAuthnAutoConfiguration implements InitializingBean {
|
||||
@Bean(name = "jwtLoginService")
|
||||
public JwtLoginService jwtLoginService(
|
||||
DefaultJwtSigningAndValidationService jwtSignerValidationService,
|
||||
OIDCProviderMetadataDetails oidcProviderMetadata) {
|
||||
JwtLoginService jwkSetKeyStore = new JwtLoginService();
|
||||
jwkSetKeyStore.setJwtSignerValidationService(jwtSignerValidationService);
|
||||
jwkSetKeyStore.setJwtProviderMetadata(oidcProviderMetadata);
|
||||
return jwkSetKeyStore;
|
||||
OIDCProviderMetadataDetails oidcProviderMetadata,
|
||||
RealmAuthenticationProvider authenticationProvider) {
|
||||
JwtLoginService jwtLoginService = new JwtLoginService();
|
||||
jwtLoginService.setJwtSignerValidationService(jwtSignerValidationService);
|
||||
jwtLoginService.setJwtProviderMetadata(oidcProviderMetadata);
|
||||
jwtLoginService.setAuthenticationProvider(authenticationProvider);
|
||||
return jwtLoginService;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.maxkey.authn.RealmAuthenticationProvider;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.domain.UserInfo;
|
||||
import org.maxkey.util.DateUtils;
|
||||
@@ -113,7 +112,7 @@ public final class WebContext {
|
||||
* @param code String
|
||||
* @param message String
|
||||
* @return boolean
|
||||
*/
|
||||
|
||||
public static boolean setAuthentication(String username,
|
||||
String type,
|
||||
String provider,
|
||||
@@ -125,7 +124,7 @@ public final class WebContext {
|
||||
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