You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2015/08/06 15:02:32 UTC
cxf git commit: Adding a couple of jose exception classes
Repository: cxf
Updated Branches:
refs/heads/master a515dcaaf -> ee6039d7f
Adding a couple of jose exception classes
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/ee6039d7
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ee6039d7
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ee6039d7
Branch: refs/heads/master
Commit: ee6039d7fd2ddece276fb9539883041a04a7f72e
Parents: a515dca
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Thu Aug 6 14:02:09 2015 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Thu Aug 6 14:02:09 2015 +0100
----------------------------------------------------------------------
.../cxf/rs/security/jose/jwk/JwkException.java | 35 ++++++++++++++++++++
.../cxf/rs/security/jose/jwk/JwkUtils.java | 8 ++---
.../jose/jwt/AbstractJoseJwtConsumer.java | 5 ++-
.../jose/jwt/AbstractJoseJwtProducer.java | 3 +-
.../cxf/rs/security/jose/jwt/JwtException.java | 35 ++++++++++++++++++++
.../cxf/rs/security/jose/jwt/JwtUtils.java | 4 +--
6 files changed, 79 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/ee6039d7/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkException.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkException.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkException.java
new file mode 100644
index 0000000..44e9535
--- /dev/null
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkException.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.rs.security.jose.jwk;
+
+import org.apache.cxf.rs.security.jose.JoseException;
+
+public class JwkException extends JoseException {
+
+ private static final long serialVersionUID = 4118589816228511524L;
+ public JwkException() {
+
+ }
+ public JwkException(String error) {
+ super(error);
+ }
+ public JwkException(Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/ee6039d7/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
index b70a01c..e1f161c 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
@@ -278,11 +278,11 @@ public final class JwkUtils {
try {
InputStream is = ResourceUtils.getResourceStream(keyStoreLoc, bus);
if (is == null) {
- throw new SecurityException("Error in loading keystore location: " + keyStoreLoc);
+ throw new JwkException("Error in loading keystore location: " + keyStoreLoc);
}
keyContent = IOUtils.readStringFromStream(is);
} catch (Exception ex) {
- throw new SecurityException(ex);
+ throw new JwkException(ex);
}
} else {
keyContent = props.getProperty(RSSEC_KEY_STORE_JWKSET);
@@ -469,7 +469,7 @@ public final class JwkUtils {
}
public static JsonWebKey fromSecretKey(SecretKey secretKey, String algo) {
if (!AlgorithmUtils.isOctet(algo)) {
- throw new SecurityException("Invalid algorithm");
+ throw new JwkException("Invalid algorithm");
}
JsonWebKey jwk = new JsonWebKey();
jwk.setKeyType(KeyType.OCTET);
@@ -491,7 +491,7 @@ public final class JwkUtils {
}
private static JsonWebKey prepareRSAJwk(BigInteger modulus, String algo) {
if (!AlgorithmUtils.isRsa(algo)) {
- throw new SecurityException("Invalid algorithm");
+ throw new JwkException("Invalid algorithm");
}
JsonWebKey jwk = new JsonWebKey();
jwk.setKeyType(KeyType.RSA);
http://git-wip-us.apache.org/repos/asf/cxf/blob/ee6039d7/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtConsumer.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtConsumer.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtConsumer.java
index 0708cac..608f09e 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtConsumer.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtConsumer.java
@@ -19,7 +19,6 @@
package org.apache.cxf.rs.security.jose.jwt;
import org.apache.cxf.rs.security.jose.AbstractJoseConsumer;
-import org.apache.cxf.rs.security.jose.JoseException;
import org.apache.cxf.rs.security.jose.jwe.JweDecryptionProvider;
import org.apache.cxf.rs.security.jose.jwe.JweJwtCompactConsumer;
import org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer;
@@ -31,7 +30,7 @@ public abstract class AbstractJoseJwtConsumer extends AbstractJoseConsumer {
protected JwtToken getJwtToken(String wrappedJwtToken) {
if (!isJwsRequired() && !isJweRequired()) {
- throw new JoseException("Unable to process JWT");
+ throw new JwtException("Unable to process JWT");
}
JweDecryptionProvider jweDecryptor = getInitializedDecryptionProvider(isJweRequired());
if (jweDecryptor != null) {
@@ -45,7 +44,7 @@ public abstract class AbstractJoseJwtConsumer extends AbstractJoseConsumer {
JwtToken jwt = jwtConsumer.getJwtToken();
JwsSignatureVerifier theSigVerifier = getInitializedSignatureVerifier(jwt);
if (!jwtConsumer.verifySignatureWith(theSigVerifier)) {
- throw new SecurityException("Invalid Signature");
+ throw new JwtException("Invalid Signature");
}
validateToken(jwt);
return jwt;
http://git-wip-us.apache.org/repos/asf/cxf/blob/ee6039d7/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtProducer.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtProducer.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtProducer.java
index 6ec4b44..b90b386 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtProducer.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/AbstractJoseJwtProducer.java
@@ -20,7 +20,6 @@ package org.apache.cxf.rs.security.jose.jwt;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.rs.security.jose.AbstractJoseProducer;
-import org.apache.cxf.rs.security.jose.JoseException;
import org.apache.cxf.rs.security.jose.jwe.JweEncryptionProvider;
import org.apache.cxf.rs.security.jose.jwe.JweJwtCompactProducer;
import org.apache.cxf.rs.security.jose.jws.JwsJwtCompactProducer;
@@ -32,7 +31,7 @@ public abstract class AbstractJoseJwtProducer extends AbstractJoseProducer {
protected String processJwt(JwtToken jwt) {
if (!isJwsRequired() && !isJweRequired()) {
- throw new JoseException("Unable to secure JWT");
+ throw new JwtException("Unable to secure JWT");
}
String data = null;
JweEncryptionProvider theEncProvider = getInitializedEncryptionProvider(isJweRequired());
http://git-wip-us.apache.org/repos/asf/cxf/blob/ee6039d7/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtException.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtException.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtException.java
new file mode 100644
index 0000000..84314bd
--- /dev/null
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtException.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.rs.security.jose.jwt;
+
+import org.apache.cxf.rs.security.jose.JoseException;
+
+public class JwtException extends JoseException {
+
+ private static final long serialVersionUID = 4118589816228511524L;
+ public JwtException() {
+
+ }
+ public JwtException(String error) {
+ super(error);
+ }
+ public JwtException(Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/ee6039d7/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java
index 302d9c0..c846659 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java
@@ -42,7 +42,7 @@ public final class JwtUtils {
Long expiryTimeInSecs = claims.getExpiryTime();
if (expiryTimeInSecs == null && claimsRequired
|| expiryTimeInSecs != null && currentTimeInSecs > expiryTimeInSecs) {
- throw new SecurityException("The token expired");
+ throw new JwtException("The token expired");
}
Long issuedAtInSecs = claims.getIssuedAt();
if (clockOffset <= 0) {
@@ -51,7 +51,7 @@ public final class JwtUtils {
if (issuedAtInSecs == null && claimsRequired
|| issuedAtInSecs != null && (issuedAtInSecs - clockOffset > currentTimeInSecs || issuedAtRange > 0
&& issuedAtInSecs < currentTimeInSecs - issuedAtRange)) {
- throw new SecurityException("Invalid issuedAt");
+ throw new JwtException("Invalid issuedAt");
}
}