@Test(expected = ParseException.class) public void testPlainJwt() throws Exception { final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); final KeyPair pair = keyGen.generateKeyPair(); final RSAPublicKey publicKey = (RSAPublicKey) pair.getPublic(); final Date expiration = new Date(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS)); final JWTClaimsSet claimsSet = new JWTClaimsSet.Builder() .subject("user-1") .expirationTime(expiration) .build(); final PlainJWT plainJWT = new PlainJWT(claimsSet); final KnoxConfiguration configuration = getConfiguration(publicKey); final KnoxService service = new KnoxService(configuration); service.getAuthenticationFromToken(plainJWT.serialize()); }
public String getAuthenticationFromToken(final String jwt) throws ParseException, JOSEException { if (!configuration.isKnoxEnabled()) { throw new IllegalStateException("Apache Knox SSO is not enabled."); } final SignedJWT signedJwt = SignedJWT.parse(jwt); if (validateToken(signedJwt)) { final JWTClaimsSet claimsSet = signedJwt.getJWTClaimsSet(); if (claimsSet == null) { logger.info("Claims set is missing from Knox JWT."); throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } return claimsSet.getSubject(); } else { throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } }
KnoxService { public String getAuthenticationFromToken(final String jwt) throws ParseException, JOSEException { if (!configuration.isKnoxEnabled()) { throw new IllegalStateException("Apache Knox SSO is not enabled."); } final SignedJWT signedJwt = SignedJWT.parse(jwt); if (validateToken(signedJwt)) { final JWTClaimsSet claimsSet = signedJwt.getJWTClaimsSet(); if (claimsSet == null) { logger.info("Claims set is missing from Knox JWT."); throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } return claimsSet.getSubject(); } else { throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } } }
KnoxService { public String getAuthenticationFromToken(final String jwt) throws ParseException, JOSEException { if (!configuration.isKnoxEnabled()) { throw new IllegalStateException("Apache Knox SSO is not enabled."); } final SignedJWT signedJwt = SignedJWT.parse(jwt); if (validateToken(signedJwt)) { final JWTClaimsSet claimsSet = signedJwt.getJWTClaimsSet(); if (claimsSet == null) { logger.info("Claims set is missing from Knox JWT."); throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } return claimsSet.getSubject(); } else { throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } } KnoxService(final KnoxConfiguration configuration); }
KnoxService { public String getAuthenticationFromToken(final String jwt) throws ParseException, JOSEException { if (!configuration.isKnoxEnabled()) { throw new IllegalStateException("Apache Knox SSO is not enabled."); } final SignedJWT signedJwt = SignedJWT.parse(jwt); if (validateToken(signedJwt)) { final JWTClaimsSet claimsSet = signedJwt.getJWTClaimsSet(); if (claimsSet == null) { logger.info("Claims set is missing from Knox JWT."); throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } return claimsSet.getSubject(); } else { throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } } KnoxService(final KnoxConfiguration configuration); boolean isKnoxEnabled(); String getKnoxUrl(); String getAuthenticationFromToken(final String jwt); }
KnoxService { public String getAuthenticationFromToken(final String jwt) throws ParseException, JOSEException { if (!configuration.isKnoxEnabled()) { throw new IllegalStateException("Apache Knox SSO is not enabled."); } final SignedJWT signedJwt = SignedJWT.parse(jwt); if (validateToken(signedJwt)) { final JWTClaimsSet claimsSet = signedJwt.getJWTClaimsSet(); if (claimsSet == null) { logger.info("Claims set is missing from Knox JWT."); throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } return claimsSet.getSubject(); } else { throw new InvalidAuthenticationException("The Knox JWT token is not valid."); } } KnoxService(final KnoxConfiguration configuration); boolean isKnoxEnabled(); String getKnoxUrl(); String getAuthenticationFromToken(final String jwt);  }