1 /*
2 * ====================
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 *
5 * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.
6 *
7 * The contents of this file are subject to the terms of the Common Development
8 * and Distribution License("CDDL") (the "License"). You may not use this file
9 * except in compliance with the License.
10 *
11 * You can obtain a copy of the License at
12 * http://IdentityConnectors.dev.java.net/legal/license.txt
13 * See the License for the specific language governing permissions and limitations
14 * under the License.
15 *
16 * When distributing the Covered Code, include this CDDL Header Notice in each file
17 * and include the License file at identityconnectors/legal/license.txt.
18 * If applicable, add the following below this CDDL Header, with the fields
19 * enclosed by brackets [] replaced by your own identifying information:
20 * "Portions Copyrighted [year] [name of copyright owner]"
21 * ====================
22 */
23 package org.identityconnectors.common.security;
24
25
26 public abstract class EncryptorFactory {
27
28 // At some point we might make this pluggable, but for now, hard-code
29 private static final String IMPL_NAME = "org.identityconnectors.common.security.impl.EncryptorFactoryImpl";
30
31 private static EncryptorFactory _instance;
32
33 /**
34 * Get the singleton instance of the {@link EncryptorFactory}.
35 */
36 public static synchronized EncryptorFactory getInstance() {
37 if (_instance == null) {
38 try {
39 Class<?> clazz = Class.forName(IMPL_NAME);
40 Object object = clazz.newInstance();
41 _instance = EncryptorFactory.class.cast(object);
42 } catch (RuntimeException e) {
43 throw e;
44 } catch (Exception e) {
45 throw new RuntimeException(e);
46 }
47 }
48 return _instance;
49 }
50
51 /**
52 * Default encryptor that encrypts/descrypts using a default key
53 */
54 public abstract Encryptor getDefaultEncryptor();
55
56 /**
57 * Creates a new encryptor initialized with a random encryption key
58 */
59 public abstract Encryptor newRandomEncryptor();
60
61 }