@Test void shouldThrowExceptionIfTheKeysAreNull() { jwtSecurityInitializer = new JwtSecurityInitializer(); Exception exception = assertThrows(HttpsConfigError.class, () -> jwtSecurityInitializer.init(), "Expected exception is not HttpsConfigError"); assertEquals("Not found 'null' key alias in the keystore 'null'.", exception.getMessage()); }
@PostConstruct public void init() { signatureAlgorithm = SignatureAlgorithm.RS256; HttpsConfig config = HttpsConfig.builder().keyAlias(keyAlias).keyStore(keyStore).keyPassword(keyPassword) .keyStorePassword(keyStorePassword).keyStoreType(keyStoreType).build(); try { jwtSecret = SecurityUtils.loadKey(config); jwtPublicKey = SecurityUtils.loadPublicKey(config); } catch (HttpsConfigError er) { apimlLog.log("org.zowe.apiml.gateway.jwtInitConfigError", er.getCode(), er.getMessage()); } if (jwtSecret == null || jwtPublicKey == null) { String errorMessage = String.format("Not found '%s' key alias in the keystore '%s'.", keyAlias, keyStore); apimlLog.log("org.zowe.apiml.gateway.jwtKeyMissing", keyAlias, keyStore); throw new HttpsConfigError(errorMessage, HttpsConfigError.ErrorCode.WRONG_KEY_ALIAS, config); } }
JwtSecurityInitializer { @PostConstruct public void init() { signatureAlgorithm = SignatureAlgorithm.RS256; HttpsConfig config = HttpsConfig.builder().keyAlias(keyAlias).keyStore(keyStore).keyPassword(keyPassword) .keyStorePassword(keyStorePassword).keyStoreType(keyStoreType).build(); try { jwtSecret = SecurityUtils.loadKey(config); jwtPublicKey = SecurityUtils.loadPublicKey(config); } catch (HttpsConfigError er) { apimlLog.log("org.zowe.apiml.gateway.jwtInitConfigError", er.getCode(), er.getMessage()); } if (jwtSecret == null || jwtPublicKey == null) { String errorMessage = String.format("Not found '%s' key alias in the keystore '%s'.", keyAlias, keyStore); apimlLog.log("org.zowe.apiml.gateway.jwtKeyMissing", keyAlias, keyStore); throw new HttpsConfigError(errorMessage, HttpsConfigError.ErrorCode.WRONG_KEY_ALIAS, config); } } }
JwtSecurityInitializer { @PostConstruct public void init() { signatureAlgorithm = SignatureAlgorithm.RS256; HttpsConfig config = HttpsConfig.builder().keyAlias(keyAlias).keyStore(keyStore).keyPassword(keyPassword) .keyStorePassword(keyStorePassword).keyStoreType(keyStoreType).build(); try { jwtSecret = SecurityUtils.loadKey(config); jwtPublicKey = SecurityUtils.loadPublicKey(config); } catch (HttpsConfigError er) { apimlLog.log("org.zowe.apiml.gateway.jwtInitConfigError", er.getCode(), er.getMessage()); } if (jwtSecret == null || jwtPublicKey == null) { String errorMessage = String.format("Not found '%s' key alias in the keystore '%s'.", keyAlias, keyStore); apimlLog.log("org.zowe.apiml.gateway.jwtKeyMissing", keyAlias, keyStore); throw new HttpsConfigError(errorMessage, HttpsConfigError.ErrorCode.WRONG_KEY_ALIAS, config); } }  }
JwtSecurityInitializer { @PostConstruct public void init() { signatureAlgorithm = SignatureAlgorithm.RS256; HttpsConfig config = HttpsConfig.builder().keyAlias(keyAlias).keyStore(keyStore).keyPassword(keyPassword) .keyStorePassword(keyStorePassword).keyStoreType(keyStoreType).build(); try { jwtSecret = SecurityUtils.loadKey(config); jwtPublicKey = SecurityUtils.loadPublicKey(config); } catch (HttpsConfigError er) { apimlLog.log("org.zowe.apiml.gateway.jwtInitConfigError", er.getCode(), er.getMessage()); } if (jwtSecret == null || jwtPublicKey == null) { String errorMessage = String.format("Not found '%s' key alias in the keystore '%s'.", keyAlias, keyStore); apimlLog.log("org.zowe.apiml.gateway.jwtKeyMissing", keyAlias, keyStore); throw new HttpsConfigError(errorMessage, HttpsConfigError.ErrorCode.WRONG_KEY_ALIAS, config); } }  @PostConstruct void init(); SignatureAlgorithm getSignatureAlgorithm(); Key getJwtSecret(); PublicKey getJwtPublicKey(); JWK getJwkPublicKey(); }
JwtSecurityInitializer { @PostConstruct public void init() { signatureAlgorithm = SignatureAlgorithm.RS256; HttpsConfig config = HttpsConfig.builder().keyAlias(keyAlias).keyStore(keyStore).keyPassword(keyPassword) .keyStorePassword(keyStorePassword).keyStoreType(keyStoreType).build(); try { jwtSecret = SecurityUtils.loadKey(config); jwtPublicKey = SecurityUtils.loadPublicKey(config); } catch (HttpsConfigError er) { apimlLog.log("org.zowe.apiml.gateway.jwtInitConfigError", er.getCode(), er.getMessage()); } if (jwtSecret == null || jwtPublicKey == null) { String errorMessage = String.format("Not found '%s' key alias in the keystore '%s'.", keyAlias, keyStore); apimlLog.log("org.zowe.apiml.gateway.jwtKeyMissing", keyAlias, keyStore); throw new HttpsConfigError(errorMessage, HttpsConfigError.ErrorCode.WRONG_KEY_ALIAS, config); } }  @PostConstruct void init(); SignatureAlgorithm getSignatureAlgorithm(); Key getJwtSecret(); PublicKey getJwtPublicKey(); JWK getJwkPublicKey();  }