NIFI-271

Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/1eb4387d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/1eb4387d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/1eb4387d

Branch: refs/heads/NIFI-292
Commit: 1eb4387dbe8964862316d9a2ce2e999651e2124b
Parents: e811929
Author: joewitt <[email protected]>
Authored: Mon Apr 27 21:29:06 2015 -0400
Committer: joewitt <[email protected]>
Committed: Mon Apr 27 21:29:06 2015 -0400

----------------------------------------------------------------------
 .../nifi-file-authorization-provider/pom.xml    |  8 ++
 .../FileAuthorizationProvider.java              | 90 +-------------------
 .../FileAuthorizationProviderTest.java          | 63 +++++++-------
 3 files changed, 41 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/1eb4387d/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/pom.xml
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/pom.xml
 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/pom.xml
index d79b0ca..b5cde8d 100644
--- 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/pom.xml
+++ 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/pom.xml
@@ -49,6 +49,14 @@
                     
<generateDirectory>${project.build.directory}/generated-sources/jaxb</generateDirectory>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <excludes>**/user/generated/*.java</excludes>
+                </configuration>
+            </plugin>            
+
         </plugins>
     </build>
     <dependencies>

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/1eb4387d/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/main/java/org/apache/nifi/authorization/FileAuthorizationProvider.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/main/java/org/apache/nifi/authorization/FileAuthorizationProvider.java
 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/main/java/org/apache/nifi/authorization/FileAuthorizationProvider.java
index 5657369..9c2cad5 100644
--- 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/main/java/org/apache/nifi/authorization/FileAuthorizationProvider.java
+++ 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/main/java/org/apache/nifi/authorization/FileAuthorizationProvider.java
@@ -167,23 +167,10 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
     public void preDestruction() {
     }
 
-    /**
-     * Determines if this provider has a default role.
-     *
-     * @return
-     */
     private boolean hasDefaultRoles() {
         return !defaultAuthorities.isEmpty();
     }
 
-    /**
-     * Determines if the specified dn is known to this authority provider. When
-     * this provider is configured to have default role(s), all dn are
-     * considered to exist.
-     *
-     * @param dn
-     * @return True if he dn is known, false otherwise
-     */
     @Override
     public boolean doesDnExist(String dn) throws AuthorityAccessException {
         if (hasDefaultRoles()) {
@@ -194,21 +181,11 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
         return user != null;
     }
 
-    /**
-     * Loads the authorities for the specified user. If this provider is
-     * configured for default user role(s) and a non existent dn is specified, 
a
-     * new user will be automatically created with the default role(s).
-     *
-     * @param dn
-     * @return
-     * @throws UnknownIdentityException
-     * @throws AuthorityAccessException
-     */
     @Override
     public synchronized Set<Authority> getAuthorities(String dn) throws 
UnknownIdentityException, AuthorityAccessException {
         final Set<Authority> authorities = EnumSet.noneOf(Authority.class);
 
-        // get the user 
+        // get the user
         final User user = getUser(dn);
 
         // ensure the user was located
@@ -234,16 +211,6 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
         return authorities;
     }
 
-    /**
-     * Adds the specified authorities to the specified user. Regardless of
-     * whether this provider is configured for a default user role, when a non
-     * existent dn is specified, an UnknownIdentityException will be thrown.
-     *
-     * @param dn
-     * @param authorities
-     * @throws UnknownIdentityException
-     * @throws AuthorityAccessException
-     */
     @Override
     public synchronized void setAuthorities(String dn, Set<Authority> 
authorities) throws UnknownIdentityException, AuthorityAccessException {
         // get the user
@@ -265,12 +232,6 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
         }
     }
 
-    /**
-     * Adds the specified authorities to the specified user.
-     *
-     * @param user
-     * @param authorities
-     */
     private void setUserAuthorities(final User user, final Set<Authority> 
authorities) {
         // clear the existing rules
         user.getRole().clear();
@@ -286,15 +247,6 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
         }
     }
 
-    /**
-     * Adds the specified user. If this provider is configured with default
-     * role(s) they will be added to the new user.
-     *
-     * @param dn
-     * @param group
-     * @throws UnknownIdentityException
-     * @throws AuthorityAccessException
-     */
     @Override
     public synchronized void addUser(String dn, String group) throws 
IdentityAlreadyExistsException, AuthorityAccessException {
         final User user = getUser(dn);
@@ -334,13 +286,6 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
         }
     }
 
-    /**
-     * Gets the users for the specified authority.
-     *
-     * @param authority
-     * @return
-     * @throws AuthorityAccessException
-     */
     @Override
     public synchronized Set<String> getUsers(Authority authority) throws 
AuthorityAccessException {
         final Set<String> userSet = new HashSet<>();
@@ -354,15 +299,6 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
         return userSet;
     }
 
-    /**
-     * Removes the specified user. Regardless of whether this provider is
-     * configured for a default user role, when a non existent dn is specified,
-     * an UnknownIdentityException will be thrown.
-     *
-     * @param dn
-     * @throws UnknownIdentityException
-     * @throws AuthorityAccessException
-     */
     @Override
     public synchronized void revokeUser(String dn) throws 
