use of org.apache.ranger.plugin.service.RangerBasePlugin in project ranger by apache.
the class RangerAtlasAuthorizer method checkAccess.
private boolean checkAccess(RangerAccessRequestImpl request, RangerAtlasAuditHandler auditHandler) {
boolean ret = false;
RangerBasePlugin plugin = atlasPlugin;
if (plugin != null) {
RangerAccessResult result = plugin.isAccessAllowed(request, auditHandler);
ret = result != null && result.getIsAllowed();
} else {
LOG.warn("RangerAtlasPlugin not initialized. Access blocked!!!");
}
return ret;
}
use of org.apache.ranger.plugin.service.RangerBasePlugin in project ranger by apache.
the class AuthorizationSessionTest method testIsBuildable.
@Test
public void testIsBuildable() {
RangerBasePlugin plugin = new RangerBasePlugin("hbase", "hbase");
AuthorizationSession session = new AuthorizationSession(plugin);
try {
session.verifyBuildable();
Assert.fail("Should have thrown exception");
} catch (IllegalStateException e) {
}
// user and access are the only required ones.
User user = mock(User.class);
when(user.getGroupNames()).thenReturn(new String[] { "groups", "group2" });
session.access(" ");
session.user(user);
try {
session.verifyBuildable();
} catch (IllegalStateException e) {
Assert.fail("Shouldn't have thrown an exception!");
}
// setting column-family without table is a problem
session.columnFamily("family");
try {
session.verifyBuildable();
Assert.fail("Should have thrown an exception");
} catch (IllegalStateException e) {
}
session.table("table");
try {
session.verifyBuildable();
} catch (IllegalStateException e) {
Assert.fail("Shouldn't have thrown an exception!");
}
// setting column without column-family is a problem
session.columnFamily(null);
session.column("col");
try {
session.verifyBuildable();
Assert.fail("Should have thrown an exception");
} catch (IllegalStateException e) {
}
session.columnFamily("family");
try {
session.verifyBuildable();
} catch (IllegalStateException e) {
Assert.fail("Should have thrown an exception");
}
}
use of org.apache.ranger.plugin.service.RangerBasePlugin in project ranger by apache.
the class AuthorizationSessionTest method testAuthorize.
@Test
public void testAuthorize() {
RangerBasePlugin plugin = new RangerBasePlugin("hbase", "hbase");
User user = mock(User.class);
when(user.getShortName()).thenReturn("user1");
when(user.getGroupNames()).thenReturn(new String[] { "users" });
AuthorizationSession session = new AuthorizationSession(plugin);
session.access("read").user(user).table(":meta:").buildRequest().authorize();
}
use of org.apache.ranger.plugin.service.RangerBasePlugin in project ranger by apache.
the class TestPolicyEngine method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
plugin = new RangerBasePlugin("hbase", "hbase");
gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").setPrettyPrinting().registerTypeAdapter(RangerAccessRequest.class, new RangerAccessRequestDeserializer()).registerTypeAdapter(RangerAccessResource.class, new RangerResourceDeserializer()).create();
}
use of org.apache.ranger.plugin.service.RangerBasePlugin in project ranger by apache.
the class RangerAuthorizer method init.
public void init() {
if (plugin == null) {
synchronized (RangerAuthorizer.class) {
if (plugin == null) {
plugin = new RangerBasePlugin("sampleapp", "sampleapp");
plugin.setResultProcessor(new RangerDefaultAuditHandler());
plugin.init();
}
}
}
}
Aggregations