Search in sources :

Example 6 with Builder

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());
        }
    }));
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Builder(org.apache.nifi.authorization.user.StandardNiFiUser.Builder) ArgumentMatcher(org.mockito.ArgumentMatcher) Test(org.junit.Test)

Example 7 with Builder

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());
        }
    }));
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Builder(org.apache.nifi.authorization.user.StandardNiFiUser.Builder) ArgumentMatcher(org.mockito.ArgumentMatcher) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult) Test(org.junit.Test)

Example 8 with Builder

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);
}
Also used : AuthorizationRequest(org.apache.nifi.authorization.AuthorizationRequest) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Builder(org.apache.nifi.authorization.user.StandardNiFiUser.Builder) Test(org.junit.Test)

Example 9 with Builder

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 + ">");
}
Also used : ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Entity(org.apache.nifi.web.api.entity.Entity) StandardNiFiUser(org.apache.nifi.authorization.user.StandardNiFiUser) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Builder(org.apache.nifi.authorization.user.StandardNiFiUser.Builder) ClientBuilder(javax.ws.rs.client.ClientBuilder) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) URI(java.net.URI) NiFiAuthenticationToken(org.apache.nifi.web.security.token.NiFiAuthenticationToken) Authentication(org.springframework.security.core.Authentication) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NiFiUserDetails(org.apache.nifi.authorization.user.NiFiUserDetails) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Builder

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());
        }
    }));
}
Also used : AuthorizationRequest(org.apache.nifi.authorization.AuthorizationRequest) Authentication(org.springframework.security.core.Authentication) Builder(org.apache.nifi.authorization.user.StandardNiFiUser.Builder) ArgumentMatcher(org.mockito.ArgumentMatcher) NiFiUserDetails(org.apache.nifi.authorization.user.NiFiUserDetails) ActionEntity(org.apache.nifi.web.api.entity.ActionEntity) NiFiAuthenticationToken(org.apache.nifi.web.security.token.NiFiAuthenticationToken) Test(org.junit.Test)

Aggregations

Builder (org.apache.nifi.authorization.user.StandardNiFiUser.Builder)17 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)12 Test (org.junit.Test)12 NiFiUserDetails (org.apache.nifi.authorization.user.NiFiUserDetails)11 NiFiAuthenticationToken (org.apache.nifi.web.security.token.NiFiAuthenticationToken)10 Authentication (org.springframework.security.core.Authentication)7 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)5 ArgumentMatcher (org.mockito.ArgumentMatcher)5 InvalidAuthenticationException (org.apache.nifi.web.security.InvalidAuthenticationException)4 AuthorizationResult (org.apache.nifi.authorization.AuthorizationResult)3 StandardNiFiUser (org.apache.nifi.authorization.user.StandardNiFiUser)2 HistoryDTO (org.apache.nifi.web.api.dto.action.HistoryDTO)2 HistoryQueryDTO (org.apache.nifi.web.api.dto.action.HistoryQueryDTO)2 ActionEntity (org.apache.nifi.web.api.entity.ActionEntity)2 JOSEException (com.nimbusds.jose.JOSEException)1 JwtException (io.jsonwebtoken.JwtException)1 URI (java.net.URI)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1