This commit is contained in:
Crystal.Sea
2021-09-24 14:37:15 +08:00
parent 5f4c44ec59
commit 2fdd018239
114 changed files with 451 additions and 812 deletions

View File

@@ -25,8 +25,6 @@ package org.maxkey.authz.cas.endpoint.ticket;
* @since 4.2.0
*/
public abstract class AbstractTicketException{
private static final long serialVersionUID = -5128676415951733624L;
String code;
String msg;
Throwable throwable;

View File

@@ -33,8 +33,6 @@ import org.slf4j.LoggerFactory;
*/
public abstract class AbstractWebApplicationService {
private static final long serialVersionUID = 610105280927740076L;
/** Logger instance. **/
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractWebApplicationService.class);

View File

@@ -31,7 +31,7 @@ package org.maxkey.authz.cas.endpoint.ticket;
* </p>
*/
public interface Service {
boolean getId();
String getId();
boolean matches(Service service);
}

View File

@@ -26,8 +26,6 @@ package org.maxkey.authz.cas.endpoint.ticket;
*/
public final class SimpleWebApplicationServiceImpl extends AbstractWebApplicationService {
private static final long serialVersionUID = 8334068957483758042L;
public SimpleWebApplicationServiceImpl(final String id) {
this(id, id, null);
}

View File

@@ -17,9 +17,6 @@
package org.maxkey.authz.cas.endpoint.ticket.generator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
/**
@@ -29,8 +26,7 @@ import java.net.InetAddress;
* @since 5.0.0
*/
public final class InetAddressUtils {
private static final Logger logger = LoggerFactory.getLogger(InetAddressUtils.class);
private InetAddressUtils() {
}

View File

@@ -42,7 +42,6 @@ public class RestTestClient {
String password ="maxkey";
String serviceUrl = "http://cas.demo.maxkey.top:9521/demo-cas/";
CasConfiguration casConfiguration = new CasConfiguration(casUrlPrefix);
final CasRestAuthenticator authenticator = new CasRestAuthenticator(casConfiguration);
final CasRestFormClient client = new CasRestFormClient(casConfiguration,"username","password");
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
@@ -61,7 +60,7 @@ public class RestTestClient {
Map<String,Object> attributes = casProfile.getAttributes();
Set<Map.Entry<String,Object>> mapEntries = attributes.entrySet();
for (Map.Entry entry : mapEntries) {
for (Map.Entry<String,Object> entry : mapEntries) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
client.destroyTicketGrantingTicket(profile,webContext);

View File

@@ -64,7 +64,8 @@ public class ExtendApiCndnsApiMailAdapter extends AbstractAuthorizeAdapter {
return null;
}
@Override
@SuppressWarnings("unchecked")
@Override
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
HttpsTrusts.beforeConnection();

View File

@@ -53,18 +53,21 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
return null;
}
@Override
@SuppressWarnings("unchecked")
@Override
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
HttpsTrusts.beforeConnection();
Apps details=(Apps)app;
String username = data.substring(0, data.indexOf("="));
String password = data.substring(data.indexOf("=") + 1);
_logger.trace("username " + username +" password " + password);
//extraAttrs from Applications
ExtraAttrs extraAttrs=null;
if(details.getIsExtendAttr()==1){
extraAttrs=new ExtraAttrs(details.getExtendAttr());
}
_logger.debug("Extra Attrs "+extraAttrs);
OAuthClient tokenRestClient=new OAuthClient(
String.format(TOKEN_URI,details.getPrincipal(),details.getCredentials()));
Token token =tokenRestClient.requestAccessToken();

View File

@@ -62,6 +62,7 @@ public class ExtendApiZentaoAdapter extends AbstractAuthorizeAdapter {
if(details.getIsExtendAttr()==1){
extraAttrs=new ExtraAttrs(details.getExtendAttr());
}
_logger.trace("Extra Attrs " + extraAttrs);
String code = details.getPrincipal();
String key = details.getCredentials();
String time = ""+Instant.now().getEpochSecond();

View File

@@ -26,6 +26,11 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
*/
public class OAuth2ExceptionJackson2Serializer extends StdSerializer<OAuth2Exception> {
/**
*
*/
private static final long serialVersionUID = -767680428859994107L;
public OAuth2ExceptionJackson2Serializer() {
super(OAuth2Exception.class);
}

View File

@@ -113,7 +113,7 @@ class JwtHeaderHelper {
static HeaderParameters parseParams(byte[] header) {
JsonParser jp = null;
try {
jp = f.createJsonParser(header);
jp = f.createParser(header);
String alg = null, enc = null, iv = null;
jp.nextToken();
while (jp.nextToken() != JsonToken.END_OBJECT) {
@@ -163,7 +163,7 @@ class JwtHeaderHelper {
JsonGenerator g = null;
try {
g = f.createJsonGenerator(baos);
g = f.createGenerator(baos);
g.writeStartObject();
g.writeStringField("alg", params.alg);
if (params.enc != null) {

View File

@@ -649,6 +649,11 @@ final class Base64Codec {
class InvalidBase64CharacterException extends IllegalArgumentException {
/**
*
*/
private static final long serialVersionUID = -616861303718228577L;
InvalidBase64CharacterException(String message) {
super(message);
}

View File

@@ -16,6 +16,11 @@ package org.maxkey.authz.oauth2.jwt.crypto.sign;
* @author Luke Taylor
*/
public class InvalidSignatureException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 7078872206905207270L;
public InvalidSignatureException(String message) {
super(message);
}

View File

@@ -20,10 +20,8 @@ import org.maxkey.authn.online.OnlineTicket;
import org.maxkey.entity.UserInfo;
import org.maxkey.persistence.db.LoginService;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

View File

@@ -23,6 +23,7 @@ import org.maxkey.authz.oauth2.common.util.JsonDateDeserializer;
import org.maxkey.authz.oauth2.common.util.JsonDateSerializer;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@@ -31,7 +32,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
* @author Vidya Val
*
*/
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Approval {
private String userId;
@@ -97,7 +98,8 @@ public class Approval {
this.scope = scope == null ? "" : scope;
}
@JsonSerialize(using = JsonDateSerializer.class, include = JsonSerialize.Inclusion.NON_NULL)
@JsonSerialize(using = JsonDateSerializer.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public Date getExpiresAt() {
return expiresAt;
}
@@ -112,7 +114,8 @@ public class Approval {
this.expiresAt = expiresAt;
}
@JsonSerialize(using = JsonDateSerializer.class, include = JsonSerialize.Inclusion.NON_NULL)
@JsonSerialize(using = JsonDateSerializer.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public Date getLastUpdatedAt() {
return lastUpdatedAt;
}

View File

@@ -83,7 +83,7 @@ public class JdbcApprovalStore implements ApprovalStore {
private boolean handleRevocationsAsExpiry = false;
public JdbcApprovalStore(DataSource dataSource) {
Assert.notNull(dataSource);
Assert.notNull(dataSource,"DataSource must not null");
this.jdbcTemplate = new JdbcTemplate(dataSource);
}

View File

@@ -20,7 +20,6 @@ package org.maxkey.authz.oauth2.provider.code;
import java.util.UUID;
import org.maxkey.authz.oauth2.common.exceptions.InvalidGrantException;
import org.maxkey.authz.oauth2.common.util.RandomValueStringGenerator;
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
/**
@@ -32,7 +31,7 @@ import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
public abstract class RandomValueAuthorizationCodeServices implements AuthorizationCodeServices {
//default Random code Generator
private RandomValueStringGenerator generator = new RandomValueStringGenerator();
//private RandomValueStringGenerator generator = new RandomValueStringGenerator();
protected abstract void store(String code, OAuth2Authentication authentication);

View File

@@ -36,14 +36,11 @@ import org.apache.commons.logging.LogFactory;
import org.maxkey.authz.oauth2.common.OAuth2AccessToken;
import org.maxkey.authz.oauth2.common.OAuth2Constants;
import org.maxkey.authz.oauth2.common.exceptions.InvalidTokenException;
import org.maxkey.authz.oauth2.common.exceptions.OAuth2Exception;
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
import org.maxkey.authz.oauth2.provider.token.AccessTokenConverter;
import org.maxkey.authz.oauth2.provider.token.DefaultAccessTokenConverter;
import org.maxkey.authz.oauth2.provider.token.ResourceServerTokenServices;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

View File

@@ -31,6 +31,7 @@ package org.maxkey.authz.oauth2.provider.token;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -44,7 +45,6 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.codec.Base64;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -134,7 +134,7 @@ public class RemoteTokenServices implements ResourceServerTokenServices {
private String getAuthorizationHeader(String clientId, String clientSecret) {
String creds = String.format("%s:%s", clientId, clientSecret);
try {
return "Basic " + new String(Base64.encode(creds.getBytes("UTF-8")));
return "Basic " + new String(Base64.getEncoder().encodeToString(creds.getBytes("UTF-8")));
}
catch (UnsupportedEncodingException e) {
throw new IllegalStateException("Could not convert String");

View File

@@ -33,6 +33,7 @@ import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.Base64;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -62,7 +63,6 @@ import org.maxkey.authz.oauth2.provider.token.AccessTokenConverter;
import org.maxkey.authz.oauth2.provider.token.DefaultAccessTokenConverter;
import org.maxkey.authz.oauth2.provider.token.TokenEnhancer;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.crypto.codec.Base64;
import org.springframework.util.Assert;
/**
@@ -144,7 +144,7 @@ public class JwtAccessTokenConverter implements TokenEnhancer, AccessTokenConver
signer = new RsaSigner((RSAPrivateKey) privateKey);
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
verifier = new RsaVerifier(publicKey);
verifierKey = "-----BEGIN PUBLIC KEY-----\n" + new String(Base64.encode(publicKey.getEncoded()))
verifierKey = "-----BEGIN PUBLIC KEY-----\n" + new String(Base64.getMimeEncoder().encodeToString(publicKey.getEncoded()))
+ "\n-----END PUBLIC KEY-----";
}
@@ -155,7 +155,7 @@ public class JwtAccessTokenConverter implements TokenEnhancer, AccessTokenConver
* @param key the key to be used for signing JWTs.
*/
public void setSigningKey(String key) {
Assert.hasText(key);
Assert.hasText(key,"key must not be empty");
key = key.trim();
this.signingKey = key;

View File

@@ -43,20 +43,22 @@ import java.util.Date;
public class RedisTokenStore implements TokenStore {
static final Logger _logger = LoggerFactory.getLogger(RedisTokenStore.class);
private static final String ACCESS = "REDIS_OAUTH_V20_ACCESS_";
private static final String AUTH_TO_ACCESS = "REDIS_OAUTH_V20_AUTH_TO_ACCESS_";
private static final String AUTH = "REDIS_OAUTH_V20_AUTH_";
private static final String REFRESH_AUTH = "REDIS_OAUTH_V20_REFRESH_AUTH_";
private static final String ACCESS_TO_REFRESH = "REDIS_OAUTH_V20_ACCESS_TO_REFRESH_";
private static final String REFRESH = "REDIS_OAUTH_V20_REFRESH_";
private static final String REFRESH_TO_ACCESS = "REDIS_OAUTH_V20_REFRESH_TO_ACCESS_";
private static final String CLIENT_ID_TO_ACCESS = "REDIS_OAUTH_V20_CLIENT_ID_TO_ACCESS_";
private static final String UNAME_TO_ACCESS = "REDIS_OAUTH_V20_UNAME_TO_ACCESS_";
private static final String PREFIX = "REDIS_OAUTH_V20_";
private static final String ACCESS = PREFIX + "ACCESS_";
private static final String AUTH_TO_ACCESS = PREFIX + "AUTH_TO_ACCESS_";
private static final String AUTH = PREFIX + "AUTH_";
private static final String REFRESH_AUTH = PREFIX + "REFRESH_AUTH_";
private static final String ACCESS_TO_REFRESH = PREFIX + "ACCESS_TO_REFRESH_";
private static final String REFRESH = PREFIX + "REFRESH_";
private static final String REFRESH_TO_ACCESS = PREFIX + "REFRESH_TO_ACCESS_";
private static final String CLIENT_ID_TO_ACCESS = PREFIX + "CLIENT_ID_TO_ACCESS_";
private static final String UNAME_TO_ACCESS = PREFIX + "UNAME_TO_ACCESS_";
private final RedisConnectionFactory connectionFactory;
private AuthenticationKeyGenerator authenticationKeyGenerator = new DefaultAuthenticationKeyGenerator();
private String prefix = "";
public RedisTokenStore(RedisConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
@@ -66,11 +68,6 @@ public class RedisTokenStore implements TokenStore {
this.authenticationKeyGenerator = authenticationKeyGenerator;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
private RedisConnection getConnection() {
return connectionFactory.getConnection();
}

View File

@@ -47,6 +47,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Strings;
import com.nimbusds.jose.Algorithm;
import com.nimbusds.jose.EncryptionMethod;
import com.nimbusds.jose.JWEAlgorithm;
import com.nimbusds.jose.JWEHeader;
@@ -164,7 +165,7 @@ public class OIDCIdTokenEnhancer implements TokenEnhancer {
logger.error("Couldn't create Jwt Encryption Service");
}
} else {
if (signingAlg==null||signingAlg.equals("none")) {
if (signingAlg==null||signingAlg.equals(Algorithm.NONE)) {
// unsigned ID token
idToken = new PlainJWT(builder.build());
} else {

View File

@@ -150,7 +150,7 @@ public class Oauth20AutoConfiguration implements InitializingBean {
throws NoSuchAlgorithmException, InvalidKeySpecException, JOSEException {
DefaultJwtEncryptionAndDecryptionService jwtEncryptionService =
new DefaultJwtEncryptionAndDecryptionService(jwtSetKeyStore);
jwtEncryptionService.setDefaultAlgorithm(JWEAlgorithm.RSA1_5);//RSA1_5
jwtEncryptionService.setDefaultAlgorithm(JWEAlgorithm.RSA_OAEP_256);//RSA1_5
jwtEncryptionService.setDefaultDecryptionKeyId("maxkey_rsa");
jwtEncryptionService.setDefaultEncryptionKeyId("maxkey_rsa");
return jwtEncryptionService;

View File

@@ -1,3 +0,0 @@
Manifest-Version: 1.0
Class-Path:

View File

@@ -35,6 +35,7 @@ import org.maxkey.authz.saml.common.EndpointGenerator;
import org.maxkey.authz.saml.common.TrustResolver;
import org.maxkey.authz.saml.service.IDService;
import org.maxkey.authz.saml.service.TimeService;
import org.maxkey.authz.saml20.binding.BindingAdapter;
import org.maxkey.authz.saml20.binding.ExtractBindingAdapter;
import org.maxkey.authz.saml20.consumer.AuthnRequestGenerator;
import org.maxkey.authz.saml20.consumer.spring.IdentityProviderAuthenticationException;
@@ -51,6 +52,7 @@ import org.opensaml.common.binding.security.MessageReplayRule;
import org.opensaml.saml2.core.Assertion;
import org.opensaml.saml2.core.Response;
import org.opensaml.saml2.core.StatusCode;
import org.opensaml.ws.message.decoder.MessageDecodingException;
import org.opensaml.xml.security.CriteriaSet;
import org.opensaml.xml.security.SecurityException;
import org.opensaml.xml.security.credential.Credential;
@@ -77,6 +79,8 @@ public class ConsumerEndpoint {
private final static Logger logger = LoggerFactory.getLogger(ConsumerEndpoint.class);
private BindingAdapter bindingAdapter;
@Autowired
@Qualifier("spKeyStoreLoader")
private KeyStoreLoader keyStoreLoader;
@@ -129,8 +133,8 @@ public class ConsumerEndpoint {
initCredential(spId);
SAMLMessageContext messageContext=null;
/*try {
/*
try {
messageContext = bindingAdapter.extractSAMLMessageContext(request);
} catch (MessageDecodingException me) {
logger.error("Could not decode SAML Response", me);

View File

@@ -18,12 +18,6 @@
package org.maxkey.authz.saml20.jit;
import java.util.HashMap;
import java.util.List;
import org.maxkey.entity.UserInfo;
public interface ProvisioningAdapter {
//HashMap<String,String> construct(UserInfo userInfo,Companys company,List<Roles> listRoles) ;

View File

@@ -21,7 +21,6 @@ import org.opensaml.xml.Configuration;
import org.opensaml.xml.XMLObject;
import org.opensaml.xml.validation.ValidationException;
import org.opensaml.xml.validation.ValidatorSuite;
import org.springframework.beans.factory.InitializingBean;
public class SAML2ValidatorSuite {

View File

@@ -107,6 +107,7 @@ public class Saml20AutoConfiguration implements InitializingBean {
@Bean(name = "authnResponseGenerator")
public AuthnResponseGenerator authnResponseGenerator(TimeService timeService,IDService idService,
@Value("${maxkey.saml.v20.idp.issuer}") String issuerEntityName) {
_logger.debug("issuerEntityName " + issuerEntityName);
AuthnResponseGenerator generator = new AuthnResponseGenerator(issuerEntityName,timeService,idService);
return generator;
}
@@ -163,6 +164,7 @@ public class Saml20AutoConfiguration implements InitializingBean {
* MapBasedStorageService.
* @return mapBasedStorageService
*/
@SuppressWarnings("rawtypes")
@Bean(name = "mapBasedStorageService")
public MapBasedStorageService mapBasedStorageService() {
MapBasedStorageService mapBasedStorageService = new MapBasedStorageService();
@@ -175,6 +177,7 @@ public class Saml20AutoConfiguration implements InitializingBean {
* @throws IOException
* @throws VelocityException
*/
@SuppressWarnings({ "deprecation"})
@Bean(name = "velocityEngine")
public VelocityEngine velocityEngine() throws VelocityException, IOException {
VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();