com.nimbusds.jose.Algorithm.getName()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中com.nimbusds.jose.Algorithm.getName()方法的一些代码示例,展示了Algorithm.getName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Algorithm.getName()方法的具体详情如下:
包路径:com.nimbusds.jose.Algorithm
类名称:Algorithm
方法名:getName

Algorithm.getName介绍

[英]Gets the name of this algorithm.
[中]获取此算法的名称。

代码示例

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

@Override
  public String apply(Algorithm alg) {
    if (alg == null) {
      return null;
    } else {
      return alg.getName();
    }
  }
};

代码示例来源:origin: spring-projects/spring-security

@Test
public void getWhenMatchThenCreatesKeys() {
  when(this.matcher.matches(any())).thenReturn(true);
  List<JWK> keys = this.source.get(this.selector).block();
  assertThat(keys).hasSize(2);
  JWK key1 = keys.get(0);
  assertThat(key1.getKeyID()).isEqualTo("1923397381d9574bb873202a90c32b7ceeaed027");
  assertThat(key1.getAlgorithm().getName()).isEqualTo("RS256");
  assertThat(key1.getKeyType()).isEqualTo(KeyType.RSA);
  assertThat(key1.getKeyUse()).isEqualTo(KeyUse.SIGNATURE);
  JWK key2 = keys.get(1);
  assertThat(key2.getKeyID()).isEqualTo("7ddf54d3032d1f0d48c3618892ca74c1ac30ad77");
  assertThat(key2.getAlgorithm().getName()).isEqualTo("RS256");
  assertThat(key2.getKeyType()).isEqualTo(KeyType.RSA);
  assertThat(key2.getKeyUse()).isEqualTo(KeyUse.SIGNATURE);
}

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

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;
}

代码示例来源:origin: org.mitre/openid-connect-server

@Override
  public String apply(Algorithm alg) {
    if (alg == null) {
      return null;
    } else {
      return alg.getName();
    }
  }
};

代码示例来源:origin: org.apereo.cas/cas-server-support-token

