use of org.apache.nifi.authorization.user.StandardNiFiUser.Builder in project nifi by apache.
the class DataAuthorizableTest method testAuthorizedUser.
@Test
public void testAuthorizedUser() {
final NiFiUser user = new Builder().identity(IDENTITY_1).build();
testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null);
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
}
}));
}
use of org.apache.nifi.authorization.user.StandardNiFiUser.Builder in project nifi by apache.
the class DataAuthorizableTest method testCheckAuthorizationUser.
@Test
public void testCheckAuthorizationUser() {
final NiFiUser user = new Builder().identity(IDENTITY_1).build();
final AuthorizationResult result = testDataAuthorizable.checkAuthorization(testAuthorizer, RequestAction.READ, user, null);
assertEquals(Result.Approved, result.getResult());
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
}
}));
}
use of org.apache.nifi.authorization.user.StandardNiFiUser.Builder in project nifi by apache.
the class DataAuthorizableTest method testAuthorizedUserChain.
@Test
public void testAuthorizedUserChain() {
final NiFiUser proxy2 = new Builder().identity(PROXY_2).build();
final NiFiUser proxy1 = new Builder().identity(PROXY_1).chain(proxy2).build();
final NiFiUser user = new Builder().identity(IDENTITY_1).chain(proxy1).build();
testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null);
verify(testAuthorizer, times(3)).authorize(any(AuthorizationRequest.class));
verifyAuthorizeForUser(IDENTITY_1);
verifyAuthorizeForUser(PROXY_1);
verifyAuthorizeForUser(PROXY_2);
}
use of org.apache.nifi.authorization.user.StandardNiFiUser.Builder in project nifi by apache.
the class TestThreadPoolRequestReplicator method testRequestChain.
@Test
public void testRequestChain() {
final String proxyIdentity2 = "proxy-2";
final String proxyIdentity1 = "proxy-1";
final String userIdentity = "user";
withReplicator(replicator -> {
final Set<NodeIdentifier> nodeIds = new HashSet<>();
nodeIds.add(new NodeIdentifier("1", "localhost", 8000, "localhost", 8001, "localhost", 8002, 8003, false));
final URI uri = new URI("http://localhost:8080/processors/1");
final Entity entity = new ProcessorEntity();
// set the user
final NiFiUser proxy2 = new Builder().identity(proxyIdentity2).build();
final NiFiUser proxy1 = new Builder().identity(proxyIdentity1).chain(proxy2).build();
final NiFiUser user = new Builder().identity(userIdentity).chain(proxy1).build();
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(user));
SecurityContextHolder.getContext().setAuthentication(authentication);
replicator.replicate(nodeIds, HttpMethod.GET, uri, entity, new HashMap<>(), true, true);
}, Response.Status.OK, 0L, null, "<" + userIdentity + "><" + proxyIdentity1 + "><" + proxyIdentity2 + ">");
}
use of org.apache.nifi.authorization.user.StandardNiFiUser.Builder in project nifi by apache.
the class StandardNiFiServiceFacadeTest method testGetActionApprovedThroughController.
@Test
public void testGetActionApprovedThroughController() throws Exception {
// set the user
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_2).build()));
SecurityContextHolder.getContext().setAuthentication(authentication);
// get the action
final ActionEntity entity = serviceFacade.getAction(ACTION_ID_2);
// verify
assertEquals(ACTION_ID_2, entity.getId());
assertTrue(entity.getCanRead());
// component does not exists, so only checks against the controller
verify(authorizer, times(0)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return ((AuthorizationRequest) o).getResource().getIdentifier().endsWith(PROCESSOR_ID_2);
}
}));
verify(authorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return ((AuthorizationRequest) o).getResource().equals(ResourceFactory.getControllerResource());
}
}));
}
Aggregations