KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > config > CertificateFile


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.subversion.config;
21
22 import java.io.File JavaDoc;
23 import java.security.cert.CertificateEncodingException JavaDoc;
24 import java.security.cert.X509Certificate JavaDoc;
25 import org.netbeans.modules.subversion.config.KVFile.Key;
26 import org.openide.filesystems.FileUtil;
27
28 /**
29  * Represents a Subversions file holding a X509Certificate for a realmstring.
30  *
31  * @author Tomas Stupka
32  */

33 public class CertificateFile extends SVNCredentialFile {
34
35     private final static Key CERT = new Key(0, "ascii_cert"); // NOI18N
36
private final static Key FAILURES = new Key(1, "failures"); // NOI18N
37
private final static Key REALMSTRING = new Key(2, "svn:realmstring"); // NOI18N
38

39     private static final String JavaDoc NEWLINE = System.getProperty("line.separator"); // NOI18N
40

41     public CertificateFile(X509Certificate JavaDoc cert, String JavaDoc realmString, int failures, boolean temporarily) throws CertificateEncodingException JavaDoc {
42         super(getNBCertFile(realmString));
43         setCert(cert);
44         setFailures(failures);
45         setRealmString(realmString);
46         if(temporarily) {
47             getFile().deleteOnExit();
48         }
49     }
50
51     private void setCert(X509Certificate JavaDoc cert) throws CertificateEncodingException JavaDoc {
52         String JavaDoc encodedCert = new sun.misc.BASE64Encoder().encode(cert.getEncoded());
53         encodedCert = encodedCert.replace(NEWLINE, ""); // XXX where does this come from ????!!! // NOI18N
54
setValue(getCertKey(), encodedCert.getBytes());
55     }
56         
57     protected void setRealmString(String JavaDoc realm) {
58         setValue(getRealmstringKey(), realm);
59     }
60
61     protected String JavaDoc getRealmString() {
62         return getStringValue(getRealmstringKey());
63     }
64
65     private void setFailures(int failures) {
66         setValue(getFailuresKey(), String.valueOf(failures));
67     }
68
69     public static File JavaDoc getSystemCertFile(String JavaDoc realmString) {
70         File JavaDoc file = new File JavaDoc(SvnConfigFiles.getUserConfigPath() + "auth/svn.ssl.server/" + getFileName(realmString)); // NOI18N
71
return FileUtil.normalizeFile(file);
72     }
73
74     public static File JavaDoc getNBCertFile(String JavaDoc realmString) {
75         File JavaDoc file = new File JavaDoc(SvnConfigFiles.getNBConfigPath() + "auth/svn.ssl.server/" + getFileName(realmString)); // NOI18N
76
return FileUtil.normalizeFile(file);
77     }
78
79     private Key getCertKey() {
80         return getKey(CERT);
81     }
82
83     private Key getFailuresKey() {
84         return getKey(FAILURES);
85     }
86
87     private Key getRealmstringKey() {
88         return getKey(REALMSTRING);
89     }
90
91 }
92
Popular Tags