2222import com .nimbusds .jose .JWSObject ;
2323import com .nimbusds .jose .JWSVerifier ;
2424import com .nimbusds .jose .crypto .RSASSAVerifier ;
25+ import com .nimbusds .jose .jwk .RSAKey ;
2526import com .nimbusds .jose .jwk .source .JWKSource ;
2627import com .nimbusds .jose .jwk .source .RemoteJWKSet ;
2728import com .nimbusds .jose .proc .BadJOSEException ;
2829import com .nimbusds .jose .proc .JWSKeySelector ;
2930import com .nimbusds .jose .proc .JWSVerificationKeySelector ;
3031import com .nimbusds .jose .proc .SecurityContext ;
32+ import com .nimbusds .jose .util .X509CertUtils ;
3133import com .nimbusds .jwt .SignedJWT ;
3234import com .nimbusds .jwt .proc .ConfigurableJWTProcessor ;
3335import org .apache .commons .lang3 .StringUtils ;
34- import org .apache .hadoop .security .authentication .server .AuthenticationToken ;
35- import org .apache .hadoop .security .authentication .util .CertificateUtil ;
3636import org .apache .ranger .authz .handler .RangerAuthHandler ;
3737import org .slf4j .Logger ;
3838import org .slf4j .LoggerFactory ;
@@ -82,7 +82,7 @@ public void initialize(final Properties config) throws Exception {
8282
8383 // setup JWT provider public key if configured
8484 if (StringUtils .isNotBlank (pemPublicKey )) {
85- verifier = new RSASSAVerifier (CertificateUtil . parseRSAPublicKey ( pemPublicKey ));
85+ verifier = new RSASSAVerifier (RSAKey . parse ( X509CertUtils . parse ( pemPublicKey ) ));
8686 } else if (StringUtils .isBlank (jwksProviderUrl )) {
8787 throw new Exception ("RangerJwtAuthHandler: Mandatory configs ('jwks.provider-url' & 'jwt.public-key') are missing, must provide atleast one." );
8888 }
@@ -106,12 +106,11 @@ public void initialize(final Properties config) throws Exception {
106106
107107 public abstract ConfigurableJWTProcessor <SecurityContext > getJwtProcessor (JWSKeySelector <SecurityContext > keySelector );
108108
109- protected AuthenticationToken authenticate (final String jwtAuthHeader , final String jwtCookie , final String doAsUser ) {
109+ protected String authenticate (final String jwtAuthHeader , final String jwtCookie , final String doAsUser ) {
110110 if (LOG .isDebugEnabled ()) {
111111 LOG .debug ("===>>> RangerJwtAuthHandler.authenticate()" );
112112 }
113113
114- AuthenticationToken token = null ;
115114 if (shouldProceedAuth (jwtAuthHeader , jwtCookie )) {
116115 String serializedJWT = getJWT (jwtAuthHeader , jwtCookie );
117116
@@ -132,7 +131,7 @@ protected AuthenticationToken authenticate(final String jwtAuthHeader, final Str
132131 LOG .debug ("RangerJwtAuthHandler.authenticate(): Issuing AuthenticationToken for user: [{}]" , userName );
133132 LOG .debug ("RangerJwtAuthHandler.authenticate(): Authentication successful for user [{}] and doAs user is [{}]" , jwtToken .getJWTClaimsSet ().getSubject (), doAsUser );
134133 }
135- token = new AuthenticationToken ( userName , userName , TYPE ) ;
134+ return userName ;
136135 } else {
137136 LOG .warn ("RangerJwtAuthHandler.authenticate(): Validation failed for JWT token: [{}] " , jwtToken .serialize ());
138137 }
@@ -148,7 +147,7 @@ protected AuthenticationToken authenticate(final String jwtAuthHeader, final Str
148147 LOG .debug ("<<<=== RangerJwtAuthHandler.authenticate()" );
149148 }
150149
151- return token ;
150+ return null ;
152151 }
153152
154153 protected String getJWT (final String jwtAuthHeader , final String jwtCookie ) {
@@ -267,13 +266,11 @@ protected boolean validateAudiences(final SignedJWT jwtToken) {
267266 boolean valid = false ;
268267 try {
269268 List <String > tokenAudienceList = jwtToken .getJWTClaimsSet ().getAudience ();
270- // if there were no expected audiences configured then just
271- // consider any audience acceptable
269+ // if there were no expected audiences configured then just consider any audience acceptable
272270 if (audiences == null ) {
273271 valid = true ;
274272 } else {
275- // if any of the configured audiences is found then consider it
276- // acceptable
273+ // if any of the configured audiences is found then consider it acceptable
277274 for (String aud : tokenAudienceList ) {
278275 if (audiences .contains (aud )) {
279276 if (LOG .isDebugEnabled ()) {
@@ -294,8 +291,8 @@ protected boolean validateAudiences(final SignedJWT jwtToken) {
294291 }
295292
296293 /**
297- * Validate that the expiration time of the JWT token has not been violated. If
298- * it has then throw an AuthenticationException. Override this method in
294+ * Validate that the expiration time of the JWT has not been violated. If
295+ * it has, then throw an AuthenticationException. Override this method in
299296 * subclasses in order to customize the expiration validation behavior.
300297 *
301298 * @param jwtToken the token that contains the expiration date to validate
0 commit comments