Coverage Report - org.kuali.rice.ksb.security.service.impl.DigitalSignatureServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DigitalSignatureServiceImpl
0%
0/16
0%
0/4
1.8
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ksb.security.service.impl;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.security.GeneralSecurityException;
 20  
 import java.security.KeyException;
 21  
 import java.security.PublicKey;
 22  
 import java.security.Signature;
 23  
 import java.security.cert.Certificate;
 24  
 import java.security.cert.CertificateException;
 25  
 
 26  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 27  
 import org.kuali.rice.ksb.security.admin.service.JavaSecurityManagementService;
 28  
 import org.kuali.rice.ksb.security.service.DigitalSignatureService;
 29  
 import org.kuali.rice.ksb.util.KSBConstants;
 30  
 
 31  0
 public class DigitalSignatureServiceImpl implements DigitalSignatureService {
 32  
 
 33  
         public Signature getSignatureForSigning() throws IOException, GeneralSecurityException {
 34  0
                 Signature signature = getSignature();
 35  0
                 signature.initSign(getJavaSecurityManagementService().getModulePrivateKey());
 36  0
                 return signature;
 37  
         }
 38  
 
 39  
     public Signature getSignatureForVerification(String verificationAlias) throws IOException, GeneralSecurityException {
 40  0
         Certificate cert = getJavaSecurityManagementService().getCertificate(verificationAlias);
 41  0
         return getSignatureForVerification(cert);
 42  
     }
 43  
 
 44  
     public Signature getSignatureForVerification(Certificate certificate) throws IOException, GeneralSecurityException {
 45  0
         if (certificate == null) {
 46  0
             throw new CertificateException("Could not find certificate");
 47  
         }
 48  0
         PublicKey publicKey = certificate.getPublicKey();
 49  0
         if (publicKey == null) {
 50  0
             throw new KeyException("Could not find the public key from valid certificate");
 51  
         }
 52  0
         Signature signature = getSignature();
 53  0
         signature.initVerify(publicKey);
 54  0
         return signature;
 55  
     }
 56  
     
 57  
         protected Signature getSignature() throws GeneralSecurityException {
 58  0
                 return Signature.getInstance(getJavaSecurityManagementService().getModuleSignatureAlgorithm());
 59  
         }
 60  
         
 61  
         protected JavaSecurityManagementService getJavaSecurityManagementService() {
 62  0
                 return (JavaSecurityManagementService)GlobalResourceLoader.getService(KSBConstants.ServiceNames.JAVA_SECURITY_MANAGEMENT_SERVICE);
 63  
         }
 64  
 
 65  
 
 66  
 }