Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit fe2f27d

Browse files
authored
1073 asymmetric keys (#1210)
* 1073: property name cleanup to be easier to understand * 1073: added RSA and EC signature support * fixed file header, removed unused dependency reference * 1073: fixed artifact id typo * 1073: added debug statement
1 parent 10e3b95 commit fe2f27d

File tree

27 files changed

+1427
-207
lines changed

27 files changed

+1427
-207
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2017 Stormpath, Inc.
3+
*
4+
* Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 com.stormpath.sdk.lang;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
21+
import java.security.Provider;
22+
import java.security.Security;
23+
import java.util.concurrent.atomic.AtomicBoolean;
24+
25+
/**
26+
* @since 1.3.0
27+
*/
28+
public final class DefaultRuntimeEnvironment implements RuntimeEnvironment {
29+
30+
private static final Logger log = LoggerFactory.getLogger(DefaultRuntimeEnvironment.class);
31+
32+
public static final DefaultRuntimeEnvironment INSTANCE = new DefaultRuntimeEnvironment();
33+
34+
private DefaultRuntimeEnvironment() {
35+
}
36+
37+
private static final String BC_PROVIDER_CLASS_NAME = "org.bouncycastle.jce.provider.BouncyCastleProvider";
38+
39+
private static final AtomicBoolean bcLoaded = new AtomicBoolean(false);
40+
41+
private static void enableBouncyCastleIfPossible() {
42+
43+
if (bcLoaded.get()) {
44+
return;
45+
}
46+
47+
try {
48+
Class clazz = Classes.forName(BC_PROVIDER_CLASS_NAME);
49+
50+
//check to see if the user has already registered the BC provider:
51+
52+
Provider[] providers = Security.getProviders();
53+
54+
for (Provider provider : providers) {
55+
if (clazz.isInstance(provider)) {
56+
bcLoaded.set(true);
57+
return;
58+
}
59+
}
60+
61+
//bc provider not enabled - add it:
62+
Security.addProvider((Provider) Classes.newInstance(clazz));
63+
bcLoaded.set(true);
64+
65+
} catch (UnknownClassException e) {
66+
log.debug("Unable to load BouncyCastle. This is an acceptable outcome and this exception " +
67+
"does not necessarily reflect a problem and can be ignored.", e);
68+
//not available
69+
}
70+
}
71+
72+
static {
73+
enableBouncyCastleIfPossible();
74+
}
75+
76+
@Override
77+
public boolean isClassAvailable(String fqcn) {
78+
return Classes.isAvailable(fqcn);
79+
}
80+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2017 Stormpath, Inc.
3+
*
4+
* Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 com.stormpath.sdk.lang;
17+
18+
/**
19+
* @since 1.3.0
20+
*/
21+
public interface RuntimeEnvironment {
22+
23+
boolean isClassAvailable(String fqcn);
24+
25+
}

0 commit comments

Comments
 (0)