Skip to content

Commit 4421984

Browse files
committed
RANGER-5371: addressed review suggestions
1 parent ffe01ea commit 4421984

8 files changed

Lines changed: 66 additions & 37 deletions

File tree

intg/src/main/python/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,14 @@ from apache_ranger.model.ranger_authz import (
166166
pdp = RangerPDPClient("http://localhost:6500", HTTPKerberosAuth())
167167

168168
req = RangerAuthzRequest({
169-
"requestId": "req-1",
170-
"user": RangerUserInfo({"name": "alice"}),
171-
"access": RangerAccessInfo({
172-
"resource": RangerResourceInfo({"name": "table:default/test_tbl1"}),
173-
"permissions": ["select"]
169+
'requestId': 'req-1',
170+
'user': RangerUserInfo({'name': 'alice'}),
171+
'access': RangerAccessInfo({
172+
'resource': RangerResourceInfo({'name': 'table:default/test_tbl1', 'subResources': ['column:id', 'column:name', 'column:email']}),
173+
'action': 'QUERY',
174+
'permissions': ['select']
174175
}),
175-
"context": RangerAccessContext({"serviceType": "hive", "serviceName": "dev_hive"})
176+
'context': RangerAccessContext({'serviceType': 'hive', 'serviceName': 'dev_hive'})
176177
})
177178

178179
res = pdp.authorize(req)
@@ -193,7 +194,8 @@ payload = {
193194
"requestId": "req-1",
194195
"user": {"name": "alice"},
195196
"access": {
196-
"resource": {"name": "table:default/test_tbl1"},
197+
"resource": {"name": "table:default/test_tbl1", "subResources": ["column:id", "column:name", "column:email"]},
198+
"action": "QUERY",
197199
"permissions": ["select"]
198200
},
199201
"context": {"serviceType": "hive", "serviceName": "dev_hive"}

pdp/conf.dist/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<configuration>
2020
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
21-
<Target>System.out</Target>
21+
<target>System.out</target>
2222
<encoder>
2323
<pattern>%d{ISO8601} %-5p [%X{requestId}] %c{1} - %m%n</pattern>
2424
</encoder>

pdp/src/main/java/org/apache/ranger/pdp/RangerPdpServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private Connector createConnector() {
186186
connector.setProperty("truststoreFile", config.getTruststoreFile());
187187
connector.setProperty("truststorePass", config.getTruststorePassword());
188188
connector.setProperty("truststoreType", config.getTruststoreType());
189-
connector.setProperty("clientAuth", "want");
189+
connector.setProperty("clientAuth", "true");
190190
}
191191
}
192192

pdp/src/main/java/org/apache/ranger/pdp/RangerPdpStatusServlet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.servlet.http.HttpServlet;
2828
import javax.servlet.http.HttpServletRequest;
2929
import javax.servlet.http.HttpServletResponse;
30+
import javax.ws.rs.core.MediaType;
3031

3132
import java.io.File;
3233
import java.io.IOException;
@@ -73,7 +74,7 @@ private void writeLive(HttpServletResponse resp) throws IOException {
7374
payload.put("live", runtimeState.isServerStarted());
7475

7576
resp.setStatus(runtimeState.isServerStarted() ? HttpServletResponse.SC_OK : HttpServletResponse.SC_SERVICE_UNAVAILABLE);
76-
resp.setContentType("application/json");
77+
resp.setContentType(MediaType.APPLICATION_JSON);
7778

7879
MAPPER.writeValue(resp.getOutputStream(), payload);
7980
}
@@ -91,7 +92,7 @@ private void writeReady(HttpServletResponse resp) throws IOException {
9192
payload.put("policyCacheAgeMs", getPolicyCacheAgeMs());
9293

9394
resp.setStatus(ready ? HttpServletResponse.SC_OK : HttpServletResponse.SC_SERVICE_UNAVAILABLE);
94-
resp.setContentType("application/json");
95+
resp.setContentType(MediaType.APPLICATION_JSON);
9596

9697
MAPPER.writeValue(resp.getOutputStream(), payload);
9798
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.ranger.pdp.model;
21+
22+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
23+
import com.fasterxml.jackson.annotation.JsonInclude;
24+
25+
import javax.ws.rs.core.Response;
26+
27+
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
28+
@JsonInclude(JsonInclude.Include.NON_NULL)
29+
public class ErrorResponse {
30+
private final String code;
31+
private final String message;
32+
33+
public ErrorResponse(Response.Status status, String message) {
34+
this.code = status.name();
35+
this.message = message;
36+
}
37+
38+
public String getCode() {
39+
return code;
40+
}
41+
42+
public String getMessage() {
43+
return message;
44+
}
45+
}

pdp/src/main/java/org/apache/ranger/pdp/rest/RangerPdpREST.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package org.apache.ranger.pdp.rest;
2121

22-
import com.fasterxml.jackson.annotation.JsonAutoDetect;
23-
import com.fasterxml.jackson.annotation.JsonInclude;
2422
import org.apache.commons.collections.CollectionUtils;
2523
import org.apache.commons.collections.MapUtils;
2624
import org.apache.commons.lang3.StringUtils;
@@ -38,6 +36,7 @@
3836
import org.apache.ranger.pdp.RangerPdpStats;
3937
import org.apache.ranger.pdp.config.RangerPdpConfig;
4038
import org.apache.ranger.pdp.config.RangerPdpConstants;
39+
import org.apache.ranger.pdp.model.ErrorResponse;
4140
import org.slf4j.Logger;
4241
import org.slf4j.LoggerFactory;
4342

@@ -484,24 +483,4 @@ private Response serverError() {
484483
.entity(new ErrorResponse(INTERNAL_SERVER_ERROR, "Internal Server Error"))
485484
.build();
486485
}
487-
488-
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
489-
@JsonInclude(JsonInclude.Include.NON_NULL)
490-
public static class ErrorResponse {
491-
private final String code;
492-
private final String message;
493-
494-
public ErrorResponse(Response.Status status, String message) {
495-
this.code = status.name();
496-
this.message = message;
497-
}
498-
499-
public String getCode() {
500-
return code;
501-
}
502-
503-
public String getMessage() {
504-
return message;
505-
}
506-
}
507486
}

pdp/src/main/java/org/apache/ranger/pdp/security/KerberosAuthNHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void init(Properties config) throws Exception {
118118
serverCred = Subject.doAs(serviceSubject, (PrivilegedExceptionAction<GSSCredential>) () ->
119119
gssManager.createCredential(serverName, tokenLifetime, new Oid[] {SPNEGO_OID, KRB5_OID}, GSSCredential.ACCEPT_ONLY));
120120

121-
LOG.info("KerberosAuthHandler initialized; principal={} (bound acceptor credential to configured principal)", principal);
121+
LOG.info("KerberosAuthNHandler initialized; principal={} (bound acceptor credential to configured principal)", principal);
122122
}
123123

124124
@Override

pdp/src/main/java/org/apache/ranger/pdp/security/RangerPdpAuthNFilter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import javax.servlet.ServletResponse;
3333
import javax.servlet.http.HttpServletRequest;
3434
import javax.servlet.http.HttpServletResponse;
35+
import javax.ws.rs.core.MediaType;
36+
import javax.ws.rs.core.Response;
3537

3638
import java.io.IOException;
3739
import java.util.ArrayList;
@@ -138,9 +140,9 @@ private void sendUnauthenticated(HttpServletResponse response) throws IOExceptio
138140
}
139141
}
140142

141-
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
142-
response.setContentType("application/json");
143-
response.getWriter().write("{\"code\":\"UNAUTHENTICATED\",\"message\":\"Authentication required\"}");
143+
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
144+
response.setContentType(MediaType.APPLICATION_JSON);
145+
response.getWriter().write("{\"code\":\"UNAUTHORIZED\",\"message\":\"Authentication required\"}");
144146
}
145147

146148
private PdpAuthNHandler createHandler(String type, FilterConfig filterConfig) {

0 commit comments

Comments
 (0)