mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 12:32:09 +08:00
AuthorizationHeaderCredential rename to AuthorizationHeader
This commit is contained in:
@@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import org.maxkey.authn.LoginCredential;
|
import org.maxkey.authn.LoginCredential;
|
||||||
import org.maxkey.authn.provider.AbstractAuthenticationProvider;
|
import org.maxkey.authn.provider.AbstractAuthenticationProvider;
|
||||||
import org.maxkey.constants.ConstsLoginType;
|
import org.maxkey.constants.ConstsLoginType;
|
||||||
import org.maxkey.util.AuthorizationHeaderCredential;
|
import org.maxkey.util.AuthorizationHeader;
|
||||||
import org.maxkey.util.AuthorizationHeaderUtils;
|
import org.maxkey.util.AuthorizationHeaderUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -96,7 +96,7 @@ public class BasicEntryPoint implements AsyncHandlerInterceptor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthorizationHeaderCredential headerCredential = null;
|
AuthorizationHeader headerCredential = null;
|
||||||
|
|
||||||
if(AuthorizationHeaderUtils.isBasic(basicCredential)){
|
if(AuthorizationHeaderUtils.isBasic(basicCredential)){
|
||||||
headerCredential=AuthorizationHeaderUtils.resolve(basicCredential);
|
headerCredential=AuthorizationHeaderUtils.resolve(basicCredential);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.maxkey.util;
|
package org.maxkey.util;
|
||||||
|
|
||||||
public class AuthorizationHeaderCredential {
|
public class AuthorizationHeader {
|
||||||
|
|
||||||
public static class Credential {
|
public static class Credential {
|
||||||
|
|
||||||
@@ -30,13 +30,13 @@ public class AuthorizationHeaderCredential {
|
|||||||
String credential;
|
String credential;
|
||||||
String authorization;
|
String authorization;
|
||||||
|
|
||||||
public AuthorizationHeaderCredential(String bearer) {
|
public AuthorizationHeader(String bearer) {
|
||||||
super();
|
super();
|
||||||
this.credential = bearer;
|
this.credential = bearer;
|
||||||
this.credentialType = Credential.BEARER;
|
this.credentialType = Credential.BEARER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthorizationHeaderCredential(String username, String credential) {
|
public AuthorizationHeader(String username, String credential) {
|
||||||
super();
|
super();
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.credential = credential;
|
this.credential = credential;
|
||||||
@@ -39,25 +39,25 @@ public class AuthorizationHeaderUtils {
|
|||||||
public static String createBasic(String username, String password) {
|
public static String createBasic(String username, String password) {
|
||||||
String authUserPass = username + ":" + password;
|
String authUserPass = username + ":" + password;
|
||||||
String encodedAuthUserPass = Base64Utils.encode(authUserPass);
|
String encodedAuthUserPass = Base64Utils.encode(authUserPass);
|
||||||
return AuthorizationHeaderCredential.Credential.BASIC + encodedAuthUserPass;
|
return AuthorizationHeader.Credential.BASIC + encodedAuthUserPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createBearer(String bearer) {
|
public static String createBearer(String bearer) {
|
||||||
return AuthorizationHeaderCredential.Credential.BEARER + bearer;
|
return AuthorizationHeader.Credential.BEARER + bearer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthorizationHeaderCredential resolve(HttpServletRequest request) {
|
public static AuthorizationHeader resolve(HttpServletRequest request) {
|
||||||
String authorization = resolveBearer(request);
|
String authorization = resolveBearer(request);
|
||||||
return resolve(authorization);
|
return resolve(authorization);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthorizationHeaderCredential resolve(String authorization) {
|
public static AuthorizationHeader resolve(String authorization) {
|
||||||
if (StringUtils.isNotBlank(authorization) && isBasic(authorization)) {
|
if (StringUtils.isNotBlank(authorization) && isBasic(authorization)) {
|
||||||
String decodeUserPass = Base64Utils.decode(authorization.split(" ")[1]);
|
String decodeUserPass = Base64Utils.decode(authorization.split(" ")[1]);
|
||||||
String []userPass =decodeUserPass.split(":");
|
String []userPass =decodeUserPass.split(":");
|
||||||
return new AuthorizationHeaderCredential(userPass[0],userPass[1]);
|
return new AuthorizationHeader(userPass[0],userPass[1]);
|
||||||
} else {
|
} else {
|
||||||
return new AuthorizationHeaderCredential(resolveBearer(authorization));
|
return new AuthorizationHeader(resolveBearer(authorization));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ public class AuthorizationHeaderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBasic(String basic) {
|
public static boolean isBasic(String basic) {
|
||||||
if (basic.startsWith(AuthorizationHeaderCredential.Credential.BASIC)) {
|
if (basic.startsWith(AuthorizationHeader.Credential.BASIC)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -88,7 +88,7 @@ public class AuthorizationHeaderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean isBearer(String bearer) {
|
static boolean isBearer(String bearer) {
|
||||||
if (bearer.toLowerCase().startsWith(AuthorizationHeaderCredential.Credential.BEARER.toLowerCase())) {
|
if (bearer.toLowerCase().startsWith(AuthorizationHeader.Credential.BEARER.toLowerCase())) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
package org.maxkey.rest;
|
package org.maxkey.rest;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.util.AuthorizationHeaderCredential;
|
import org.maxkey.util.AuthorizationHeader;
|
||||||
import org.maxkey.util.AuthorizationHeaderUtils;
|
import org.maxkey.util.AuthorizationHeaderUtils;
|
||||||
|
|
||||||
public class AuthorizationHeaderTest {
|
public class AuthorizationHeaderTest {
|
||||||
@@ -32,7 +32,7 @@ public class AuthorizationHeaderTest {
|
|||||||
String ahc_basic ="Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==";
|
String ahc_basic ="Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==";
|
||||||
System.out.println(AuthorizationHeaderUtils.resolve(ahc_basic));
|
System.out.println(AuthorizationHeaderUtils.resolve(ahc_basic));
|
||||||
|
|
||||||
AuthorizationHeaderCredential ahc =new AuthorizationHeaderCredential("Aladdin");
|
AuthorizationHeader ahc =new AuthorizationHeader("Aladdin");
|
||||||
System.out.println(ahc.transform());
|
System.out.println(ahc.transform());
|
||||||
|
|
||||||
System.out.println(AuthorizationHeaderUtils.resolve(ahc.transform()));
|
System.out.println(AuthorizationHeaderUtils.resolve(ahc.transform()));
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import org.maxkey.authz.oauth2.common.exceptions.OAuth2Exception;
|
|||||||
import org.maxkey.authz.oauth2.provider.ClientDetailsService;
|
import org.maxkey.authz.oauth2.provider.ClientDetailsService;
|
||||||
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
||||||
import org.maxkey.authz.oauth2.provider.token.DefaultTokenServices;
|
import org.maxkey.authz.oauth2.provider.token.DefaultTokenServices;
|
||||||
import org.maxkey.util.AuthorizationHeaderCredential;
|
import org.maxkey.util.AuthorizationHeader;
|
||||||
import org.maxkey.util.JsonUtils;
|
import org.maxkey.util.JsonUtils;
|
||||||
import org.maxkey.util.RequestTokenUtils;
|
import org.maxkey.util.RequestTokenUtils;
|
||||||
import org.maxkey.web.HttpResponseAdapter;
|
import org.maxkey.web.HttpResponseAdapter;
|
||||||
@@ -91,7 +91,7 @@ public class IntrospectEndpoint {
|
|||||||
httpResponseAdapter.write(response,JsonUtils.gsonToString(introspection),"json");
|
httpResponseAdapter.write(response,JsonUtils.gsonToString(introspection),"json");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean clientAuthenticate(AuthorizationHeaderCredential headerCredential) {
|
public boolean clientAuthenticate(AuthorizationHeader headerCredential) {
|
||||||
if(headerCredential != null){
|
if(headerCredential != null){
|
||||||
UsernamePasswordAuthenticationToken authenticationToken = null;
|
UsernamePasswordAuthenticationToken authenticationToken = null;
|
||||||
if(headerCredential.isBasic()) {
|
if(headerCredential.isBasic()) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import org.maxkey.authz.oauth2.provider.AuthorizationRequest;
|
|||||||
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
||||||
import org.maxkey.authz.oauth2.provider.OAuth2Request;
|
import org.maxkey.authz.oauth2.provider.OAuth2Request;
|
||||||
import org.maxkey.authz.oauth2.provider.OAuth2RequestFactory;
|
import org.maxkey.authz.oauth2.provider.OAuth2RequestFactory;
|
||||||
import org.maxkey.util.AuthorizationHeaderCredential;
|
import org.maxkey.util.AuthorizationHeader;
|
||||||
import org.maxkey.util.AuthorizationHeaderUtils;
|
import org.maxkey.util.AuthorizationHeaderUtils;
|
||||||
import org.maxkey.web.WebContext;
|
import org.maxkey.web.WebContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -238,7 +238,7 @@ public class TokenEndpointAuthenticationFilter implements Filter {
|
|||||||
if(clientId == null) {
|
if(clientId == null) {
|
||||||
//for header authorization basic
|
//for header authorization basic
|
||||||
String authorization_bearer =request.getHeader("authorization");
|
String authorization_bearer =request.getHeader("authorization");
|
||||||
AuthorizationHeaderCredential ahc=AuthorizationHeaderUtils.resolve(authorization_bearer);
|
AuthorizationHeader ahc=AuthorizationHeaderUtils.resolve(authorization_bearer);
|
||||||
clientId =ahc.getUsername();
|
clientId =ahc.getUsername();
|
||||||
clientSecret=ahc.getCredential();
|
clientSecret=ahc.getCredential();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import org.maxkey.authn.web.AuthorizationUtils;
|
import org.maxkey.authn.web.AuthorizationUtils;
|
||||||
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
||||||
import org.maxkey.authz.oauth2.provider.token.DefaultTokenServices;
|
import org.maxkey.authz.oauth2.provider.token.DefaultTokenServices;
|
||||||
import org.maxkey.util.AuthorizationHeaderCredential;
|
import org.maxkey.util.AuthorizationHeader;
|
||||||
import org.maxkey.util.AuthorizationHeaderUtils;
|
import org.maxkey.util.AuthorizationHeaderUtils;
|
||||||
import org.maxkey.util.StringUtils;
|
import org.maxkey.util.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -62,7 +62,7 @@ public class RestApiPermissionAdapter implements AsyncHandlerInterceptor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
|
||||||
_logger.trace("Rest API Permission Adapter pre handle");
|
_logger.trace("Rest API Permission Adapter pre handle");
|
||||||
AuthorizationHeaderCredential headerCredential = AuthorizationHeaderUtils.resolve(request);
|
AuthorizationHeader headerCredential = AuthorizationHeaderUtils.resolve(request);
|
||||||
|
|
||||||
//判断应用的AppId和Secret
|
//判断应用的AppId和Secret
|
||||||
if(headerCredential != null){
|
if(headerCredential != null){
|
||||||
|
|||||||
Reference in New Issue
Block a user