View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 package com.sun.xml.registry.ebxml.util; 11 12 import java.io.File; 13 14 import javax.xml.registry.JAXRException; 15 16 /*** 17 * Provides methods to check that jaxr-ebxml keystore properties are set 18 * correctly and keystore file exists. 19 * 20 * @author Fabian Ritzmann 21 */ 22 public class KeystoreUtil { 23 24 /*** 25 * Return location of keystore file defined in jaxr-ebxml properties 26 * 27 * @return Path to keystore file 28 * @throws JAXRException Thrown if properties are not set 29 */ 30 public static File getKeystoreFile() throws JAXRException { 31 32 String jaxrHomeFileName = 33 ProviderProperties.getInstance().getProperty("jaxr-ebxml.home"); 34 if ((jaxrHomeFileName == null) || (jaxrHomeFileName.length() == 0)) { 35 throw new JAXRException("Could not find property jaxr-ebxml.home"); 36 } 37 File jaxrHomeFile = new File(jaxrHomeFileName); 38 39 String keystoreFileName = 40 ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.keystore"); 41 if ((keystoreFileName == null) || (keystoreFileName.length() == 0)) { 42 throw new JAXRException("Could not find property jaxr-ebxml.security.keystore"); 43 } 44 return new File(jaxrHomeFile.getAbsolutePath(), keystoreFileName); 45 } 46 47 48 /*** 49 * Returns if keystore file can be read, throws an exception otherwise 50 * 51 * @param keystoreFile Path to keystore file 52 * @throws JAXRException Thrown if keystore file can not be read 53 */ 54 public static void canReadKeystoreFile(File keystoreFile) 55 throws JAXRException { 56 57 try { 58 if (! keystoreFile.exists()) 59 throw new JAXRException("Keystore file \"" 60 + keystoreFile.getAbsolutePath() + "\" does not exist"); 61 62 if (! keystoreFile.canRead()) 63 throw new JAXRException("Could not read keystore file \"" 64 + keystoreFile.getAbsolutePath() + "\""); 65 66 } catch (SecurityException e) { 67 throw new JAXRException("Could not read keystore file \"" 68 + keystoreFile.getAbsolutePath() + "\"", e); 69 } 70 71 } 72 73 74 /*** 75 * Create keystore directory if it does not already exist 76 * 77 * @param keystoreFile Path to keystore file 78 * @throws JAXRException Thrown if directory could not be created 79 */ 80 public static void createKeystoreDirectory(File keystoreFile) 81 throws JAXRException { 82 83 File keystoreDir = keystoreFile.getParentFile(); 84 try { 85 // Ignore return value of mkdirs, returns false if directories 86 // already exist 87 keystoreDir.mkdirs(); 88 } catch (SecurityException e) { 89 throw new JAXRException("Could not create directory \"" 90 + keystoreDir.getAbsolutePath() + "\" for keystore", e); 91 } 92 } 93 94 }

This page was automatically generated by Maven