use of org.apache.cxf.common.util.Base64Exception in project cxf by apache.
the class AbstractHawkAccessTokenValidator method validateAccessToken.
public AccessTokenValidation validateAccessToken(MessageContext mc, String authScheme, String authSchemeData, MultivaluedMap<String, String> extraProps) throws OAuthServiceException {
Map<String, String> schemeParams = getSchemeParameters(authSchemeData);
AccessTokenValidation atv = getAccessTokenValidation(mc, authScheme, authSchemeData, extraProps, schemeParams);
if (isRemoteSignatureValidation()) {
return atv;
}
String macKey = atv.getExtraProps().get(OAuthConstants.HAWK_TOKEN_KEY);
String macAlgo = atv.getExtraProps().get(OAuthConstants.HAWK_TOKEN_ALGORITHM);
HttpRequestProperties httpProps = null;
if (extraProps != null && extraProps.containsKey(HTTP_VERB) && extraProps.containsKey(HTTP_URI)) {
httpProps = new HttpRequestProperties(URI.create(extraProps.getFirst(HTTP_URI)), extraProps.getFirst(HTTP_VERB));
} else {
httpProps = new HttpRequestProperties(mc.getUriInfo().getRequestUri(), mc.getHttpServletRequest().getMethod());
}
HawkAuthorizationScheme macAuthInfo = new HawkAuthorizationScheme(httpProps, schemeParams);
String normalizedString = macAuthInfo.getNormalizedRequestString();
try {
HmacAlgorithm hmacAlgo = HmacAlgorithm.toHmacAlgorithm(macAlgo);
byte[] serverMacData = HmacUtils.computeHmac(macKey, hmacAlgo.getJavaName(), normalizedString);
String clientMacString = schemeParams.get(OAuthConstants.HAWK_TOKEN_SIGNATURE);
byte[] clientMacData = Base64Utility.decode(clientMacString);
boolean validMac = MessageDigest.isEqual(serverMacData, clientMacData);
if (!validMac) {
AuthorizationUtils.throwAuthorizationFailure(Collections.singleton(OAuthConstants.HAWK_AUTHORIZATION_SCHEME));
}
} catch (Base64Exception e) {
throw new OAuthServiceException(OAuthConstants.SERVER_ERROR, e);
}
validateTimestampNonce(macKey, macAuthInfo.getTimestamp(), macAuthInfo.getNonce());
return atv;
}
use of org.apache.cxf.common.util.Base64Exception in project cxf by apache.
the class Base64DecoderStream method decodeStreamData.
/**
* Decode a requested number of bytes of data into a buffer.
*
* @return true if we were able to obtain more data, false otherwise.
*/
private boolean decodeStreamData() throws IOException {
decodedIndex = 0;
// fill up a data buffer with input data
int readCharacters = fillEncodedBuffer();
if (readCharacters > 0) {
try {
decodedChars = Base64Utility.decodeChunk(encodedChars, 0, readCharacters);
} catch (Base64Exception e) {
throw new IOException(e);
}
decodedCount = decodedChars.length;
return true;
}
return false;
}
use of org.apache.cxf.common.util.Base64Exception in project midpoint by Evolveum.
the class SamlModuleWebSecurityConfiguration method getSaml2Credential.
public static Saml2X509Credential getSaml2Credential(ModuleSaml2SimpleKeyType key, boolean isActive) {
if (key == null) {
return null;
}
PrivateKey pkey;
try {
pkey = getPrivateKey(key, protector);
} catch (IOException | OperatorCreationException | PKCSException | EncryptionException e) {
throw new Saml2Exception("Unable get key from " + key, e);
}
Certificate certificate;
try {
certificate = getCertificate(key, protector);
} catch (Base64Exception | EncryptionException | CertificateException e) {
throw new Saml2Exception("Unable get certificate from " + key, e);
}
List<Saml2X509Credential.Saml2X509CredentialType> types = getTypesForKey(isActive, key.getType());
return new Saml2X509Credential(pkey, (X509Certificate) certificate, types.toArray(new Saml2X509Credential.Saml2X509CredentialType[0]));
}
use of org.apache.cxf.common.util.Base64Exception in project midpoint by Evolveum.
the class OidcResourceServerModuleWebSecurityConfiguration method initializePublicKeyDecoderFromCertificate.
private static NimbusJwtDecoder.PublicKeyJwtDecoderBuilder initializePublicKeyDecoderFromCertificate(ProtectedStringType certificateType) {
if (certificateType == null) {
return null;
}
PublicKey publicKey;
try {
Certificate certificate = getCertificate(certificateType, protector);
publicKey = certificate.getPublicKey();
} catch (Base64Exception | EncryptionException | CertificateException e) {
throw new OAuth2AuthenticationException(new OAuth2Error("missing_key"), "Unable get certificate", e);
}
return NimbusJwtDecoder.withPublicKey((RSAPublicKey) publicKey);
}
use of org.apache.cxf.common.util.Base64Exception in project midpoint by Evolveum.
the class OidcClientModuleWebSecurityConfiguration method initializeProofKey.
private static void initializeProofKey(AbstractSimpleKeyType key, OidcAdditionalConfiguration.Builder builder) {
if (key == null) {
return;
}
PrivateKey pkey;
try {
pkey = getPrivateKey(key, protector);
} catch (IOException | OperatorCreationException | PKCSException | EncryptionException e) {
throw new OAuth2AuthenticationException(new OAuth2Error("missing_key"), "Unable get key from " + key, e);
}
if (!(pkey instanceof RSAPrivateKey)) {
throw new OAuth2AuthenticationException(new OAuth2Error("missing_key"), "Unable get key from " + key);
}
PublicKey publicKey;
try {
Certificate certificate = getCertificate(key, protector);
publicKey = certificate.getPublicKey();
} catch (Base64Exception | EncryptionException | CertificateException e) {
throw new OAuth2AuthenticationException(new OAuth2Error("missing_key"), "Unable get certificate from " + key, e);
}
builder.privateKey((RSAPrivateKey) pkey);
builder.publicKey((RSAPublicKey) publicKey);
}
Aggregations