com.nimbusds.jose.Algorithm类的使用及代码示例

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

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

Algorithm介绍

[英]The base class for algorithm names, with optional implementation requirement. This class is immutable.

Includes constants for the following standard algorithm names:

  • #NONE
    [中]算法名称的基类,具有可选的实现要求。这个类是不可变的。
    包括以下标准算法名称的常量:
    *#没有

代码示例

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

  1. @Override
  2. public String apply(Algorithm alg) {
  3. if (alg == null) {
  4. return null;
  5. } else {
  6. return alg.getName();
  7. }
  8. }
  9. };

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

  1. if (!clientAlg.equals(tokenAlg)) {
  2. throw new AuthenticationServiceException("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg);
  3. if (tokenAlg != null && !tokenAlg.equals(Algorithm.NONE)) {
  4. throw new AuthenticationServiceException("Unsigned token received, expected signature with " + tokenAlg);
  5. if (tokenAlg.equals(JWSAlgorithm.HS256)
  6. || tokenAlg.equals(JWSAlgorithm.HS384)
  7. || tokenAlg.equals(JWSAlgorithm.HS512)) {

代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.hostobjects.oidc

  1. Algorithm clientAlg = new Algorithm(clientAlgorithm);
  2. if (!clientAlg.equals(tokenAlg)) {
  3. isValid = false;
  4. log.error("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg);

代码示例来源:origin: stackoverflow.com

  1. public class Test2 extends Application {
  2. @Override
  3. public void start(Stage primaryStage) {
  4. Algorithm alg = new Algorithm();
  5. alg.solve();
  6. GUI gui = new GUI();
  7. gui.displaySolution(alg.getSolution());
  8. }
  9. // included for the benefit of IDEs that do not support
  10. // launching an Application without a main method:
  11. public static void main(String[] args) { launch(args); }
  12. }

代码示例来源:origin: stackoverflow.com

  1. Algorithm algorithm = new Algorithm(new BigInteger(jtfX.getText()));
  2. jlSolution.setText(algorithm.check());

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

  1. /**
  2. * Parses the optional algorithm.
  3. *
  4. * @param o The JSON object to parse. Must not be {@code null}.
  5. *
  6. * @return The intended JOSE algorithm, {@code null} if not specified.
  7. *
  8. * @throws ParseException If parsing failed.
  9. */
  10. static Algorithm parseAlgorithm(final JSONObject o)
  11. throws ParseException {
  12. if (o.containsKey("alg")) {
  13. return new Algorithm(JSONObjectUtils.getString(o, "alg"));
  14. } else {
  15. return null;
  16. }
  17. }

代码示例来源:origin: stackoverflow.com

  1. final Button button3 = new Button("Button 3");
  2. Algorithm algo = new Algorithm() {

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

  1. @Test
  2. public void getWhenMatchThenCreatesKeys() {
  3. when(this.matcher.matches(any())).thenReturn(true);
  4. List<JWK> keys = this.source.get(this.selector).block();
  5. assertThat(keys).hasSize(2);
  6. JWK key1 = keys.get(0);
  7. assertThat(key1.getKeyID()).isEqualTo("1923397381d9574bb873202a90c32b7ceeaed027");
  8. assertThat(key1.getAlgorithm().getName()).isEqualTo("RS256");
  9. assertThat(key1.getKeyType()).isEqualTo(KeyType.RSA);
  10. assertThat(key1.getKeyUse()).isEqualTo(KeyUse.SIGNATURE);
  11. JWK key2 = keys.get(1);
  12. assertThat(key2.getKeyID()).isEqualTo("7ddf54d3032d1f0d48c3618892ca74c1ac30ad77");
  13. assertThat(key2.getAlgorithm().getName()).isEqualTo("RS256");
  14. assertThat(key2.getKeyType()).isEqualTo(KeyType.RSA);
  15. assertThat(key2.getKeyUse()).isEqualTo(KeyUse.SIGNATURE);
  16. }

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

  1. if (alg.equals(Algorithm.NONE)) {
  2. return PlainJWT.parse(s);
  3. } else if (alg instanceof JWSAlgorithm) {

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

  1. private ECPublicKey getKey(String kid, String alg) throws Exception {
  2. JWK jwk = keyCache.get(kid);
  3. if (jwk == null) {
  4. // update cache loading jwk public key data from url
  5. JWKSet jwkSet = JWKSet.load(new URL(PUBLIC_KEY_VERIFICATION_URL));
  6. for (JWK key : jwkSet.getKeys()) {
  7. keyCache.put(key.getKeyID(), key);
  8. }
  9. jwk = keyCache.get(kid);
  10. }
  11. // confirm that algorithm matches
  12. if (jwk != null && jwk.getAlgorithm().getName().equals(alg)) {
  13. return ECKey.parse(jwk.toJSONString()).toECPublicKey();
  14. }
  15. return null;
  16. }

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

  1. /**
  2. * Parses a {@link PlainHeader}, {@link JWSHeader} or {@link JWEHeader}
  3. * from the specified JSON object.
  4. *
  5. * @param jsonObject The JSON object to parse. Must not be
  6. * {@code null}.
  7. * @param parsedBase64URL The original parsed Base64URL, {@code null}
  8. * if not applicable.
  9. *
  10. * @return The header.
  11. *
  12. * @throws ParseException If the specified JSON object doesn't
  13. * represent a valid header.
  14. */
  15. public static Header parse(final JSONObject jsonObject,
  16. final Base64URL parsedBase64URL)
  17. throws ParseException {
  18. Algorithm alg = parseAlgorithm(jsonObject);
  19. if (alg.equals(Algorithm.NONE)) {
  20. return PlainHeader.parse(jsonObject, parsedBase64URL);
  21. } else if (alg instanceof JWSAlgorithm) {
  22. return JWSHeader.parse(jsonObject, parsedBase64URL);
  23. } else if (alg instanceof JWEAlgorithm) {
  24. return JWEHeader.parse(jsonObject, parsedBase64URL);
  25. } else {
  26. throw new AssertionError("Unexpected algorithm type: " + alg);
  27. }
  28. }

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

  1. @Override
  2. public String apply(Algorithm alg) {
  3. if (alg == null) {
  4. return null;
  5. } else {
  6. return alg.getName();
  7. }
  8. }
  9. };

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

  1. if (alg.equals(Algorithm.NONE)) {
  2. return PlainObject.parse(s);
  3. } else if (alg instanceof JWSAlgorithm) {

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

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

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

  1. private void setRequestObjectValues(String requestObjectString, RequestObject requestObjectInstance) throws
  2. RequestObjectException {
  3. try {
  4. JOSEObject jwt = JOSEObject.parse(requestObjectString);
  5. if (jwt.getHeader().getAlgorithm() == null || jwt.getHeader().getAlgorithm().equals(JWSAlgorithm.NONE)) {
  6. requestObjectInstance.setPlainJWT(PlainJWT.parse(requestObjectString));
  7. } else {
  8. requestObjectInstance.setSignedJWT(SignedJWT.parse(requestObjectString));
  9. }
  10. } catch (ParseException e) {
  11. String errorMessage = "No Valid JWT is found for the Request Object.";
  12. if (log.isDebugEnabled()) {
  13. log.debug(errorMessage + "Received Request Object: " + requestObjectString, e);
  14. }
  15. throw new RequestObjectException(OAuth2ErrorCodes.INVALID_REQUEST, errorMessage);
  16. }
  17. }

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

  1. /**
  2. * Creates a new JWS header builder.
  3. *
  4. * @param alg The JWS algorithm ({@code alg}) parameter. Must
  5. * not be "none" or {@code null}.
  6. */
  7. public Builder(final JWSAlgorithm alg) {
  8. if (alg.getName().equals(Algorithm.NONE.getName())) {
  9. throw new IllegalArgumentException("The JWS algorithm \"alg\" cannot be \"none\"");
  10. }
  11. this.alg = alg;
  12. }

代码示例来源:origin: com.moomanow/moomanow-oauth2

  1. if (!clientAlg.equals(tokenAlg)) {
  2. throw new AuthenticationServiceException("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg);
  3. if (tokenAlg != null && !tokenAlg.equals(Algorithm.NONE)) {
  4. throw new AuthenticationServiceException("Unsigned token received, expected signature with " + tokenAlg);
  5. if (tokenAlg.equals(JWSAlgorithm.HS256)
  6. || tokenAlg.equals(JWSAlgorithm.HS384)
  7. || tokenAlg.equals(JWSAlgorithm.HS512)) {

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

  1. private static <T extends Algorithm> T findAlgorithmFamily(final Set<Algorithm> family,
  2. final String alg, final Class<T> clazz) {
  3. val result = family
  4. .stream()
  5. .filter(l -> l.getName().equalsIgnoreCase(alg))
  6. .findFirst()
  7. .get();
  8. if (!clazz.isAssignableFrom(result.getClass())) {
  9. throw new ClassCastException("Result [" + result
  10. + " is of type " + result.getClass()
  11. + " when we were expecting " + clazz);
  12. }
  13. return (T) result;
  14. }

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

  1. if (!clientAlg.equals(tokenAlg)) {
  2. throw new AuthenticationServiceException("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg);
  3. if (tokenAlg != null && !tokenAlg.equals(Algorithm.NONE)) {
  4. throw new AuthenticationServiceException("Unsigned token received, expected signature with " + tokenAlg);
  5. if (tokenAlg.equals(JWSAlgorithm.HS256)
  6. || tokenAlg.equals(JWSAlgorithm.HS384)
  7. || tokenAlg.equals(JWSAlgorithm.HS512)) {

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

  1. public JWTTokenGenerator(boolean includeClaims, boolean enableSigning) {
  2. this.includeClaims = includeClaims;
  3. this.enableSigning = enableSigning;
  4. signatureAlgorithm = new JWSAlgorithm(JWSAlgorithm.NONE.getName());
  5. }

相关文章