本文整理汇总了Java中com.nimbusds.jose.jwk.JWKSet类的典型用法代码示例。如果您正苦于以下问题:Java JWKSet类的具体用法?Java JWKSet怎么用?Java JWKSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JWKSet类属于com.nimbusds.jose.jwk包,在下文中一共展示了JWKSet类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
@PostConstruct
public void init() {
InputStream inputStream = TokenGenerator.class.getClassLoader().getResourceAsStream("rsa.keyset");
String content = new Scanner(inputStream).useDelimiter("\\Z").next();
try {
jwkSet = JWKSet.parse(content);
inputStream.close();
} catch (ParseException | IOException e) {
e.printStackTrace();
// FIXME
}
keys = jwkSet.getKeys().stream().map(JWK::getKeyID).collect(Collectors.toList());
}
示例2: getKey
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
private ECPublicKey getKey(String kid, String alg) throws Exception {
JWK jwk = keyCache.get(kid);
if (jwk == null) {
// update cache loading jwk public key data from url
JWKSet jwkSet = JWKSet.load(new URL(PUBLIC_KEY_VERIFICATION_URL));
for (JWK key : jwkSet.getKeys()) {
keyCache.put(key.getKeyID(), key);
}
jwk = keyCache.get(kid);
}
// confirm that algorithm matches
if (jwk != null && jwk.getAlgorithm().getName().equals(alg)) {
return ECKey.parse(jwk.toJSONString()).toECPublicKey();
}
return null;
}
示例3: lookupJWKSource
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
private JWKSource<SecurityContext> lookupJWKSource() throws IOException, ParseException {
if(jwtConfiguration.getJwkResource() != null &&
!"".equals(jwtConfiguration.getJwkResource())) {
URL resource = DefaultValidatingJWTProcessor.class.getResource(jwtConfiguration.getJwkResource());
try(InputStream stream = resource.openStream()) {
String key = com.nimbusds.jose.util.IOUtils.readInputStreamToString(stream, Charset.defaultCharset());
return new ImmutableJWKSet<>(JWKSet.parse(key));
}
}
else if(jwtConfiguration.getJwkSourceUrl() != null &&
!"".equals(jwtConfiguration.getJwkSourceUrl())) {
return new RemoteJWKSet<>(new URL(jwtConfiguration.getJwkSourceUrl()));
}
else {
JWKSet jwkSet = JWKSet.load(new File(jwtConfiguration.getJwkSourceFile()));
return new ImmutableJWKSet<>(jwkSet);
}
}
示例4: loadAadPublicKeys
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
private static JWKSet loadAadPublicKeys() {
try {
return JWKSet.load(
new URL(KEY_DISCOVERY_URI));
} catch (IOException | ParseException e) {
LOG.error("Error loading AAD public keys: {}", e.getMessage());
}
return null;
}
示例5: resolveJwk
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
private JWK resolveJwk(JWSAlgorithm algorithm) {
// @formatter:off
JWKMatcher jwkMatcher = new JWKMatcher.Builder()
.keyType(KeyType.forAlgorithm(algorithm))
.keyUse(KeyUse.SIGNATURE)
.build();
// @formatter:on
JWKSelector jwkSelector = new JWKSelector(jwkMatcher);
JWKSet jwkSet = this.jwkSetLoader.load();
List<JWK> keys = jwkSelector.select(jwkSet);
return keys.iterator().next();
}
示例6: getJwkSet
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
@GetMapping
public void getJwkSet(HttpServletResponse response) throws IOException {
JWKSet jwkSet = this.jwkSetLoader.load();
response.setContentType(JWKSet.MIME_TYPE);
PrintWriter writer = response.getWriter();
writer.print(jwkSet.toJSONObject().toJSONString());
writer.close();
}
示例7: jwkSetLoader
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
@Bean
public JwkSetLoader jwkSetLoader() {
return () -> {
try {
Resource jwkSetResource = this.resourceLoader.getResource(JWK_SET_LOCATION);
String jwkSetJson = new String(FileCopyUtils.copyToByteArray(jwkSetResource.getInputStream()));
return JWKSet.parse(jwkSetJson);
}
catch (IOException | ParseException e) {
throw new RuntimeException(e);
}
};
}
示例8: main
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
public static void main(String[] args) {
List<JWK> jwks = new ArrayList<>();
// First key
String xApiKey = UUID.randomUUID().toString();
JWK jwk = make(2048, KeyUse.SIGNATURE, new Algorithm("PS512"), xApiKey);
jwks.add(jwk);
// Second key
xApiKey = UUID.randomUUID().toString();
jwk = make(2048, KeyUse.SIGNATURE, new Algorithm("PS512"), xApiKey);
jwks.add(jwk);
// Third key
xApiKey = UUID.randomUUID().toString();
jwk = make(2048, KeyUse.SIGNATURE, new Algorithm("PS512"), xApiKey);
jwks.add(jwk);
JWKSet jwkSet = new JWKSet(jwks);
System.out.println(jwkSet.toJSONObject(false));
}
示例9: getProviderRSAKeys
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
JWKSet getProviderRSAKeys(JSONObject json) throws ParseException {
JSONArray keyList = (JSONArray) json.get("keys");
List<JWK> rsaKeys = new LinkedList<>();
for (Object key : keyList) {
JSONObject k = (JSONObject) key;
if (k.get("use").equals("sig") && k.get("kty").equals("RSA")) {
rsaKeys.add(RSAKey.parse(k));
}
}
if (!rsaKeys.isEmpty()) {
return new JWKSet(rsaKeys);
}
throw new IllegalArgumentException("No RSA keys found");
}
示例10: init
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
@PostConstruct
public void init() {
String privateContent = readFile("private.jwkset");
try {
jwkSet = JWKSet.parse(privateContent);
} catch (ParseException e) {
e.printStackTrace();
}
}
示例11: onNewFile
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
public void onNewFile() {
currentFile = null;
jwkSet = new JWKSet();
changed.setValue(true);
}
示例12: getKeys
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
@Test
public void getKeys() throws Exception {
given(this.jwkSetLoader.load()).willReturn(new JWKSet());
this.mvc.perform(get("/oauth2/keys")).andExpect(status().isOk()).andExpect(jsonPath("$.keys").isEmpty());
}
示例13: readJWKSet
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
private static JWKSet readJWKSet() throws ParseException, IOException {
JWKSet result;
InputStream inputStream = TokenGenerator.class.getClassLoader().getResourceAsStream("rsa.keyset");
String content = new Scanner(inputStream).useDelimiter("\\Z").next();
result = JWKSet.parse(content);
inputStream.close();
return result;
}
示例14: load
import com.nimbusds.jose.jwk.JWKSet; //导入依赖的package包/类
/**
* Load JWK set.
* @return the JWK set
*/
JWKSet load();