本文整理汇总了Java中com.nimbusds.jose.jwk.JWK.parse方法的典型用法代码示例。如果您正苦于以下问题:Java JWK.parse方法的具体用法?Java JWK.parse怎么用?Java JWK.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.nimbusds.jose.jwk.JWK
的用法示例。
在下文中一共展示了JWK.parse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCreateInstance
import com.nimbusds.jose.jwk.JWK; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected BasicJWKCredential doCreateInstance() throws Exception {
if (jwkResource == null) {
log.error("{}: No JWK credential provided", getConfigDescription());
throw new BeanCreationException("No JWK credential provided");
}
JWK jwk = null;
BasicJWKCredential jwkCredential = null;
try (InputStream is = jwkResource.getInputStream()) {
jwk = JWK.parse(new String(ByteStreams.toByteArray(is)));
jwkCredential = new BasicJWKCredential();
if (jwk.getKeyType() == KeyType.EC || jwk.getKeyType() == KeyType.RSA) {
if (jwk.isPrivate()) {
jwkCredential.setPrivateKey(((AssymetricJWK) jwk).toPrivateKey());
}
jwkCredential.setPublicKey(((AssymetricJWK) jwk).toPublicKey());
} else if (jwk.getKeyType() == KeyType.OCT) {
jwkCredential.setSecretKey(((OctetSequenceKey) jwk).toSecretKey());
} else {
throw new FatalBeanException("Unsupported KeyFile at " + jwkResource.getDescription());
}
} catch (IOException | ParseException | JOSEException e) {
log.error("{}: Could not decode KeyFile at {}: {}",
getConfigDescription(), jwkResource.getDescription(), e);
throw new FatalBeanException("Could not decode provided KeyFile " + jwkResource.getDescription(), e);
}
jwkCredential.setUsageType(getUsageType(jwk));
jwkCredential.setEntityId(getEntityID());
jwkCredential.setAlgorithm(jwk.getAlgorithm());
jwkCredential.setKid(jwk.getKeyID());
final List<String> keyNames = getKeyNames();
if (keyNames != null) {
jwkCredential.getKeyNames().addAll(keyNames);
}
return jwkCredential;
}
示例2: authenticate
import com.nimbusds.jose.jwk.JWK; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
Authentication authenticationResult = authenticationManager
.authenticate(authentication);
if (authenticationResult.isAuthenticated()) {
// validates nonce because JWT is already valid
if (authentication instanceof PoPAuthenticationToken) {
PoPAuthenticationToken popAuthentication = (PoPAuthenticationToken) authentication;
// starts validating nonce here
String nonce = popAuthentication.getNonce();
if (nonce == null) {
throw new UnapprovedClientAuthenticationException(
"This request does not have a valid signed nonce");
}
String token = (String) popAuthentication.getPrincipal();
System.out.println("access token:" + token);
try {
JWT jwt = JWTParser.parse(token);
String publicKey = jwt.getJWTClaimsSet().getClaim("public_key").toString();
JWK jwk = JWK.parse(publicKey);
JWSObject jwsNonce = JWSObject.parse(nonce);
JWSVerifier verifier = new RSASSAVerifier((RSAKey) jwk);
if (!jwsNonce.verify(verifier)) {
throw new InvalidTokenException("Client hasn't possession of given token");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
return authenticationResult;
}
示例3: retrievePublicKeyFromAuthenticationToken
import com.nimbusds.jose.jwk.JWK; //导入方法依赖的package包/类
/**
* retrieves the client public key from Authentication Token
*
* @param signedJWT - the authentication token
* @return the public key as JWK object
*/
public static JWK retrievePublicKeyFromAuthenticationToken(SignedJWT signedJWT) {
JWK result = null;
try {
result = JWK.parse(signedJWT.getJWTClaimsSet().getJSONObjectClaim("sub_jwk"));
RSAKey publicKey = (RSAKey) signedJWT.getHeader().getJWK();
if (signedJWT.verify(new RSASSAVerifier(publicKey))) {
return result;
}
} catch (ParseException | JOSEException e) {
LOGGER.error(e);
}
return null;
}