encrypt/decrypt implemented. initial commit for unit testing of jwe service.

pull/650/head
William Kim 11 years ago committed by Justin Richer
parent 59f13a66b6
commit 8cb72dc9de

@ -51,4 +51,9 @@ public interface JwtEncryptionAndDecryptionService {
* @return
*/
public Collection<JWEAlgorithm> getAllEncryptionAlgsSupported();
/**
* TODO add functionality for encrypting and decrypting using a specified key id.
* Example: public void encryptJwt(EncryptedJWT jwt, String kid);
*/
}

@ -103,13 +103,12 @@ public class DefaultJwtEncryptionAndDecryptionService implements JwtEncryptionAn
@PostConstruct
public void afterPropertiesSet() throws NoSuchAlgorithmException, InvalidKeySpecException{
public void afterPropertiesSet() throws NoSuchAlgorithmException, InvalidKeySpecException, JOSEException{
if (keys == null) {
throw new IllegalArgumentException("Encryption and decryption service must have at least one key configured.");
}
// TODO call build..() again? see default signer service.
buildEncryptersAndDecrypters();
}
public String getDefaultEncryptionKeyId() {
@ -141,7 +140,18 @@ public class DefaultJwtEncryptionAndDecryptionService implements JwtEncryptionAn
*/
@Override
public void encryptJwt(EncryptedJWT jwt) {
// TODO Auto-generated method stub
if (getDefaultEncryptionKeyId() == null) {
throw new IllegalStateException("Tried to call default encryption with no default encrypter ID set");
}
JWEEncrypter encrypter = encrypters.get(getDefaultEncryptionKeyId());
try {
jwt.encrypt(encrypter);
} catch (JOSEException e) {
logger.error("Failed to encrypt JWT, error was: ", e);
}
}
@ -150,7 +160,18 @@ public class DefaultJwtEncryptionAndDecryptionService implements JwtEncryptionAn
*/
@Override
public void decryptJwt(EncryptedJWT jwt) {
// TODO Auto-generated method stub
if (getDefaultDecryptionKeyId() == null) {
throw new IllegalStateException("Tried to call default decryption with no default decrypter ID set");
}
JWEDecrypter decrypter = decrypters.get(getDefaultDecryptionKeyId());
try {
jwt.decrypt(decrypter);
} catch (JOSEException e) {
logger.error("Failed to decrypt JWT, error was: ", e);
}
}

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright 2013 The MITRE Corporation
* and the MIT Kerberos and Internet Trust Consortium
*
* Licensed 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.mitre.jwt.encryption.service.impl;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author wkim
*
*/
public class TestDefaultJwtEncryptionAndDecryptionService {
@Test
public void test() {
fail("Not yet implemented");
}
}
Loading…
Cancel
Save