use of org.apache.nifi.authorization.user.NiFiUser in project nifi by apache.
the class TestRemoteProcessGroupAuditor method setup.
@Before
public void setup() {
final SecurityContext securityContext = SecurityContextHolder.getContext();
final Authentication authentication = mock(Authentication.class);
securityContext.setAuthentication(authentication);
final NiFiUser user = new Builder().identity("user-id").build();
final NiFiUserDetails userDetail = new NiFiUserDetails(user);
when(authentication.getPrincipal()).thenReturn(userDetail);
}
use of org.apache.nifi.authorization.user.NiFiUser in project nifi by apache.
the class DataAuthorizableTest method testCheckAuthorizationUserChain.
@Test
public void testCheckAuthorizationUserChain() {
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();
final AuthorizationResult result = testDataAuthorizable.checkAuthorization(testAuthorizer, RequestAction.READ, user, null);
assertEquals(Result.Approved, result.getResult());
verify(testAuthorizer, times(3)).authorize(any(AuthorizationRequest.class));
verifyAuthorizeForUser(IDENTITY_1);
verifyAuthorizeForUser(PROXY_1);
verifyAuthorizeForUser(PROXY_2);
}
use of org.apache.nifi.authorization.user.NiFiUser in project nifi by apache.
the class DataAuthorizableTest method testAuthorizeUnauthorizedUser.
@Test(expected = AccessDeniedException.class)
public void testAuthorizeUnauthorizedUser() {
final NiFiUser user = new Builder().identity("unknown").build();
testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null);
}
use of org.apache.nifi.authorization.user.NiFiUser in project nifi by apache.
the class DataAuthorizableTest method testCheckAuthorizationUnauthorizedUser.
@Test
public void testCheckAuthorizationUnauthorizedUser() {
final NiFiUser user = new Builder().identity("unknown").build();
final AuthorizationResult result = testDataAuthorizable.checkAuthorization(testAuthorizer, RequestAction.READ, user, null);
assertEquals(Result.Denied, result.getResult());
}
use of org.apache.nifi.authorization.user.NiFiUser 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());
}
}));
}
Aggregations