private static <T extends Algorithm> T findAlgorithmFamily(final Set<Algorithm> family, final String alg) {
  return (T) family.stream().filter(l -> l.getName().equalsIgnoreCase(alg)).findFirst().get();
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Creates a new JWS header builder.
 *
 * @param alg The JWS algorithm ({@code alg}) parameter. Must
 *            not be "none" or {@code null}.
 */
public Builder(final JWSAlgorithm alg) {
  if (alg.getName().equals(Algorithm.NONE.getName())) {
    throw new IllegalArgumentException("The JWS algorithm \"alg\" cannot be \"none\"");
  }
  this.alg = alg;
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.oauth

public JWTTokenGenerator(boolean includeClaims, boolean enableSigning) {
  this.includeClaims = includeClaims;
  this.enableSigning = enableSigning;
  signatureAlgorithm = new JWSAlgorithm(JWSAlgorithm.NONE.getName());
}

代码示例来源:origin: org.apereo.cas/cas-server-support-token-authentication

private static <T extends Algorithm> T findAlgorithmFamily(final Set<Algorithm> family,
                              final String alg, final Class<T> clazz) {
  val result = family
    .stream()
    .filter(l -> l.getName().equalsIgnoreCase(alg))
    .findFirst()
    .get();
  if (!clazz.isAssignableFrom(result.getClass())) {
    throw new ClassCastException("Result [" + result
      + " is of type " + result.getClass()
      + " when we were expecting " + clazz);
  }
  return (T) result;
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

public JWTTokenGenerator(boolean includeClaims, boolean enableSigning) {
  this.includeClaims = includeClaims;
  this.enableSigning = enableSigning;
  signatureAlgorithm = new JWSAlgorithm(JWSAlgorithm.NONE.getName());
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

private boolean isIDTokenSigned() {
  return !JWSAlgorithm.NONE.getName().equals(signatureAlgorithm.getName());
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

private boolean isUnsignedIDToken() {
  return JWSAlgorithm.NONE.getName().equals(signatureAlgorithm.getName());
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

private boolean isIDTokenSigned() {
  return !JWSAlgorithm.NONE.getName().equals(signatureAlgorithm.getName());
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Creates a new JWE header builder.
 *
 * @param alg The JWE algorithm ({@code alg}) parameter. Must
 *            not be "none" or {@code null}.
 * @param enc The encryption method. Must not be {@code null}.
 */
public Builder(final JWEAlgorithm alg, final EncryptionMethod enc) {
  if (alg.getName().equals(Algorithm.NONE.getName())) {
    throw new IllegalArgumentException("The JWE algorithm \"alg\" cannot be \"none\"");
  }
  this.alg = alg;
  if (enc == null) {
    throw new IllegalArgumentException("The encryption method \"enc\" parameter must not be null");
  }
  this.enc = enc;
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

/**
 * Get the supported request object signing algorithms
 *
 * @return list of algorithms
 */
public static List<String> getRequestObjectSigningAlgValuesSupported() {
  List<String> requestObjectSigningAlgValues = new ArrayList<>();
  requestObjectSigningAlgValues.add(JWSAlgorithm.RS256.getName());
  requestObjectSigningAlgValues.add(JWSAlgorithm.RS384.getName());
  requestObjectSigningAlgValues.add(JWSAlgorithm.RS512.getName());
  requestObjectSigningAlgValues.add(JWSAlgorithm.PS256.getName());
  requestObjectSigningAlgValues.add(JWSAlgorithm.NONE.getName());
  return requestObjectSigningAlgValues;
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Checks if the specified JWS algorithm is supported by the default
 * system JCA provider(s).
 *
 * @param alg The JWS algorithm. Must not be {@code null}.
 *
 * @return {@code true} if the JWS algorithm is supported, else
 *         {@code false}.
 */
public static boolean isSupported(final JWSAlgorithm alg) {
  
  if (alg.getName().equals(Algorithm.NONE.getName())) {
    return true;
  }
  for (Provider p: Security.getProviders()) {
    if (isSupported(alg, p)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

/**
 * Build a signed jwt token from authorization request message context.
 *
 * @param request Oauth authorization message context.
 * @return Signed jwt string.
 * @throws IdentityOAuth2Exception
 */
protected String buildJWTToken(OAuthAuthzReqMessageContext request) throws IdentityOAuth2Exception {
  // Set claims to jwt token.
  JWTClaimsSet jwtClaimsSet = createJWTClaimSet(request, null, request.getAuthorizationReqDTO()
      .getConsumerKey());
  JWTClaimsSet.Builder jwtClaimsSetBuilder = new JWTClaimsSet.Builder(jwtClaimsSet);
  if (request.getApprovedScope() != null && Arrays.asList((request.getApprovedScope())).contains(AUDIENCE)) {
    jwtClaimsSetBuilder.audience(Arrays.asList(request.getApprovedScope()));
  }
  jwtClaimsSet = jwtClaimsSetBuilder.build();
  if (JWSAlgorithm.NONE.getName().equals(signatureAlgorithm.getName())) {
    return new PlainJWT(jwtClaimsSet).serialize();
  }
  return signJWT(jwtClaimsSet, null, request);
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

/**
 * Build a signed jwt token from OauthToken request message context.
 *
 * @param request Token request message context.
 * @return Signed jwt string.
 * @throws IdentityOAuth2Exception
 */
protected String buildJWTToken(OAuthTokenReqMessageContext request) throws IdentityOAuth2Exception {
  // Set claims to jwt token.
  JWTClaimsSet jwtClaimsSet = createJWTClaimSet(null, request, request.getOauth2AccessTokenReqDTO()
      .getClientId());
  JWTClaimsSet.Builder jwtClaimsSetBuilder = new JWTClaimsSet.Builder(jwtClaimsSet);
  if (request.getScope() != null && Arrays.asList((request.getScope())).contains(AUDIENCE)) {
    jwtClaimsSetBuilder.audience(Arrays.asList(request.getScope()));
  }
  jwtClaimsSet = jwtClaimsSetBuilder.build();
  if (JWSAlgorithm.NONE.getName().equals(signatureAlgorithm.getName())) {
    return new PlainJWT(jwtClaimsSet).serialize();
  }
  return signJWT(jwtClaimsSet, request, null);
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

if (algName.equals(Algorithm.NONE.getName())) {

代码示例来源:origin: org.wso2.carbon.auth/org.wso2.carbon.auth.oauth

@Override
public void generateAccessToken(AccessTokenContext context) {
  JWTClaimsSet jwtClaimsSet = getJWTClaimSet(context);
  String jwtToken;
  if (JWSAlgorithm.NONE.getName().equals(signatureAlgorithm.getName())) {
    jwtToken = new PlainJWT(jwtClaimsSet).serialize();
    context.getParams().put(OAuthConstants.TOKEN_ALIAS, jwtClaimsSet.getJWTID());
    context.getParams().put(OAuthConstants.TOKEN, jwtToken);
    super.generateAccessToken(context);
  } else {
    try {
      jwtToken = signJwt(jwtClaimsSet);
      context.getParams().put(OAuthConstants.TOKEN_ALIAS, jwtClaimsSet.getJWTID());
      context.getParams().put(OAuthConstants.TOKEN, jwtToken);
      super.generateAccessToken(context);
    } catch (AuthException e) {
      context.setSuccessful(false);
      context.setErrorObject(OAuth2Error.SERVER_ERROR);
    }
  }
}

代码示例来源:origin: wso2/msf4j

addUserClaims(jwtClaimsSet, request.getAuthorizationReqDTO().getUser());
if (JWSAlgorithm.NONE.getName().equals(signatureAlgorithm.getName())) {
  return new PlainJWT(jwtClaimsSet).serialize();

相关文章