UnknownIdentityException, AuthorityAccessException {
         // get the user
@@ -496,24 +432,12 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
 
     /**
      * Grants access to download content regardless of FlowFile attributes.
-     * 
-     * @param dnChain
-     * @param attributes
-     * @return
-     * @throws UnknownIdentityException
-     * @throws AuthorityAccessException 
      */
     @Override
     public DownloadAuthorization authorizeDownload(List<String> dnChain, 
Map<String, String> attributes) throws UnknownIdentityException, 
AuthorityAccessException {
         return DownloadAuthorization.approved();
     }
 
-    /**
-     * Locates the user with the specified DN.
-     *
-     * @param dn
-     * @return
-     */
     private User getUser(String dn) throws UnknownIdentityException {
         // ensure the DN was specified
         if (dn == null) {
@@ -532,13 +456,6 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
         return desiredUser;
     }
 
-    /**
-     * Locates all users that are part of the specified group.
-     *
-     * @param group
-     * @return
-     * @throws UnknownIdentityException
-     */
     private Collection<User> getUserGroup(String group) throws 
UnknownIdentityException {
         // ensure the DN was specified
         if (group == null) {
@@ -559,11 +476,6 @@ public class FileAuthorizationProvider implements 
AuthorityProvider {
         return userGroup;
     }
 
-    /**
-     * Saves the users file.
-     *
-     * @throws Exception
-     */
     private void save() throws Exception {
         final Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/1eb4387d/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/test/java/org/apache/nifi/authorization/FileAuthorizationProviderTest.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/test/java/org/apache/nifi/authorization/FileAuthorizationProviderTest.java
 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/test/java/org/apache/nifi/authorization/FileAuthorizationProviderTest.java
index d02d4d7..7428500 100644
--- 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/test/java/org/apache/nifi/authorization/FileAuthorizationProviderTest.java
+++ 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorization-provider/src/test/java/org/apache/nifi/authorization/FileAuthorizationProviderTest.java
@@ -23,105 +23,106 @@ import 
org.apache.nifi.authorization.exception.ProviderCreationException;
 import org.apache.nifi.util.file.FileUtils;
 import org.apache.nifi.util.NiFiProperties;
 import org.junit.After;
+import static org.junit.Assert.assertEquals;
 import org.junit.Before;
 import org.junit.Test;
-import static org.mockito.Mockito.*;
-import static org.junit.Assert.*;
 import org.junit.Ignore;
 import org.mockito.Mockito;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 @Ignore
 public class FileAuthorizationProviderTest {
-    
+
     private FileAuthorizationProvider provider;
-    
+
     private File primary;
-    
+
     private File restore;
-    
+
     private NiFiProperties mockProperties;
-    
+
     private AuthorityProviderConfigurationContext mockConfigurationContext;
-    
+
     @Before
     public void setup() throws IOException {
-        
+
         primary = new File("target/primary/users.txt");
         restore = new File("target/restore/users.txt");
-        
+
         System.out.println("absolute path: " + primary.getAbsolutePath());
-        
+
         mockProperties = mock(NiFiProperties.class);
         
when(mockProperties.getRestoreDirectory()).thenReturn(restore.getParentFile());
-        
+
         mockConfigurationContext = 
mock(AuthorityProviderConfigurationContext.class);
         when(mockConfigurationContext.getProperty(Mockito.eq("Authorized Users 
File"))).thenReturn(primary.getPath());
-        
+
         provider = new FileAuthorizationProvider();
         provider.setNiFiProperties(mockProperties);
         provider.initialize(null);
-    }     
-    
+    }
+
     @After
     public void cleanup() throws Exception {
         deleteFile(primary);
         deleteFile(restore);
     }
-    
+
     private boolean deleteFile(final File file) {
-        if(file.isDirectory()) {
+        if (file.isDirectory()) {
             FileUtils.deleteFilesInDir(file, null, null, true, true);
         }
         return FileUtils.deleteFile(file, null, 10);
     }
-    
+
     @Test
     public void testPostContructionWhenRestoreDoesNotExist() throws Exception {
-        
+
         byte[] primaryBytes = "<users/>".getBytes();
         FileOutputStream fos = new FileOutputStream(primary);
         fos.write(primaryBytes);
         fos.close();
-        
+
         provider.onConfigured(mockConfigurationContext);
         assertEquals(primary.length(), restore.length());
     }
-    
+
     @Test
     public void testPostContructionWhenPrimaryDoesNotExist() throws Exception {
-        
+
         byte[] restoreBytes = "<users/>".getBytes();
         FileOutputStream fos = new FileOutputStream(restore);
         fos.write(restoreBytes);
         fos.close();
-        
+
         provider.onConfigured(mockConfigurationContext);
         assertEquals(restore.length(), primary.length());
-        
+
     }
-    
+
     @Test(expected = ProviderCreationException.class)
     public void testPostContructionWhenPrimaryDifferentThanRestore() throws 
Exception {
-        
+
         byte[] primaryBytes = "<users></users>".getBytes();
         FileOutputStream fos = new FileOutputStream(primary);
         fos.write(primaryBytes);
         fos.close();
-        
+
         byte[] restoreBytes = "<users/>".getBytes();
         fos = new FileOutputStream(restore);
         fos.write(restoreBytes);
         fos.close();
-        
+
         provider.onConfigured(mockConfigurationContext);
     }
-    
+
     @Test
     public void testPostContructionWhenPrimaryAndBackupDoNotExist() throws 
Exception {
-        
+
         provider.onConfigured(mockConfigurationContext);
         assertEquals(0, restore.length());
         assertEquals(restore.length(), primary.length());
     }
-    
+
 }

Reply via email to