http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/AuthorizeUserActionTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/AuthorizeUserActionTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/AuthorizeUserActionTest.java new file mode 100644 index 0000000..28ea4a9 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/AuthorizeUserActionTest.java @@ -0,0 +1,433 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.admin.service.action; + +import java.util.Date; +import java.util.EnumSet; +import java.util.Set; +import org.apache.nifi.admin.dao.AuthorityDAO; +import org.apache.nifi.admin.dao.DAOFactory; +import org.apache.nifi.admin.dao.DataAccessException; +import org.apache.nifi.admin.dao.UserDAO; +import org.apache.nifi.admin.service.AccountDisabledException; +import org.apache.nifi.admin.service.AccountNotFoundException; +import org.apache.nifi.admin.service.AccountPendingException; +import org.apache.nifi.admin.service.AdministrationException; +import org.apache.nifi.authorization.Authority; +import org.apache.nifi.authorization.AuthorityProvider; +import org.apache.nifi.authorization.exception.AuthorityAccessException; +import org.apache.nifi.authorization.exception.UnknownIdentityException; +import org.apache.nifi.user.AccountStatus; +import org.apache.nifi.user.NiFiUser; +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +/** + * + */ +public class AuthorizeUserActionTest { + + private static final String USER_ID_6 = "6"; + private static final String USER_ID_7 = "7"; + private static final String USER_ID_8 = "8"; + private static final String USER_ID_9 = "9"; + private static final String USER_ID_10 = "10"; + private static final String USER_ID_11 = "11"; + + private static final String USER_DN_1 = "authority access exception while searching for user"; + private static final String USER_DN_2 = "unknown user"; + private static final String USER_DN_3 = "user removed after checking existence"; + private static final String USER_DN_4 = "access exception getting authorities"; + private static final String USER_DN_5 = "error creating user account"; + private static final String USER_DN_6 = "create user general sequence"; + private static final String USER_DN_7 = "existing user requires verification"; + private static final String USER_DN_8 = "existing user does not require verification"; + private static final String USER_DN_9 = "existing pending user"; + private static final String USER_DN_10 = "existing disabled user"; + private static final String USER_DN_11 = "existing user is now unknown in the authority provider"; + + private DAOFactory daoFactory; + private UserDAO userDao; + private AuthorityDAO authorityDao; + private AuthorityProvider authorityProvider; + + @Before + public void setup() throws Exception { + // mock the user dao + userDao = Mockito.mock(UserDAO.class); + Mockito.doAnswer(new Answer<NiFiUser>() { + @Override + public NiFiUser answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String id = (String) args[0]; + + NiFiUser user = null; + if (USER_ID_7.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_7); + user.setDn(USER_DN_7); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + } else if (USER_ID_8.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_8); + user.setDn(USER_DN_8); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + user.setLastVerified(new Date()); + } else if (USER_ID_11.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_11); + user.setDn(USER_DN_11); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + user.setStatus(AccountStatus.ACTIVE); + } + + return user; + } + }).when(userDao).findUserById(Mockito.anyString()); + Mockito.doAnswer(new Answer<NiFiUser>() { + @Override + public NiFiUser answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + + NiFiUser user = null; + switch (dn) { + case USER_DN_7: + user = new NiFiUser(); + user.setId(USER_ID_7); + user.setDn(USER_DN_7); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + break; + case USER_DN_8: + user = new NiFiUser(); + user.setId(USER_ID_8); + user.setDn(USER_DN_8); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + user.setLastVerified(new Date()); + break; + case USER_DN_9: + user = new NiFiUser(); + user.setId(USER_ID_9); + user.setDn(USER_DN_9); + user.setStatus(AccountStatus.PENDING); + break; + case USER_DN_10: + user = new NiFiUser(); + user.setId(USER_ID_10); + user.setDn(USER_DN_10); + user.setStatus(AccountStatus.DISABLED); + break; + case USER_DN_11: + user = new NiFiUser(); + user.setId(USER_ID_11); + user.setDn(USER_DN_11); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + user.setStatus(AccountStatus.ACTIVE); + break; + } + + return user; + } + }).when(userDao).findUserByDn(Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + NiFiUser user = (NiFiUser) args[0]; + switch (user.getDn()) { + case USER_DN_5: + throw new DataAccessException(); + case USER_DN_6: + user.setId(USER_ID_6); + break; + } + + // do nothing + return null; + } + }).when(userDao).createUser(Mockito.any(NiFiUser.class)); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + NiFiUser user = (NiFiUser) args[0]; + + // do nothing + return null; + } + }).when(userDao).updateUser(Mockito.any(NiFiUser.class)); + + // mock the authority dao + authorityDao = Mockito.mock(AuthorityDAO.class); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + Set<Authority> authorities = (Set<Authority>) args[0]; + String id = (String) args[1]; + + // do nothing + return null; + } + }).when(authorityDao).createAuthorities(Mockito.anySetOf(Authority.class), Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + Set<Authority> authorities = (Set<Authority>) args[0]; + String id = (String) args[1]; + + // do nothing + return null; + } + }).when(authorityDao).deleteAuthorities(Mockito.anySetOf(Authority.class), Mockito.anyString()); + + // mock the dao factory + daoFactory = Mockito.mock(DAOFactory.class); + Mockito.when(daoFactory.getUserDAO()).thenReturn(userDao); + Mockito.when(daoFactory.getAuthorityDAO()).thenReturn(authorityDao); + + // mock the authority provider + authorityProvider = Mockito.mock(AuthorityProvider.class); + Mockito.doAnswer(new Answer<Boolean>() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + switch (dn) { + case USER_DN_1: + throw new AuthorityAccessException(StringUtils.EMPTY); + case USER_DN_2: + return false; + } + + return true; + } + }).when(authorityProvider).doesDnExist(Mockito.anyString()); + Mockito.doAnswer(new Answer<Set<Authority>>() { + @Override + public Set<Authority> answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + Set<Authority> authorities = EnumSet.noneOf(Authority.class); + switch (dn) { + case USER_DN_3: + throw new UnknownIdentityException(StringUtils.EMPTY); + case USER_DN_4: + throw new AuthorityAccessException(StringUtils.EMPTY); + case USER_DN_6: + authorities.add(Authority.ROLE_MONITOR); + break; + case USER_DN_7: + authorities.add(Authority.ROLE_DFM); + break; + case USER_DN_9: + throw new UnknownIdentityException(StringUtils.EMPTY); + case USER_DN_10: + throw new UnknownIdentityException(StringUtils.EMPTY); + case USER_DN_11: + throw new UnknownIdentityException(StringUtils.EMPTY); + } + + return authorities; + } + }).when(authorityProvider).getAuthorities(Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + Set<Authority> authorites = (Set<Authority>) args[1]; + + // do nothing + return null; + } + }).when(authorityProvider).setAuthorities(Mockito.anyString(), Mockito.anySet()); + } + + /** + * Tests AuthorityAccessException in doesDnExist. + * + * @throws Exception ex + */ + @Test(expected = AdministrationException.class) + public void testAuthorityAccessExceptionInDoesDnExist() throws Exception { + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_1, 0); + authorizeUser.execute(daoFactory, authorityProvider); + } + + /** + * Test unknown user in the authority provider. + * + * @throws Exception ex + */ + @Test(expected = AccountNotFoundException.class) + public void testUnknownUser() throws Exception { + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_2, 0); + authorizeUser.execute(daoFactory, authorityProvider); + } + + /** + * Test a user thats been removed after checking their existence. + * + * @throws Exception ex + */ + @Test(expected = AccountNotFoundException.class) + public void testUserRemovedAfterCheckingExistence() throws Exception { + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_3, 0); + authorizeUser.execute(daoFactory, authorityProvider); + } + + /** + * Testing AuthorityAccessException when getting authorities. + * + * @throws Exception ex + */ + @Test(expected = AdministrationException.class) + public void testAuthorityAccessException() throws Exception { + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_4, 0); + authorizeUser.execute(daoFactory, authorityProvider); + } + + /** + * Testing DataAccessException while creating user accounts. + * + * @throws Exception ex + */ + @Test(expected = DataAccessException.class) + public void testErrorCreatingUserAccount() throws Exception { + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_5, 0); + authorizeUser.execute(daoFactory, authorityProvider); + } + + /** + * Tests the general case when a user account is created. + * + * @throws Exception ex + */ + @Test + public void testAccountCreation() throws Exception { + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_6, 0); + NiFiUser user = authorizeUser.execute(daoFactory, authorityProvider); + + // verify the user + Assert.assertEquals(USER_DN_6, user.getDn()); + Assert.assertEquals(1, user.getAuthorities().size()); + Assert.assertTrue(user.getAuthorities().contains(Authority.ROLE_MONITOR)); + + // verify interaction with dao and provider + Mockito.verify(userDao, Mockito.times(1)).createUser(user); + } + + /** + * Tests the general case when there is an existing user account that + * requires verification. + * + * @throws Exception ex + */ + @Test + public void testExistingUserRequiresVerification() throws Exception { + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_7, 0); + NiFiUser user = authorizeUser.execute(daoFactory, authorityProvider); + + // verify the user + Assert.assertEquals(USER_DN_7, user.getDn()); + Assert.assertEquals(1, user.getAuthorities().size()); + Assert.assertTrue(user.getAuthorities().contains(Authority.ROLE_DFM)); + + // verify interaction with dao and provider + Mockito.verify(userDao, Mockito.times(1)).updateUser(user); + Mockito.verify(authorityDao, Mockito.times(1)).createAuthorities(EnumSet.of(Authority.ROLE_DFM), USER_ID_7); + } + + /** + * Tests the general case when there is an existing user account that does + * not require verification. + * + * @throws Exception ex + */ + @Test + public void testExistingUserNoVerification() throws Exception { + // disabling verification by passing in a large cache duration + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_8, Integer.MAX_VALUE); + NiFiUser user = authorizeUser.execute(daoFactory, authorityProvider); + + // verify the user + Assert.assertEquals(USER_DN_8, user.getDn()); + Assert.assertEquals(1, user.getAuthorities().size()); + Assert.assertTrue(user.getAuthorities().contains(Authority.ROLE_MONITOR)); + + // verify interaction with dao and provider + Mockito.verify(userDao, Mockito.times(1)).updateUser(user); + Mockito.verify(authorityDao, Mockito.never()).createAuthorities(Mockito.anySet(), Mockito.eq(USER_ID_8)); + Mockito.verify(authorityDao, Mockito.never()).deleteAuthorities(Mockito.anySet(), Mockito.eq(USER_ID_8)); + } + + /** + * Tests existing users whose accounts are in a pending status. + * + * @throws Exception ex + */ + @Test(expected = AccountPendingException.class) + public void testExistingPendingUser() throws Exception { + // disabling verification by passing in a large cache duration + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_9, Integer.MAX_VALUE); + authorizeUser.execute(daoFactory, authorityProvider); + } + + /** + * Tests existing users whose accounts are in a disabled status. + * + * @throws Exception ex + */ + @Test(expected = AccountDisabledException.class) + public void testExistingDisabledUser() throws Exception { + // disabling verification by passing in a large cache duration + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_10, Integer.MAX_VALUE); + authorizeUser.execute(daoFactory, authorityProvider); + } + + /** + * Tests the general case where there is an active user that has been + * removed from the authority provider. + * + * @throws Exception ex + */ + @Test + public void testExistingActiveUserNotFoundInProvider() throws Exception { + try { + AuthorizeUserAction authorizeUser = new AuthorizeUserAction(USER_DN_11, 0); + authorizeUser.execute(daoFactory, authorityProvider); + + Assert.fail(); + } catch (AccountDisabledException ade) { + ArgumentCaptor<NiFiUser> user = ArgumentCaptor.forClass(NiFiUser.class); + + // verify interaction with dao + Mockito.verify(userDao, Mockito.times(1)).updateUser(user.capture()); + + // verify user + Assert.assertEquals(AccountStatus.DISABLED, user.getValue().getStatus()); + } + } +}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/CreateUserActionTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/CreateUserActionTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/CreateUserActionTest.java new file mode 100644 index 0000000..6486d32 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/CreateUserActionTest.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.admin.service.action; + +import java.util.EnumSet; +import java.util.Set; +import org.apache.nifi.admin.dao.AuthorityDAO; +import org.apache.nifi.admin.dao.DAOFactory; +import org.apache.nifi.admin.dao.DataAccessException; +import org.apache.nifi.admin.dao.UserDAO; +import org.apache.nifi.authorization.Authority; +import org.apache.nifi.user.NiFiUser; +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +/** + * Test cases for creating a user. + */ +public class CreateUserActionTest { + + private final String USER_ID_2 = "2"; + private final String USER_ID_3 = "3"; + + private final String USER_DN_1 = "data access exception when creating user"; + private final String USER_DN_3 = "general create user case"; + + private DAOFactory daoFactory; + private UserDAO userDao; + private AuthorityDAO authorityDao; + + @Before + public void setup() throws Exception { + // mock the user dao + userDao = Mockito.mock(UserDAO.class); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + NiFiUser user = (NiFiUser) args[0]; + + if (USER_DN_1.equals(user.getDn())) { + throw new DataAccessException(); + } else if (USER_DN_3.equals(user.getDn())) { + user.setId(USER_ID_3); + } + + // do nothing + return null; + } + }).when(userDao).createUser(Mockito.any(NiFiUser.class)); + + // mock the authority dao + authorityDao = Mockito.mock(AuthorityDAO.class); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + Set<Authority> authorities = (Set<Authority>) args[0]; + String id = (String) args[1]; + + if (USER_ID_2.equals(id)) { + throw new DataAccessException(StringUtils.EMPTY); + } + + // do nothing + return null; + } + }).when(authorityDao).createAuthorities(Mockito.anySetOf(Authority.class), Mockito.anyString()); + + // mock the dao factory + daoFactory = Mockito.mock(DAOFactory.class); + Mockito.when(daoFactory.getUserDAO()).thenReturn(userDao); + Mockito.when(daoFactory.getAuthorityDAO()).thenReturn(authorityDao); + } + + /** + * Tests DataAccessExceptions that occur while creating user accounts. + * + * @throws Exception ex + */ + @Test(expected = DataAccessException.class) + public void testExceptionCreatingUser() throws Exception { + NiFiUser user = new NiFiUser(); + user.setDn(USER_DN_1); + + CreateUserAction createUser = new CreateUserAction(user); + createUser.execute(daoFactory, null); + } + + /** + * Tests DataAccessExceptions that occur while create user authorities. + * + * @throws Exception ex + */ + @Test(expected = DataAccessException.class) + public void testExceptionCreatingAuthoroties() throws Exception { + NiFiUser user = new NiFiUser(); + user.setId(USER_ID_2); + + CreateUserAction createUser = new CreateUserAction(user); + createUser.execute(daoFactory, null); + } + + /** + * General case for creating a user. + * + * @throws Exception ex + */ + @Test + public void testCreateUserAccount() throws Exception { + NiFiUser user = new NiFiUser(); + user.setDn(USER_DN_3); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_DFM, Authority.ROLE_ADMIN)); + + CreateUserAction createUser = new CreateUserAction(user); + createUser.execute(daoFactory, null); + + // verify the user + Assert.assertEquals(USER_ID_3, user.getId()); + + // verify interaction with dao + Mockito.verify(userDao, Mockito.times(1)).createUser(user); + Mockito.verify(authorityDao, Mockito.times(1)).createAuthorities(user.getAuthorities(), USER_ID_3); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/DisableUserActionTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/DisableUserActionTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/DisableUserActionTest.java new file mode 100644 index 0000000..b0e1ac1 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/DisableUserActionTest.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.admin.service.action; + +import org.apache.nifi.admin.dao.DAOFactory; +import org.apache.nifi.admin.dao.DataAccessException; +import org.apache.nifi.admin.dao.UserDAO; +import org.apache.nifi.admin.service.AccountNotFoundException; +import org.apache.nifi.admin.service.AdministrationException; +import org.apache.nifi.authorization.AuthorityProvider; +import org.apache.nifi.authorization.exception.AuthorityAccessException; +import org.apache.nifi.user.AccountStatus; +import org.apache.nifi.user.NiFiUser; +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +public class DisableUserActionTest { + + private static final String USER_ID_1 = "1"; + private static final String USER_ID_2 = "2"; + private static final String USER_ID_3 = "3"; + private static final String USER_ID_4 = "4"; + + private static final String USER_DN_3 = "authority access exception"; + private static final String USER_DN_4 = "general disable user case"; + + private DAOFactory daoFactory; + private UserDAO userDao; + private AuthorityProvider authorityProvider; + + @Before + public void setup() throws Exception { + // mock the user dao + userDao = Mockito.mock(UserDAO.class); + Mockito.doAnswer(new Answer<NiFiUser>() { + @Override + public NiFiUser answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String id = (String) args[0]; + + NiFiUser user = null; + if (USER_ID_1.equals(id)) { + // leave user uninitialized + } else if (USER_ID_2.equals(id)) { + user = new NiFiUser(); + user.setId(id); + } else if (USER_ID_3.equals(id)) { + user = new NiFiUser(); + user.setId(id); + user.setDn(USER_DN_3); + } else if (USER_ID_4.equals(id)) { + user = new NiFiUser(); + user.setId(id); + user.setDn(USER_DN_4); + user.setStatus(AccountStatus.ACTIVE); + } + return user; + } + }).when(userDao).findUserById(Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + NiFiUser user = (NiFiUser) args[0]; + + if (USER_ID_2.equals(user.getId())) { + throw new DataAccessException(StringUtils.EMPTY); + } + + // do nothing + return null; + } + }).when(userDao).updateUser(Mockito.any(NiFiUser.class)); + + // mock the dao factory + daoFactory = Mockito.mock(DAOFactory.class); + Mockito.when(daoFactory.getUserDAO()).thenReturn(userDao); + + // mock the authority provider + authorityProvider = Mockito.mock(AuthorityProvider.class); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + + if (USER_DN_3.equals(dn)) { + throw new AuthorityAccessException(StringUtils.EMPTY); + } + + // do nothing + return null; + } + }).when(authorityProvider).revokeUser(Mockito.anyString()); + } + + /** + * Tests the case when the user account is unknown. + * + * @throws Exception ex + */ + @Test(expected = AccountNotFoundException.class) + public void testUnknownUserAccount() throws Exception { + DisableUserAction disableUser = new DisableUserAction(USER_ID_1); + disableUser.execute(daoFactory, authorityProvider); + } + + /** + * Tests the case when a DataAccessException is thrown by the userDao. + * + * @throws Exception ex + */ + @Test(expected = DataAccessException.class) + public void testDataAccessExceptionInUserDao() throws Exception { + DisableUserAction disableUser = new DisableUserAction(USER_ID_2); + disableUser.execute(daoFactory, authorityProvider); + } + + /** + * Tests the case when a AuthorityAccessException is thrown by the provider. + * + * @throws Exception ex + */ + @Test(expected = AdministrationException.class) + public void testAuthorityAccessExceptionInProvider() throws Exception { + DisableUserAction disableUser = new DisableUserAction(USER_ID_3); + disableUser.execute(daoFactory, authorityProvider); + } + + /** + * Tests the general case when the user is disabled. + * + * @throws Exception ex + */ + @Test + public void testDisableUser() throws Exception { + DisableUserAction disableUser = new DisableUserAction(USER_ID_4); + NiFiUser user = disableUser.execute(daoFactory, authorityProvider); + + // verify the user + Assert.assertEquals(USER_ID_4, user.getId()); + Assert.assertEquals(USER_DN_4, user.getDn()); + Assert.assertEquals(AccountStatus.DISABLED, user.getStatus()); + + // verify the interaction with the dao and provider + Mockito.verify(userDao, Mockito.times(1)).updateUser(user); + Mockito.verify(authorityProvider, Mockito.times(1)).revokeUser(USER_DN_4); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/InvalidateUserAccountActionTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/InvalidateUserAccountActionTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/InvalidateUserAccountActionTest.java new file mode 100644 index 0000000..cffd280 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/InvalidateUserAccountActionTest.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.admin.service.action; + +import java.util.Date; +import org.junit.Assert; +import org.apache.nifi.admin.dao.DAOFactory; +import org.apache.nifi.admin.dao.DataAccessException; +import org.apache.nifi.admin.dao.UserDAO; +import org.apache.nifi.admin.service.AccountNotFoundException; +import org.apache.nifi.user.NiFiUser; +import org.apache.commons.lang3.StringUtils; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +/** + * Test case for InvalidateUserAccountAction. + */ +public class InvalidateUserAccountActionTest { + + private static final String USER_ID_1 = "1"; + private static final String USER_ID_2 = "2"; + private static final String USER_ID_3 = "3"; + + private DAOFactory daoFactory; + private UserDAO userDao; + + @Before + public void setup() throws Exception { + // mock the user dao + userDao = Mockito.mock(UserDAO.class); + Mockito.doAnswer(new Answer<NiFiUser>() { + @Override + public NiFiUser answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String id = (String) args[0]; + + NiFiUser user = null; + if (USER_ID_1.equals(id)) { + // leave uninitialized + } else if (USER_ID_2.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_2); + } else if (USER_ID_3.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_3); + user.setLastVerified(new Date()); + } + return user; + } + }).when(userDao).findUserById(Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + NiFiUser user = (NiFiUser) args[0]; + + if (USER_ID_2.equals(user.getId())) { + throw new DataAccessException(StringUtils.EMPTY); + } + + // do nothing + return null; + } + }).when(userDao).updateUser(Mockito.any(NiFiUser.class)); + + // mock the dao factory + daoFactory = Mockito.mock(DAOFactory.class); + Mockito.when(daoFactory.getUserDAO()).thenReturn(userDao); + } + + @Test(expected = AccountNotFoundException.class) + public void testAccountNotFoundException() throws Exception { + InvalidateUserAccountAction invalidateUserAccount = new InvalidateUserAccountAction(USER_ID_1); + invalidateUserAccount.execute(daoFactory, null); + } + + /** + * Tests when a data access exception occurs when updating the user record. + * + * @throws Exception ex + */ + @Test(expected = DataAccessException.class) + public void testDataAccessException() throws Exception { + InvalidateUserAccountAction invalidateUserAccount = new InvalidateUserAccountAction(USER_ID_2); + invalidateUserAccount.execute(daoFactory, null); + } + + /** + * Tests the general case of invalidating a user. + * + * @throws Exception ex + */ + @Test + public void testInvalidateUser() throws Exception { + InvalidateUserAccountAction invalidateUserAccount = new InvalidateUserAccountAction(USER_ID_3); + invalidateUserAccount.execute(daoFactory, null); + + // verify the interaction with the dao + ArgumentCaptor<NiFiUser> userCaptor = ArgumentCaptor.forClass(NiFiUser.class); + Mockito.verify(userDao, Mockito.times(1)).updateUser(userCaptor.capture()); + + // verify the user + NiFiUser user = userCaptor.getValue(); + Assert.assertEquals(USER_ID_3, user.getId()); + Assert.assertNull(user.getLastVerified()); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/RequestUserAccountActionTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/RequestUserAccountActionTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/RequestUserAccountActionTest.java new file mode 100644 index 0000000..7707b2c --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/RequestUserAccountActionTest.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.admin.service.action; + +import org.apache.nifi.admin.dao.DAOFactory; +import org.apache.nifi.admin.dao.DataAccessException; +import org.apache.nifi.admin.dao.UserDAO; +import org.apache.nifi.user.AccountStatus; +import org.apache.nifi.user.NiFiUser; +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +/** + * Test case for RequestUserAccountAction. + */ +public class RequestUserAccountActionTest { + + private static final String USER_ID_3 = "3"; + + private static final String USER_DN_1 = "existing user account dn"; + private static final String USER_DN_2 = "data access exception"; + private static final String USER_DN_3 = "new account request"; + + private DAOFactory daoFactory; + private UserDAO userDao; + + @Before + public void setup() throws Exception { + // mock the user dao + userDao = Mockito.mock(UserDAO.class); + Mockito.doAnswer(new Answer<NiFiUser>() { + @Override + public NiFiUser answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + + NiFiUser user = null; + if (USER_DN_1.equals(dn)) { + user = new NiFiUser(); + } + return user; + } + }).when(userDao).findUserByDn(Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + NiFiUser user = (NiFiUser) args[0]; + switch (user.getDn()) { + case USER_DN_2: + throw new DataAccessException(); + case USER_DN_3: + user.setId(USER_ID_3); + break; + } + + // do nothing + return null; + } + }).when(userDao).createUser(Mockito.any(NiFiUser.class)); + + // mock the dao factory + daoFactory = Mockito.mock(DAOFactory.class); + Mockito.when(daoFactory.getUserDAO()).thenReturn(userDao); + } + + /** + * Tests when a user account already exists. + * + * @throws Exception ex + */ + @Test(expected = IllegalArgumentException.class) + public void testExistingAccount() throws Exception { + RequestUserAccountAction requestUserAccount = new RequestUserAccountAction(USER_DN_1, StringUtils.EMPTY); + requestUserAccount.execute(daoFactory, null); + } + + /** + * Tests when a DataAccessException occurs while saving the new account + * request. + * + * @throws Exception ex + */ + @Test(expected = DataAccessException.class) + public void testDataAccessException() throws Exception { + RequestUserAccountAction requestUserAccount = new RequestUserAccountAction(USER_DN_2, StringUtils.EMPTY); + requestUserAccount.execute(daoFactory, null); + } + + /** + * Tests the general case for requesting a new user account. + * + * @throws Exception ex + */ + @Test + public void testRequestUserAccountAction() throws Exception { + RequestUserAccountAction requestUserAccount = new RequestUserAccountAction(USER_DN_3, StringUtils.EMPTY); + NiFiUser user = requestUserAccount.execute(daoFactory, null); + + // verfiy the user + Assert.assertEquals(USER_ID_3, user.getId()); + Assert.assertEquals(USER_DN_3, user.getDn()); + Assert.assertEquals(AccountStatus.PENDING, user.getStatus()); + + // verify interaction with dao + Mockito.verify(userDao, Mockito.times(1)).createUser(user); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/SeedUserAccountsActionTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/SeedUserAccountsActionTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/SeedUserAccountsActionTest.java new file mode 100644 index 0000000..652d992 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/SeedUserAccountsActionTest.java @@ -0,0 +1,262 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.admin.service.action; + +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; +import org.apache.nifi.admin.dao.AuthorityDAO; +import org.apache.nifi.admin.dao.DAOFactory; +import org.apache.nifi.admin.dao.UserDAO; +import org.apache.nifi.authorization.Authority; +import org.apache.nifi.authorization.AuthorityProvider; +import org.apache.nifi.user.AccountStatus; +import org.apache.nifi.user.NiFiUser; +import org.hamcrest.Matcher; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatcher; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +/** + * + */ +public class SeedUserAccountsActionTest { + + private static final String USER_ID_1 = "1"; + private static final String USER_ID_2 = "2"; + private static final String USER_ID_3 = "3"; + private static final String USER_ID_4 = "4"; + + private static final String USER_DN_1 = "user dn 1 - active user - remove monitor and operator, add dfm"; + private static final String USER_DN_2 = "user dn 2 - active user - no action"; + private static final String USER_DN_3 = "user dn 3 - pending user - add operator"; + private static final String USER_DN_4 = "user dn 4 - new user - add monitor"; + + private DAOFactory daoFactory; + private UserDAO userDao; + private AuthorityDAO authorityDao; + private AuthorityProvider authorityProvider; + + @Before + public void setup() throws Exception { + // mock the user dao + userDao = Mockito.mock(UserDAO.class); + Mockito.doAnswer(new Answer<NiFiUser>() { + @Override + public NiFiUser answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String id = (String) args[0]; + + NiFiUser user = null; + if (USER_ID_1.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_1); + user.setDn(USER_DN_1); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + user.setStatus(AccountStatus.ACTIVE); + } else if (USER_ID_2.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_2); + user.setDn(USER_DN_2); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_ADMIN)); + user.setStatus(AccountStatus.ACTIVE); + } else if (USER_ID_3.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_3); + user.setDn(USER_DN_3); + user.setStatus(AccountStatus.PENDING); + } + return user; + } + }).when(userDao).findUserById(Mockito.anyString()); + Mockito.doAnswer(new Answer<NiFiUser>() { + @Override + public NiFiUser answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + + NiFiUser user = null; + if (USER_DN_1.equals(dn)) { + user = new NiFiUser(); + user.setId(USER_ID_1); + user.setDn(USER_DN_1); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + user.setStatus(AccountStatus.ACTIVE); + } else if (USER_DN_2.equals(dn)) { + user = new NiFiUser(); + user.setId(USER_ID_2); + user.setDn(USER_DN_2); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_ADMIN)); + user.setStatus(AccountStatus.ACTIVE); + } else if (USER_DN_3.equals(dn)) { + user = new NiFiUser(); + user.setId(USER_ID_3); + user.setDn(USER_DN_3); + user.setStatus(AccountStatus.PENDING); + } + return user; + } + }).when(userDao).findUserByDn(Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + NiFiUser user = (NiFiUser) args[0]; + + if (USER_DN_4.equals(user.getDn())) { + user.setId(USER_ID_4); + } + + return null; + } + }).when(userDao).createUser(Mockito.any(NiFiUser.class)); + + // mock the authority dao + authorityDao = Mockito.mock(AuthorityDAO.class); + + // mock the authority provider + authorityProvider = Mockito.mock(AuthorityProvider.class); + Mockito.doAnswer(new Answer<Set<String>>() { + @Override + public Set<String> answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + Authority role = (Authority) args[0]; + + Set<String> users = new HashSet<>(); + if (Authority.ROLE_DFM.equals(role)) { + users.add(USER_DN_1); + } else if (Authority.ROLE_ADMIN.equals(role)) { + users.add(USER_DN_2); + } else if (Authority.ROLE_PROXY.equals(role)) { + users.add(USER_DN_3); + } else if (Authority.ROLE_MONITOR.equals(role)) { + users.add(USER_DN_4); + } + return users; + } + }).when(authorityProvider).getUsers(Mockito.any(Authority.class)); + Mockito.doAnswer(new Answer<Set<Authority>>() { + @Override + public Set<Authority> answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + + Set<Authority> authorities = EnumSet.noneOf(Authority.class); + switch (dn) { + case USER_DN_1: + authorities.add(Authority.ROLE_DFM); + break; + case USER_DN_2: + authorities.add(Authority.ROLE_ADMIN); + break; + case USER_DN_3: + authorities.add(Authority.ROLE_PROXY); + break; + case USER_DN_4: + authorities.add(Authority.ROLE_MONITOR); + break; + } + return authorities; + } + }).when(authorityProvider).getAuthorities(Mockito.anyString()); + + // mock the dao factory + daoFactory = Mockito.mock(DAOFactory.class); + Mockito.when(daoFactory.getUserDAO()).thenReturn(userDao); + Mockito.when(daoFactory.getAuthorityDAO()).thenReturn(authorityDao); + } + + /** + * Tests seeding the user accounts. + * + * @throws Exception ex + */ + @Test + public void testSeedUsers() throws Exception { + SeedUserAccountsAction seedUserAccounts = new SeedUserAccountsAction(); + seedUserAccounts.execute(daoFactory, authorityProvider); + + // matcher for user 1 + Matcher<NiFiUser> matchesUser1 = new ArgumentMatcher<NiFiUser>() { + @Override + public boolean matches(Object argument) { + NiFiUser user = (NiFiUser) argument; + return USER_ID_1.equals(user.getId()); + } + }; + + // verify user 1 - active existing user - remove monitor, operator, add dfm + Mockito.verify(userDao, Mockito.times(1)).updateUser(Mockito.argThat(matchesUser1)); + Mockito.verify(userDao, Mockito.never()).createUser(Mockito.argThat(matchesUser1)); + Mockito.verify(authorityDao, Mockito.times(1)).createAuthorities(EnumSet.of(Authority.ROLE_DFM), USER_ID_1); + + // matcher for user 2 + Matcher<NiFiUser> matchesUser2 = new ArgumentMatcher<NiFiUser>() { + @Override + public boolean matches(Object argument) { + NiFiUser user = (NiFiUser) argument; + return USER_ID_2.equals(user.getId()); + } + }; + + // verify user 2 - active existing user - no actions + Mockito.verify(userDao, Mockito.times(1)).updateUser(Mockito.argThat(matchesUser2)); + Mockito.verify(userDao, Mockito.never()).createUser(Mockito.argThat(matchesUser2)); + Mockito.verify(authorityDao, Mockito.never()).createAuthorities(Mockito.anySet(), Mockito.eq(USER_ID_2)); + Mockito.verify(authorityDao, Mockito.never()).deleteAuthorities(Mockito.anySet(), Mockito.eq(USER_ID_2)); + + // matchers for user 3 + Matcher<NiFiUser> matchesPendingUser3 = new ArgumentMatcher<NiFiUser>() { + @Override + public boolean matches(Object argument) { + NiFiUser user = (NiFiUser) argument; + return USER_ID_3.equals(user.getId()) && AccountStatus.ACTIVE.equals(user.getStatus()); + } + }; + Matcher<NiFiUser> matchesUser3 = new ArgumentMatcher<NiFiUser>() { + @Override + public boolean matches(Object argument) { + NiFiUser user = (NiFiUser) argument; + return USER_ID_3.equals(user.getId()); + } + }; + + // verify user 3 - pending user - add operator + Mockito.verify(userDao, Mockito.times(1)).updateUser(Mockito.argThat(matchesPendingUser3)); + Mockito.verify(userDao, Mockito.never()).createUser(Mockito.argThat(matchesUser3)); + Mockito.verify(authorityDao, Mockito.times(1)).createAuthorities(EnumSet.of(Authority.ROLE_PROXY), USER_ID_3); + Mockito.verify(authorityDao, Mockito.never()).deleteAuthorities(Mockito.anySet(), Mockito.eq(USER_ID_3)); + + // matcher for user 4 + Matcher<NiFiUser> matchesUser4 = new ArgumentMatcher<NiFiUser>() { + @Override + public boolean matches(Object argument) { + NiFiUser user = (NiFiUser) argument; + return USER_ID_4.equals(user.getId()); + } + }; + + // verify user 4 - new user - add monitor + Mockito.verify(userDao, Mockito.never()).updateUser(Mockito.argThat(matchesUser4)); + Mockito.verify(userDao, Mockito.times(1)).createUser(Mockito.argThat(matchesUser4)); + Mockito.verify(authorityDao, Mockito.times(1)).createAuthorities(EnumSet.of(Authority.ROLE_MONITOR), USER_ID_4); + Mockito.verify(authorityDao, Mockito.never()).deleteAuthorities(Mockito.anySet(), Mockito.eq(USER_ID_4)); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/SetUserAuthoritiesActionTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/SetUserAuthoritiesActionTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/SetUserAuthoritiesActionTest.java new file mode 100644 index 0000000..22504f7 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/test/java/org/apache/nifi/admin/service/action/SetUserAuthoritiesActionTest.java @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.admin.service.action; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.Set; +import org.apache.nifi.admin.dao.AuthorityDAO; +import org.apache.nifi.admin.dao.DAOFactory; +import org.apache.nifi.admin.dao.UserDAO; +import org.apache.nifi.admin.service.AccountNotFoundException; +import org.apache.nifi.admin.service.AdministrationException; +import org.apache.nifi.authorization.Authority; +import org.apache.nifi.authorization.AuthorityProvider; +import org.apache.nifi.authorization.exception.AuthorityAccessException; +import org.apache.nifi.user.AccountStatus; +import org.apache.nifi.user.NiFiUser; +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +/** + * Test case for SetUserAuthoritiesAction. + */ +public class SetUserAuthoritiesActionTest { + + private static final String USER_ID_1 = "1"; + private static final String USER_ID_2 = "2"; + private static final String USER_ID_3 = "3"; + + private static final String USER_DN_2 = "user dn 2"; + private static final String USER_DN_3 = "user dn 3"; + + private DAOFactory daoFactory; + private UserDAO userDao; + private AuthorityDAO authorityDao; + private AuthorityProvider authorityProvider; + + @Before + public void setup() throws Exception { + // mock the user dao + userDao = Mockito.mock(UserDAO.class); + Mockito.doAnswer(new Answer<NiFiUser>() { + @Override + public NiFiUser answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String id = (String) args[0]; + + NiFiUser user = null; + if (USER_ID_1.equals(id)) { + // leave user uninitialized + } else if (USER_ID_2.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_2); + user.setDn(USER_DN_2); + } else if (USER_ID_3.equals(id)) { + user = new NiFiUser(); + user.setId(USER_ID_3); + user.setDn(USER_DN_3); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + user.setStatus(AccountStatus.ACTIVE); + } + return user; + } + }).when(userDao).findUserById(Mockito.anyString()); + Mockito.doAnswer(new Answer<NiFiUser>() { + @Override + public NiFiUser answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + + NiFiUser user = null; + if (USER_DN_3.equals(dn)) { + user = new NiFiUser(); + user.setId(USER_ID_3); + user.setDn(USER_DN_3); + user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); + user.setStatus(AccountStatus.ACTIVE); + } + return user; + } + }).when(userDao).findUserByDn(Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + NiFiUser user = (NiFiUser) args[0]; + + // do nothing + return null; + } + }).when(userDao).updateUser(Mockito.any(NiFiUser.class)); + + // mock the authority dao + authorityDao = Mockito.mock(AuthorityDAO.class); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + Set<Authority> authorities = (Set<Authority>) args[0]; + String id = (String) args[1]; + + // do nothing + return null; + } + }).when(authorityDao).createAuthorities(Mockito.anySetOf(Authority.class), Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + Set<Authority> authorities = (Set<Authority>) args[0]; + String id = (String) args[1]; + + // do nothing + return null; + } + }).when(authorityDao).deleteAuthorities(Mockito.anySetOf(Authority.class), Mockito.anyString()); + + // mock the dao factory + daoFactory = Mockito.mock(DAOFactory.class); + Mockito.when(daoFactory.getUserDAO()).thenReturn(userDao); + Mockito.when(daoFactory.getAuthorityDAO()).thenReturn(authorityDao); + + // mock the authority provider + authorityProvider = Mockito.mock(AuthorityProvider.class); + Mockito.doAnswer(new Answer<Set<Authority>>() { + @Override + public Set<Authority> answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + + Set<Authority> authorities = EnumSet.noneOf(Authority.class); + if (USER_DN_3.equals(dn)) { + authorities.add(Authority.ROLE_DFM); + } + + return authorities; + } + }).when(authorityProvider).getAuthorities(Mockito.anyString()); + Mockito.doAnswer(new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + String dn = (String) args[0]; + Set<Authority> authorites = (Set<Authority>) args[1]; + + if (USER_DN_2.equals(dn)) { + throw new AuthorityAccessException(StringUtils.EMPTY); + } + + // do nothing + return null; + } + }).when(authorityProvider).setAuthorities(Mockito.anyString(), Mockito.anySet()); + } + + /** + * Test activating an unknown user account. User accounts are unknown then + * there is no pending account for the user. + * + * @throws Exception ex + */ + @Test(expected = AccountNotFoundException.class) + public void testUnknownUser() throws Exception { + UpdateUserAction setUserAuthorities = new UpdateUserAction(USER_ID_1, Collections.EMPTY_SET); + setUserAuthorities.execute(daoFactory, authorityProvider); + } + + /** + * Testing case then an AuthorityAccessException occurs while setting a + * users authorities. + * + * @throws Exception ex + */ + @Test(expected = AdministrationException.class) + public void testAuthorityAccessException() throws Exception { + UpdateUserAction setUserAuthorities = new UpdateUserAction(USER_ID_2, Collections.EMPTY_SET); + setUserAuthorities.execute(daoFactory, authorityProvider); + } + + /** + * Tests general case of setting user authorities. + * + * @throws Exception ex + */ + @Test + public void testSetAuthorities() throws Exception { + UpdateUserAction setUserAuthorities = new UpdateUserAction(USER_ID_3, EnumSet.of(Authority.ROLE_ADMIN)); + NiFiUser user = setUserAuthorities.execute(daoFactory, authorityProvider); + + // verify user + Assert.assertEquals(USER_ID_3, user.getId()); + Assert.assertEquals(1, user.getAuthorities().size()); + Assert.assertTrue(user.getAuthorities().contains(Authority.ROLE_ADMIN)); + + // verify interaction with dao + Mockito.verify(userDao, Mockito.times(1)).updateUser(user); + Mockito.verify(authorityDao, Mockito.times(1)).createAuthorities(EnumSet.of(Authority.ROLE_ADMIN), USER_ID_3); + + Set<Authority> authoritiesAddedToProvider = EnumSet.of(Authority.ROLE_ADMIN); + + // verify interaction with provider + Mockito.verify(authorityProvider, Mockito.times(1)).setAuthorities(USER_DN_3, authoritiesAddedToProvider); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/.gitignore ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/.gitignore b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/.gitignore new file mode 100755 index 0000000..cd1a4e7 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/.gitignore @@ -0,0 +1,6 @@ +/target +/target +/target +/target +/target +/target http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/pom.xml new file mode 100644 index 0000000..bf4177f --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/pom.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-framework</artifactId> + <version>0.3.0-SNAPSHOT</version> + </parent> + <artifactId>nifi-client-dto</artifactId> + <dependencies> + <dependency> + <groupId>com.wordnik</groupId> + <artifactId>swagger-annotations</artifactId> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AboutDTO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AboutDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AboutDTO.java new file mode 100644 index 0000000..83aad41 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AboutDTO.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.web.api.dto; + +import com.wordnik.swagger.annotations.ApiModelProperty; +import javax.xml.bind.annotation.XmlType; + +/** + * Contains details about this NiFi including the title and version. + */ +@XmlType(name = "about") +public class AboutDTO { + + private String title; + private String version; + + /* getters / setters */ + /** + * The title to be used on the page and in the About dialog. + * + * @return The title + */ + @ApiModelProperty( + value = "The title to be used on the page and in the about dialog." + ) + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + /** + * The version of this NiFi. + * + * @return The version. + */ + @ApiModelProperty( + value = "The version of this NiFi." + ) + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BannerDTO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BannerDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BannerDTO.java new file mode 100644 index 0000000..c0a691b --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BannerDTO.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.web.api.dto; + +import com.wordnik.swagger.annotations.ApiModelProperty; +import javax.xml.bind.annotation.XmlType; + +/** + * Banners that should appear on the top and bottom of this NiFi. + */ +@XmlType(name = "banners") +public class BannerDTO { + + private String headerText; + private String footerText; + + /* getters / setters */ + /** + * The banner footer text. + * + * @return The footer text + */ + @ApiModelProperty( + value = "The footer text." + ) + public String getFooterText() { + return footerText; + } + + public void setFooterText(String footerText) { + this.footerText = footerText; + } + + /** + * The banner header text. + * + * @return The header text + */ + @ApiModelProperty( + value = "The header text." + ) + public String getHeaderText() { + return headerText; + } + + public void setHeaderText(String headerText) { + this.headerText = headerText; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinBoardDTO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinBoardDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinBoardDTO.java new file mode 100644 index 0000000..455769a --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinBoardDTO.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.web.api.dto; + +import com.wordnik.swagger.annotations.ApiModelProperty; +import java.util.Date; +import java.util.List; + +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.apache.nifi.web.api.dto.util.TimeAdapter; + +/** + * The contents for the bulletin board including the bulletins and the timestamp when the board was generated. + */ +@XmlType(name = "bulletinBoard") +public class BulletinBoardDTO { + + private List<BulletinDTO> bulletins; + private Date generated; + + /** + * @return bulletins to populate in the bulletin board + */ + @ApiModelProperty( + value = "The bulletins in the bulletin board, that matches the supplied request." + ) + public List<BulletinDTO> getBulletins() { + return bulletins; + } + + public void setBulletins(List<BulletinDTO> bulletins) { + this.bulletins = bulletins; + } + + /** + * @return when this bulletin board was generated + */ + @XmlJavaTypeAdapter(TimeAdapter.class) + @ApiModelProperty( + value = "The timestamp when this report was generated." + ) + public Date getGenerated() { + return generated; + } + + public void setGenerated(final Date generated) { + this.generated = generated; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinDTO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinDTO.java new file mode 100644 index 0000000..4c552f6 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinDTO.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.web.api.dto; + +import com.wordnik.swagger.annotations.ApiModelProperty; +import java.util.Date; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.apache.nifi.web.api.dto.util.TimeAdapter; + +/** + * A bulletin that represents a notification about a passing event including, the source component (if applicable), the timestamp, the message, and where the bulletin originated (if applicable). + */ +@XmlType(name = "bulletin") +public class BulletinDTO { + + private Long id; + private String nodeAddress; + private String category; + private String groupId; + private String sourceId; + private String sourceName; + private String level; + private String message; + private Date timestamp; + + /** + * @return id of this message + */ + @ApiModelProperty( + value = "The id of the bulletin." + ) + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + /** + * @return When clustered, the address of the node from which this bulletin originated + */ + @ApiModelProperty( + value = "If clustered, the address of the node from whicih the bulletin originated." + ) + public String getNodeAddress() { + return nodeAddress; + } + + public void setNodeAddress(String nodeAddress) { + this.nodeAddress = nodeAddress; + } + + /** + * @return group id of the source component + */ + @ApiModelProperty( + value = "The group id of the source component." + ) + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + /** + * @return category of this message + */ + @ApiModelProperty( + value = "The catagory of this bulletin." + ) + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + /** + * @return actual message + */ + @ApiModelProperty( + value = "The bulletin message." + ) + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + /** + * @return id of the source of this message + */ + @ApiModelProperty( + value = "The id of the source component." + ) + public String getSourceId() { + return sourceId; + } + + public void setSourceId(String sourceId) { + this.sourceId = sourceId; + } + + /** + * @return name of the source of this message + */ + @ApiModelProperty( + value = "The name of the source component." + ) + public String getSourceName() { + return sourceName; + } + + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + + /** + * @return level of this bulletin + */ + @ApiModelProperty( + value = "The level of the bulletin." + ) + public String getLevel() { + return level; + } + + public void setLevel(String level) { + this.level = level; + } + + /** + * @return When this bulletin was generated as a formatted string + */ + @XmlJavaTypeAdapter(TimeAdapter.class) + @ApiModelProperty( + value = "When this bulletin was generated." + ) + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinQueryDTO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinQueryDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinQueryDTO.java new file mode 100644 index 0000000..e47cdf9 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/BulletinQueryDTO.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.web.api.dto; + +import com.wordnik.swagger.annotations.ApiModelProperty; +import javax.xml.bind.annotation.XmlType; + +/** + * A query for bulletin board. Will filter the resulting bulletin board according to the criteria in this query. + */ +@XmlType(name = "bulletinQuery") +public class BulletinQueryDTO { + + private String sourceId; + private String groupId; + private String name; + private String message; + private Long after; + private Integer limit; + + /** + * @return Include bulletins after this id + */ + @ApiModelProperty( + value = "Will include bulletins that occurred after this id. The ids are a one-up number that are used to ensure bulletins that " + + "occur at the same time will not be missed." + ) + public Long getAfter() { + return after; + } + + public void setAfter(Long after) { + this.after = after; + } + + /** + * @return Include bulletin within this group. Supports a regular expression + */ + @ApiModelProperty( + value = "Will include bulletins that occurred within this group. Supports a regular expression." + ) + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + /** + * @return Include bulletins that match this message. Supports a regular expression + */ + @ApiModelProperty( + value = "Will include bulletins that match this message. Supports a regular expression." + ) + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + /** + * @return Include bulletins that match this name. Supports a regular expression + */ + @ApiModelProperty( + value = "Will include bulletins that match this name. Supports a regular expression." + ) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * @return Include bulletins that match this id. Supports a source id + */ + @ApiModelProperty( + value = "Will include bulletins from components that match this id. Supports a regular expression." + ) + public String getSourceId() { + return sourceId; + } + + public void setSourceId(String sourceId) { + this.sourceId = sourceId; + } + + /** + * @return The maximum number of bulletins to return + */ + @ApiModelProperty( + value = "The maximum number of bulletins to return." + ) + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + +}