Fix issues in checkstyle enforcement for module aaa-idmlight 24/57024/4
authorDavid Suarez <david.suarez.fuentes@ericsson.com>
Sun, 14 May 2017 18:55:44 +0000 (20:55 +0200)
committerRyan Goulding <ryandgoulding@gmail.com>
Fri, 2 Jun 2017 16:36:48 +0000 (16:36 +0000)
- Copyright section
- Order imports
- Line lengths
- JavaDocs
- Improve exception handling
- Change variables and methods names
- Move variables closer to their use
- Move overloaded methods closer to each other
- Declare some static constants properly
- Enforcement in pom.xml

Change-Id: Ic673b8239c3abd7ba0c23a242293fe32cc48b103
Signed-off-by: David Suarez <david.suarez.fuentes@ericsson.com>
aaa-idmlight/pom.xml
aaa-idmlight/src/main/java/org/opendaylight/aaa/idm/IdmLightApplication.java
aaa-idmlight/src/main/java/org/opendaylight/aaa/idm/rest/DomainHandler.java
aaa-idmlight/src/main/java/org/opendaylight/aaa/idm/rest/RoleHandler.java
aaa-idmlight/src/main/java/org/opendaylight/aaa/idm/rest/UserHandler.java
aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/persistence/PasswordHashTest.java
aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/DomainHandlerTest.java
aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/HandlerTest.java
aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/IDMTestStore.java
aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/RoleHandlerTest.java
aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/UserHandlerTest.java

index 9f185594686bd8a199f0e80c16a72e857b3bafa9..71edf6a883678266be424d19aa8367bfce51649c 100644 (file)
 <?xml version="1.0" encoding="UTF-8"?>
 <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/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>org.opendaylight.aaa</groupId>
-        <artifactId>aaa-parent</artifactId>
-        <version>0.6.0-SNAPSHOT</version>
-        <relativePath>../parent</relativePath>
-    </parent>
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.aaa</groupId>
+    <artifactId>aaa-parent</artifactId>
+    <version>0.6.0-SNAPSHOT</version>
+    <relativePath>../parent</relativePath>
+  </parent>
 
-    <artifactId>aaa-idmlight</artifactId>
-    <name>ODL :: aaa :: ${project.artifactId}</name>
-    <packaging>bundle</packaging>
+  <artifactId>aaa-idmlight</artifactId>
+  <name>ODL :: aaa :: ${project.artifactId}</name>
+  <packaging>bundle</packaging>
 
-    <dependencies>
-        <!--Yang Binding -->
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>config-api</artifactId>
-            <version>${config.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-binding-config</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-binding-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-common-util</artifactId>
-        </dependency>
+  <dependencies>
+    <!--Yang Binding -->
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>config-api</artifactId>
+      <version>${config.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-config</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-common-util</artifactId>
+    </dependency>
 
-        <dependency>
-            <groupId>org.opendaylight.aaa</groupId>
-            <artifactId>aaa-authn-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.aaa</groupId>
-            <artifactId>aaa-shiro</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.aaa</groupId>
-            <artifactId>aaa-authn</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.aaa</groupId>
-            <artifactId>aaa-filterchain</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.sun.jersey</groupId>
-            <artifactId>jersey-server</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>javax.servlet-api</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.dependencymanager</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-core</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
+    <dependency>
+      <groupId>org.opendaylight.aaa</groupId>
+      <artifactId>aaa-authn-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.aaa</groupId>
+      <artifactId>aaa-shiro</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.aaa</groupId>
+      <artifactId>aaa-authn</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.aaa</groupId>
+      <artifactId>aaa-filterchain</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.sun.jersey</groupId>
+      <artifactId>jersey-server</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>javax.servlet-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.dependencymanager</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+    </dependency>
 
-        <!-- JSON JAXB Stuff -->
-        <dependency>
-            <groupId>com.fasterxml.jackson.core</groupId>
-            <artifactId>jackson-core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.core</groupId>
-            <artifactId>jackson-annotations</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.core</groupId>
-            <artifactId>jackson-databind</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.datatype</groupId>
-            <artifactId>jackson-datatype-json-org</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.jaxrs</groupId>
-            <artifactId>jackson-jaxrs-base</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.jaxrs</groupId>
-            <artifactId>jackson-jaxrs-json-provider</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.module</groupId>
-            <artifactId>jackson-module-jaxb-annotations</artifactId>
-        </dependency>
+    <!-- JSON JAXB Stuff -->
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-annotations</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-databind</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.datatype</groupId>
+      <artifactId>jackson-datatype-json-org</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.jaxrs</groupId>
+      <artifactId>jackson-jaxrs-base</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.jaxrs</groupId>
+      <artifactId>jackson-jaxrs-json-provider</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.module</groupId>
+      <artifactId>jackson-module-jaxb-annotations</artifactId>
+    </dependency>
 
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-servlets</artifactId>
-            <scope>provided</scope>
-        </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-servlets</artifactId>
+      <scope>provided</scope>
+    </dependency>
 
-        <!-- Testing Dependencies -->
-        <dependency>
-            <groupId>com.sun.jersey.jersey-test-framework</groupId>
-            <artifactId>jersey-test-framework-grizzly2</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>jul-to-slf4j</artifactId>
-            <version>1.7.21</version>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>attach-artifacts-idmtool</id>
-                        <goals>
-                            <goal>attach-artifact</goal>
-                        </goals>
-                        <phase>package</phase>
-                        <configuration>
-                            <artifacts>
-                                <artifact>
-                                    <file>${project.build.directory}/classes/idmtool.py</file>
-                                    <type>py</type>
-                                    <classifier>config</classifier>
-                                </artifact>
-                            </artifacts>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <!-- override default version so we don't use bnd 2.3.0 when embedding sqlite -->
-
-                <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-                        <Import-Package>
-                            com.google.*,
-                            com.sun.jersey.spi.container.servlet,
-                            javax.servlet.http,
-                            javax.ws.rs,javax.ws.rs.core,
-                            javax.xml.bind.annotation,
-                            org.xml.sax,
-                            org.apache.felix.dm,
-                            org.apache.shiro.web.env,org.apache.shiro.authc,
-                            org.eclipse.jetty.servlets;version="[8.1,10)",
-                            org.opendaylight.aaa,
-                            org.opendaylight.aaa.api.*,
-                            org.opendaylight.aaa.filterchain.filters,
-                            org.opendaylight.aaa.shiro.filters,
-                            org.opendaylight.aaa.shiro.realm,
-                            org.opendaylight.aaa.shiro.web.env,
-                            org.opendaylight.*,
-                            org.osgi.framework,
-                            org.osgi.util.tracker,
-                            org.slf4j,
-                        </Import-Package>
-                        <Web-ContextPath>/auth</Web-ContextPath>
-                        <!--<Web-Connectors>adminConn</Web-Connectors> -->
-                        <!--Bundle-Activator>org.opendaylight.aaa.idm.Activator</Bundle-Activator-->
-                    </instructions>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
+    <!-- Testing Dependencies -->
+    <dependency>
+      <groupId>com.sun.jersey.jersey-test-framework</groupId>
+      <artifactId>jersey-test-framework-grizzly2</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jul-to-slf4j</artifactId>
+      <version>1.7.21</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
 
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <configuration>
+          <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-artifacts-idmtool</id>
+            <goals>
+              <goal>attach-artifact</goal>
+            </goals>
+            <phase>package</phase>
+            <configuration>
+              <artifacts>
+                <artifact>
+                  <file>${project.build.directory}/classes/idmtool.py</file>
+                  <type>py</type>
+                  <classifier>config</classifier>
+                </artifact>
+              </artifacts>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <!-- override default version so we don't use bnd 2.3.0 when embedding sqlite -->
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>
+              com.google.*,
+              com.sun.jersey.spi.container.servlet,
+              javax.servlet.http,
+              javax.ws.rs,javax.ws.rs.core,
+              javax.xml.bind.annotation,
+              org.xml.sax,
+              org.apache.felix.dm,
+              org.apache.shiro.web.env,org.apache.shiro.authc,
+              org.eclipse.jetty.servlets;version="[8.1,10)",
+              org.opendaylight.aaa,
+              org.opendaylight.aaa.api.*,
+              org.opendaylight.aaa.filterchain.filters,
+              org.opendaylight.aaa.shiro.filters,
+              org.opendaylight.aaa.shiro.realm,
+              org.opendaylight.aaa.shiro.web.env,
+              org.opendaylight.*,
+              org.osgi.framework,
+              org.osgi.util.tracker,
+              org.slf4j,
+            </Import-Package>
+            <Web-ContextPath>/auth</Web-ContextPath>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 </project>
index d7c2003364b5e40a0b078d1a13baf30019af4164..7c3f973a944047c26481236123e12f587feb4237 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
+ * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -19,15 +19,16 @@ import org.opendaylight.aaa.idm.rest.RoleHandler;
 import org.opendaylight.aaa.idm.rest.UserHandler;
 
 /**
- * A JAX-RS application for IdmLight.  The REST endpoints delivered by this
- * application are in the form:
- * <code>http://{HOST}:{PORT}/auth/v1/</code>
+ * A JAX-RS application for IdmLight. The REST endpoints delivered by this
+ * application are in the form: <code>http://{HOST}:{PORT}/auth/v1/</code>
  *
+ * <p>
  * For example, the users REST endpoint is:
  * <code>http://{HOST}:{PORT}/auth/v1/users</code>
  *
- * This application is responsible for interaction with the backing h2
- * database store.
+ * <p>
+ * This application is responsible for interaction with the backing h2 database
+ * store.
  *
  * @author liemmn
  * @author Ryan Goulding (ryandgoulding@gmail.com)
@@ -36,20 +37,18 @@ import org.opendaylight.aaa.idm.rest.UserHandler;
  * @see <code>org.opendaylight.aaa.idm.rest.RoleHandler</code>
  */
 public class IdmLightApplication extends Application {
-
-    //TODO create a bug to address the fact that the implementation assumes 128
+    // TODO create a bug to address the fact that the implementation assumes 128
     // as the max length, even though this claims 256.
     /**
      * The maximum field length for identity fields.
      */
     public static final int MAX_FIELD_LEN = 256;
+
     public IdmLightApplication() {
     }
 
     @Override
     public Set<Class<?>> getClasses() {
-        return new HashSet<Class<?>>(Arrays.asList(DomainHandler.class,
-                                                   RoleHandler.class,
-                                                   UserHandler.class));
+        return new HashSet<>(Arrays.asList(DomainHandler.class, RoleHandler.class, UserHandler.class));
     }
 }
index 1da7beaed76ec5f6090087edfe9ae5b784b2d449..827e4d45e761f0ef906b38b1d727ef2520de8068 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
+ * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -42,7 +42,9 @@ import org.slf4j.LoggerFactory;
  * REST application used to manipulate the H2 database domains table. The REST
  * endpoint is <code>/auth/v1/domains</code>.
  *
- * A wrapper script called <code>idmtool</code> is provided to manipulate AAA data.
+ * <p>
+ * A wrapper script called <code>idmtool</code> is provided to manipulate AAA
+ * data.
  *
  * @author peter.mellquist@hp.com
  * @author Ryan Goulding (ryandgoulding@gmail.com)
@@ -64,11 +66,11 @@ public class DomainHandler {
         Domains domains = null;
         try {
             domains = AAAIDMLightModule.getStore().getDomains();
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting domains");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         return Response.ok(domains).build();
@@ -77,7 +79,8 @@ public class DomainHandler {
     /**
      * Extracts the domain represented by <code>domainId</code>.
      *
-     * @param domainId the string domain (i.e., "sdn")
+     * @param domainId
+     *            the string domain (i.e., "sdn")
      * @return a response with the specified domain
      */
     @GET
@@ -88,11 +91,11 @@ public class DomainHandler {
         Domain domain = null;
         try {
             domain = AAAIDMLightModule.getStore().readDomain(domainId);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting domain");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
 
@@ -105,14 +108,15 @@ public class DomainHandler {
     }
 
     /**
-     * Creates a domain.  The name attribute is required for domain creation.
-     * Enabled and description fields are optional.  Optional fields default
-     * in the following manner:
-     * <code>enabled</code>: <code>false</code>
+     * Creates a domain. The name attribute is required for domain creation.
+     * Enabled and description fields are optional. Optional fields default in
+     * the following manner: <code>enabled</code>: <code>false</code>
      * <code>description</code>: An empty string (<code>""</code>).
      *
-     * @param info passed from Jersey
-     * @param domain designated by the REST payload
+     * @param info
+     *            passed from Jersey
+     * @param domain
+     *            designated by the REST payload
      * @return A response stating success or failure of domain creation.
      */
     @POST
@@ -121,10 +125,10 @@ public class DomainHandler {
     public Response createDomain(@Context UriInfo info, Domain domain) {
         LOG.info("Post /domains");
         try {
-            // Bug 8382:  domain id is an implementation detail and isn't specifiable
+            // Bug 8382: domain id is an implementation detail and isn't
+            // specifiable
             if (domain.getDomainid() != null) {
-                final String errorMessage =
-                        "do not specify domainId, it will be assigned automatically for you";
+                final String errorMessage = "do not specify domainId, it will be assigned automatically for you";
                 LOG.debug(errorMessage);
                 final IDMError idmError = new IDMError();
                 idmError.setMessage(errorMessage);
@@ -140,11 +144,11 @@ public class DomainHandler {
                 domain.setDescription("");
             }
             domain = AAAIDMLightModule.getStore().writeDomain(domain);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error creating domain");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         return Response.status(201).entity(domain).build();
@@ -153,9 +157,12 @@ public class DomainHandler {
     /**
      * Updates a domain.
      *
-     * @param info passed from Jersey
-     * @param domain the REST payload
-     * @param domainId the last part of the path, containing the specified domain id
+     * @param info
+     *            passed from Jersey
+     * @param domain
+     *            the REST payload
+     * @param domainId
+     *            the last part of the path, containing the specified domain id
      * @return A response stating success or failure of domain update.
      */
     @PUT
@@ -169,16 +176,16 @@ public class DomainHandler {
             domain = AAAIDMLightModule.getStore().updateDomain(domain);
             if (domain == null) {
                 IDMError idmerror = new IDMError();
-                idmerror.setMessage("Not found! Domain id :" + domainId);
+                idmerror.setMessage("Not found! Domain id:" + domainId);
                 return Response.status(404).entity(idmerror).build();
             }
             IdmLightProxy.clearClaimCache();
             return Response.status(200).entity(domain).build();
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error putting domain");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
     }
@@ -186,8 +193,10 @@ public class DomainHandler {
     /**
      * Deletes a domain.
      *
-     * @param info passed from Jersey
-     * @param domainId the last part of the path, containing the specified domain id
+     * @param info
+     *            passed from Jersey
+     * @param domainId
+     *            the last part of the path, containing the specified domain id
      * @return A response stating success or failure of domain deletion.
      */
     @DELETE
@@ -199,14 +208,14 @@ public class DomainHandler {
             Domain domain = AAAIDMLightModule.getStore().deleteDomain(domainId);
             if (domain == null) {
                 IDMError idmerror = new IDMError();
-                idmerror.setMessage("Not found! Domain id :" + domainId);
+                idmerror.setMessage("Not found! Domain id:" + domainId);
                 return Response.status(404).entity(idmerror).build();
             }
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error deleting Domain");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         IdmLightProxy.clearClaimCache();
@@ -214,15 +223,19 @@ public class DomainHandler {
     }
 
     /**
-     * Creates a grant.  A grant defines the role a particular user is given on
-     * a particular domain.  For example, by default, AAA installs a grant for
-     * the "admin" user, granting permission to act with "admin" role on the
-     * "sdn" domain.
+     * Creates a grant. A grant defines the role a particular user is given on a
+     * particular domain. For example, by default, AAA installs a grant for the
+     * "admin" user, granting permission to act with "admin" role on the "sdn"
+     * domain.
      *
-     * @param info passed from Jersey
-     * @param domainId the domain the user is allowed to access
-     * @param userId the user that is allowed to access the domain
-     * @param grant the payload containing role access controls
+     * @param info
+     *            passed from Jersey
+     * @param domainId
+     *            the domain the user is allowed to access
+     * @param userId
+     *            the user that is allowed to access the domain
+     * @param grant
+     *            the payload containing role access controls
      * @return A response stating success or failure of grant creation.
      */
     @POST
@@ -233,10 +246,9 @@ public class DomainHandler {
             @PathParam("uid") String userId, Grant grant) {
         LOG.info("Post /domains/{}/users/{}/roles", domainId, userId);
 
-        // Bug 8382:  grant id is an implementation detail and isn't specifiable
+        // Bug 8382: grant id is an implementation detail and isn't specifiable
         if (grant.getGrantid() != null) {
-            final String errorMessage =
-                    "do not specify grantId, it will be assigned automatically for you";
+            final String errorMessage = "do not specify grantId, it will be assigned automatically for you";
             LOG.debug(errorMessage);
             final IDMError idmError = new IDMError();
             idmError.setMessage(errorMessage);
@@ -244,18 +256,18 @@ public class DomainHandler {
         }
 
         Domain domain = null;
-        User user = null;
-        Role role = null;
-        String roleId = null;
+        User user;
+        Role role;
+        String roleId;
 
         // validate domain id
         try {
             domain = AAAIDMLightModule.getStore().readDomain(domainId);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting domain");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         if (domain == null) {
@@ -267,16 +279,16 @@ public class DomainHandler {
 
         try {
             user = AAAIDMLightModule.getStore().readUser(userId);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting user");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         if (user == null) {
             IDMError idmerror = new IDMError();
-            idmerror.setMessage("Not found! User id :" + userId);
+            idmerror.setMessage("Not found! User id:" + userId);
             return Response.status(404).entity(idmerror).build();
         }
         grant.setUserid(userId);
@@ -287,21 +299,21 @@ public class DomainHandler {
             LOG.info("roleid = {}", roleId);
         } catch (NumberFormatException nfe) {
             IDMError idmerror = new IDMError();
-            idmerror.setMessage("Invalid Role id :" + grant.getRoleid());
+            idmerror.setMessage("Invalid Role id:" + grant.getRoleid());
             return Response.status(404).entity(idmerror).build();
         }
         try {
             role = AAAIDMLightModule.getStore().readRole(roleId);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting role");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         if (role == null) {
             IDMError idmerror = new IDMError();
-            idmerror.setMessage("Not found! role :" + grant.getRoleid());
+            idmerror.setMessage("Not found! role:" + grant.getRoleid());
             return Response.status(404).entity(idmerror).build();
         }
 
@@ -310,26 +322,25 @@ public class DomainHandler {
             Grant existingGrant = AAAIDMLightModule.getStore().readGrant(domainId, userId, roleId);
             if (existingGrant != null) {
                 IDMError idmerror = new IDMError();
-                idmerror.setMessage("Grant already exists for did:" + domainId + " uid:" + userId
-                        + " rid:" + roleId);
+                idmerror.setMessage("Grant already exists for did:" + domainId + " uid:" + userId + " rid:" + roleId);
                 return Response.status(403).entity(idmerror).build();
             }
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error creating grant");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
 
         // create grant
         try {
             grant = AAAIDMLightModule.getStore().writeGrant(grant);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException: ", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error creating grant");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
 
@@ -340,22 +351,23 @@ public class DomainHandler {
     /**
      * Used to validate user access.
      *
-     * @param info passed from Jersey
-     * @param domainId the domain in question
-     * @param userpwd the password attempt
+     * @param info
+     *            passed from Jersey
+     * @param domainId
+     *            the domain in question
+     * @param userpwd
+     *            the password attempt
      * @return A response stating success or failure of user validation.
      */
     @POST
     @Path("/{did}/users/roles")
     @Consumes("application/json")
     @Produces("application/json")
-    public Response validateUser(@Context UriInfo info, @PathParam("did") String domainId,
-            UserPwd userpwd) {
-
+    public Response validateUser(@Context UriInfo info, @PathParam("did") String domainId, UserPwd userpwd) {
         LOG.info("GET /domains/{}/users", domainId);
         Domain domain = null;
         Claim claim = new Claim();
-        List<Role> roleList = new ArrayList<Role>();
+        List<Role> roleList = new ArrayList<>();
 
         try {
             domain = AAAIDMLightModule.getStore().readDomain(domainId);
@@ -368,7 +380,7 @@ public class DomainHandler {
         }
         if (domain == null) {
             IDMError idmerror = new IDMError();
-            idmerror.setMessage("Not found! Domain id :" + domainId);
+            idmerror.setMessage("Not found! Domain id:" + domainId);
             return Response.status(404).entity(idmerror).build();
         }
 
@@ -414,19 +426,19 @@ public class DomainHandler {
                     Role role = AAAIDMLightModule.getStore().readRole(grant.getRoleid());
                     roleList.add(role);
                 }
-            } catch (IDMStoreException se) {
-                LOG.error("StoreException: ", se);
+            } catch (IDMStoreException e) {
+                LOG.error("StoreException", e);
                 IDMError idmerror = new IDMError();
                 idmerror.setMessage("Internal error getting Roles");
-                idmerror.setDetails(se.getMessage());
+                idmerror.setDetails(e.getMessage());
                 return Response.status(500).entity(idmerror).build();
             }
             claim.setRoles(roleList);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting user");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
 
@@ -436,9 +448,12 @@ public class DomainHandler {
     /**
      * Get the grants for a user on a domain.
      *
-     * @param info passed from Jersey
-     * @param domainId the domain in question
-     * @param userId the user in question
+     * @param info
+     *            passed from Jersey
+     * @param domainId
+     *            the domain in question
+     * @param userId
+     *            the user in question
      * @return A response containing the grants for a user on a domain.
      */
     @GET
@@ -448,37 +463,36 @@ public class DomainHandler {
             @PathParam("uid") String userId) {
         LOG.info("GET /domains/{}/users/{}/roles", domainId, userId);
         Domain domain = null;
-        User user = null;
-        Roles roles = new Roles();
-        List<Role> roleList = new ArrayList<Role>();
+        User user;
+        List<Role> roleList = new ArrayList<>();
 
         try {
             domain = AAAIDMLightModule.getStore().readDomain(domainId);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting domain");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         if (domain == null) {
             IDMError idmerror = new IDMError();
-            idmerror.setMessage("Not found! Domain id :" + domainId);
+            idmerror.setMessage("Not found! Domain id:" + domainId);
             return Response.status(404).entity(idmerror).build();
         }
 
         try {
             user = AAAIDMLightModule.getStore().readUser(userId);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting user");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         if (user == null) {
             IDMError idmerror = new IDMError();
-            idmerror.setMessage("Not found! User id :" + userId);
+            idmerror.setMessage("Not found! User id:" + userId);
             return Response.status(404).entity(idmerror).build();
         }
 
@@ -490,14 +504,14 @@ public class DomainHandler {
                 Role role = AAAIDMLightModule.getStore().readRole(grant.getRoleid());
                 roleList.add(role);
             }
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting Roles");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
-
+        Roles roles = new Roles();
         roles.setRoles(roleList);
         return Response.ok(roles).build();
     }
@@ -505,10 +519,14 @@ public class DomainHandler {
     /**
      * Delete a grant.
      *
-     * @param info passed from Jersey
-     * @param domainId the domain for the grant
-     * @param userId the user for the grant
-     * @param roleId the role for the grant
+     * @param info
+     *            passed from Jersey
+     * @param domainId
+     *            the domain for the grant
+     * @param userId
+     *            the user for the grant
+     * @param roleId
+     *            the role for the grant
      * @return A response stating success or failure of the grant deletion.
      */
     @DELETE
@@ -516,51 +534,51 @@ public class DomainHandler {
     public Response deleteGrant(@Context UriInfo info, @PathParam("did") String domainId,
             @PathParam("uid") String userId, @PathParam("rid") String roleId) {
         Domain domain = null;
-        User user = null;
-        Role role = null;
+        User user;
+        Role role;
 
         try {
             domain = AAAIDMLightModule.getStore().readDomain(domainId);
-        } catch (IDMStoreException se) {
-            LOG.error("Error deleting Grant  : ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("Error deleting Grant", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting domain");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         if (domain == null) {
             IDMError idmerror = new IDMError();
-            idmerror.setMessage("Not found! Domain id :" + domainId);
+            idmerror.setMessage("Not found! Domain id:" + domainId);
             return Response.status(404).entity(idmerror).build();
         }
 
         try {
             user = AAAIDMLightModule.getStore().readUser(userId);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException : ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting user");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         if (user == null) {
             IDMError idmerror = new IDMError();
-            idmerror.setMessage("Not found! User id :" + userId);
+            idmerror.setMessage("Not found! User id:" + userId);
             return Response.status(404).entity(idmerror).build();
         }
 
         try {
             role = AAAIDMLightModule.getStore().readRole(roleId);
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error getting Role");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         if (role == null) {
             IDMError idmerror = new IDMError();
-            idmerror.setMessage("Not found! Role id :" + roleId);
+            idmerror.setMessage("Not found! Role id:" + roleId);
             return Response.status(404).entity(idmerror).build();
         }
 
@@ -569,20 +587,18 @@ public class DomainHandler {
             Grant existingGrant = AAAIDMLightModule.getStore().readGrant(domainId, userId, roleId);
             if (existingGrant == null) {
                 IDMError idmerror = new IDMError();
-                idmerror.setMessage("Grant does not exist for did:" + domainId + " uid:" + userId
-                        + " rid:" + roleId);
+                idmerror.setMessage("Grant does not exist for did:" + domainId + " uid:" + userId + " rid:" + roleId);
                 return Response.status(404).entity(idmerror).build();
             }
             existingGrant = AAAIDMLightModule.getStore().deleteGrant(existingGrant.getGrantid());
-        } catch (IDMStoreException se) {
-            LOG.error("StoreException: ", se);
+        } catch (IDMStoreException e) {
+            LOG.error("StoreException", e);
             IDMError idmerror = new IDMError();
             idmerror.setMessage("Internal error creating grant");
-            idmerror.setDetails(se.getMessage());
+            idmerror.setDetails(e.getMessage());
             return Response.status(500).entity(idmerror).build();
         }
         IdmLightProxy.clearClaimCache();
         return Response.status(204).build();
     }
-
 }
index 24734b79d54a05f9b856d8813db9501a9a69b4f9..22374f818893bf163f09a926ab250cc6c31ba7a9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
+ * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -34,7 +34,9 @@ import org.slf4j.LoggerFactory;
  * REST application used to manipulate the H2 database roles table. The REST
  * endpoint is <code>/auth/v1/roles</code>.
  *
- * A wrapper script called <code>idmtool</code> is provided to manipulate AAA data.
+ * <p>
+ * A wrapper script called <code>idmtool</code> is provided to manipulate AAA
+ * data.
  *
  * @author peter.mellquist@hp.com
  * @author Ryan Goulding (ryandgoulding@gmail.com)
@@ -46,7 +48,8 @@ public class RoleHandler {
     /**
      * Extracts all roles.
      *
-     * @return A response with all roles in the H2 database, or internal error if one is encountered
+     * @return A response with all roles in the H2 database, or internal error
+     *         if one is encountered
      */
     @GET
     @Produces("application/json")
@@ -55,17 +58,20 @@ public class RoleHandler {
         Roles roles = null;
         try {
             roles = AAAIDMLightModule.getStore().getRoles();
-        } catch (IDMStoreException se) {
-            return new IDMError(500, "internal error getting roles", se.getMessage()).response();
+        } catch (IDMStoreException e) {
+            LOG.error("Internal error getting the roles", e);
+            return new IDMError(500, "internal error getting roles", e.getMessage()).response();
         }
         return Response.ok(roles).build();
     }
 
     /**
-     * Extract a specific role identified by <code>id</code>
+     * Extract a specific role identified by <code>id</code>.
      *
-     * @param id the String id for the role
-     * @return A response with the role identified by <code>id</code>, or internal error if one is encountered
+     * @param id
+     *            the String id for the role
+     * @return A response with the role identified by <code>id</code>, or
+     *         internal error if one is encountered
      */
     @GET
     @Path("/{id}")
@@ -76,12 +82,13 @@ public class RoleHandler {
 
         try {
             role = AAAIDMLightModule.getStore().readRole(id);
-        } catch (IDMStoreException se) {
-            return new IDMError(500, "internal error getting roles", se.getMessage()).response();
+        } catch (IDMStoreException e) {
+            LOG.error("Internal error getting the role", e);
+            return new IDMError(500, "internal error getting roles", e.getMessage()).response();
         }
 
         if (role == null) {
-            return new IDMError(404, "role not found id :" + id, "").response();
+            return new IDMError(404, "role not found id:" + id, "").response();
         }
         return Response.ok(role).build();
     }
@@ -89,9 +96,12 @@ public class RoleHandler {
     /**
      * Creates a role.
      *
-     * @param info passed from Jersey
-     * @param role the role JSON payload
-     * @return A response stating success or failure of role creation, or internal error if one is encountered
+     * @param info
+     *            passed from Jersey
+     * @param role
+     *            the role JSON payload
+     * @return A response stating success or failure of role creation, or
+     *         internal error if one is encountered
      */
     @POST
     @Consumes("application/json")
@@ -100,10 +110,10 @@ public class RoleHandler {
         LOG.info("Post /roles");
         try {
 
-            // Bug 8382:  role id is an implementation detail and isn't specifiable
+            // Bug 8382: role id is an implementation detail and isn't
+            // specifiable
             if (role.getRoleid() != null) {
-                final String errorMessage =
-                        "do not specify roleId, it will be assigned automatically for you";
+                final String errorMessage = "do not specify roleId, it will be assigned automatically for you";
                 LOG.debug(errorMessage);
                 final IDMError idmError = new IDMError();
                 idmError.setMessage(errorMessage);
@@ -115,43 +125,46 @@ public class RoleHandler {
             if (role.getName() == null) {
                 return new IDMError(404, "name must be defined on role create", "").response();
             } else if (role.getName().length() > IdmLightApplication.MAX_FIELD_LEN) {
-                return new IDMError(400, "role name max length is :"
-                        + IdmLightApplication.MAX_FIELD_LEN, "").response();
+                return new IDMError(400, "role name max length is :" + IdmLightApplication.MAX_FIELD_LEN, "")
+                        .response();
             }
 
             // domain
             if (role.getDomainid() == null) {
-                return new IDMError(404,
-                        "The role's domain must be defined on role when creating a role.", "")
+                return new IDMError(404, "The role's domain must be defined on role when creating a role.", "")
                         .response();
             } else if (role.getDomainid().length() > IdmLightApplication.MAX_FIELD_LEN) {
-                return new IDMError(400, "role domain max length is :"
-                        + IdmLightApplication.MAX_FIELD_LEN, "").response();
+                return new IDMError(400, "role domain max length is :" + IdmLightApplication.MAX_FIELD_LEN, "")
+                        .response();
             }
 
             // description
             if (role.getDescription() == null) {
                 role.setDescription("");
             } else if (role.getDescription().length() > IdmLightApplication.MAX_FIELD_LEN) {
-                return new IDMError(400, "role description max length is :"
-                        + IdmLightApplication.MAX_FIELD_LEN, "").response();
+                return new IDMError(400, "role description max length is :" + IdmLightApplication.MAX_FIELD_LEN, "")
+                        .response();
             }
 
             role = AAAIDMLightModule.getStore().writeRole(role);
-        } catch (IDMStoreException se) {
-            return new IDMError(500, "internal error creating role", se.getMessage()).response();
+        } catch (IDMStoreException e) {
+            LOG.error("Internal error creating role", e);
+            return new IDMError(500, "internal error creating role", e.getMessage()).response();
         }
-
         return Response.status(201).entity(role).build();
     }
 
     /**
      * Updates a specific role identified by <code>id</code>.
      *
-     * @param info passed from Jersey
-     * @param role the role JSON payload
-     * @param id the String id for the role
-     * @return A response stating success or failure of role update, or internal error if one occurs
+     * @param info
+     *            passed from Jersey
+     * @param role
+     *            the role JSON payload
+     * @param id
+     *            the String id for the role
+     * @return A response stating success or failure of role update, or internal
+     *         error if one occurs
      */
     @PUT
     @Path("/{id}")
@@ -165,17 +178,16 @@ public class RoleHandler {
 
             // name
             // TODO: names should be unique
-            if ((role.getName() != null)
-                    && (role.getName().length() > IdmLightApplication.MAX_FIELD_LEN)) {
-                return new IDMError(400, "role name max length is :"
-                        + IdmLightApplication.MAX_FIELD_LEN, "").response();
+            if ((role.getName() != null) && (role.getName().length() > IdmLightApplication.MAX_FIELD_LEN)) {
+                return new IDMError(400, "role name max length is :" + IdmLightApplication.MAX_FIELD_LEN, "")
+                        .response();
             }
 
             // description
             if ((role.getDescription() != null)
                     && (role.getDescription().length() > IdmLightApplication.MAX_FIELD_LEN)) {
-                return new IDMError(400, "role description max length is :"
-                        + IdmLightApplication.MAX_FIELD_LEN, "").response();
+                return new IDMError(400, "role description max length is :" + IdmLightApplication.MAX_FIELD_LEN, "")
+                        .response();
             }
 
             role = AAAIDMLightModule.getStore().updateRole(role);
@@ -184,17 +196,21 @@ public class RoleHandler {
             }
             IdmLightProxy.clearClaimCache();
             return Response.status(200).entity(role).build();
-        } catch (IDMStoreException se) {
-            return new IDMError(500, "internal error putting role", se.getMessage()).response();
+        } catch (IDMStoreException e) {
+            LOG.error("Internal error putting role", e);
+            return new IDMError(500, "internal error putting role", e.getMessage()).response();
         }
     }
 
     /**
      * Delete a role.
      *
-     * @param info passed from Jersey
-     * @param id the String id for the role
-     * @return A response stating success or failure of user deletion, or internal error if one occurs
+     * @param info
+     *            passed from Jersey
+     * @param id
+     *            the String id for the role
+     * @return A response stating success or failure of user deletion, or
+     *         internal error if one occurs
      */
     @DELETE
     @Path("/{id}")
@@ -206,11 +222,11 @@ public class RoleHandler {
             if (role == null) {
                 return new IDMError(404, "role id not found :" + id, "").response();
             }
-        } catch (IDMStoreException se) {
-            return new IDMError(500, "internal error deleting role", se.getMessage()).response();
+        } catch (IDMStoreException e) {
+            LOG.error("Internal error deleting role", e);
+            return new IDMError(500, "internal error deleting role", e.getMessage()).response();
         }
         IdmLightProxy.clearClaimCache();
         return Response.status(204).build();
     }
-
 }
index 02fc7b60f88913572582ecb0328daae95ed2d7e1..7abe5ce74e3e4d6f509393eaa961c45d4f2e9fa3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
+ * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -36,7 +36,9 @@ import org.slf4j.LoggerFactory;
  * REST application used to manipulate the H2 database users table. The REST
  * endpoint is <code>/auth/v1/users</code>.
  *
- * A wrapper script called <code>idmtool</code> is provided to manipulate AAA data.
+ * <p>
+ * A wrapper script called <code>idmtool</code> is provided to manipulate AAA
+ * data.
  *
  * @author peter.mellquist@hp.com
  * @author Ryan Goulding (ryandgoulding@gmail.com)
@@ -51,7 +53,7 @@ public class UserHandler {
      * endpoint without a password, the default password is assigned to the
      * user.
      */
-    private final static String DEFAULT_PWD = "changeme";
+    private static final String DEFAULT_PWD = "changeme";
 
     /**
      * When an HTTP GET is performed on <code>/auth/v1/users</code>, the
@@ -108,8 +110,10 @@ public class UserHandler {
      * Extracts the user represented by <code>id</code>. The password and salt
      * fields are redacted for security reasons.
      *
-     * @param id the unique id of representing the user account
-     * @return A response with the user information, or internal error if one occurs
+     * @param id
+     *            the unique id of representing the user account
+     * @return A response with the user information, or internal error if one
+     *         occurs
      */
     @GET
     @Path("/{id}")
@@ -143,11 +147,14 @@ public class UserHandler {
      * <code>password</code>: <code>changeme</code> <code>enabled</code>:
      * <code>true</code>
      *
+     * <p>
      * If a password is not provided, please ensure you change the default
      * password ASAP for security reasons!
      *
-     * @param info passed from Jersey
-     * @param user the user defined in the JSON payload
+     * @param info
+     *            passed from Jersey
+     * @param user
+     *            the user defined in the JSON payload
      * @return A response stating success or failure of user creation
      */
     @POST
@@ -156,10 +163,9 @@ public class UserHandler {
     public Response createUser(@Context UriInfo info, User user) {
         LOG.info("POST /auth/v1/users  (create a user with the specified payload");
 
-        // Bug 8382:  user id is an implementation detail and isn't specifiable
+        // Bug 8382: user id is an implementation detail and isn't specifiable
         if (user.getUserid() != null) {
-            final String errorMessage =
-                    "do not specify userId, it will be assigned automatically for you";
+            final String errorMessage = "do not specify userId, it will be assigned automatically for you";
             LOG.debug(errorMessage);
             final IDMError idmError = new IDMError();
             idmError.setMessage(errorMessage);
@@ -212,7 +218,7 @@ public class UserHandler {
         }
         // TODO add a check on email format here.
 
-        // The "password" field is optional and defautls to "changeme".
+        // The "password" field is optional and defaults to "changeme".
         final String userPassword = user.getPassword();
         if (userPassword == null) {
             user.setPassword(DEFAULT_PWD);
@@ -239,9 +245,12 @@ public class UserHandler {
     /**
      * REST endpoint to update a user account.
      *
-     * @param info passed from Jersey
-     * @param user the user defined in the JSON payload
-     * @param id the unique id for the user that will be updated
+     * @param info
+     *            passed from Jersey
+     * @param user
+     *            the user defined in the JSON payload
+     * @param id
+     *            the unique id for the user that will be updated
      * @return A response stating success or failure of the user update
      */
     @PUT
@@ -293,8 +302,10 @@ public class UserHandler {
     /**
      * REST endpoint to delete a user account.
      *
-     * @param info passed from Jersey
-     * @param id the unique id of the user which is being deleted
+     * @param info
+     *            passed from Jersey
+     * @param id
+     *            the unique id of the user which is being deleted
      * @return A response stating success or failure of user deletion
      */
     @DELETE
@@ -306,10 +317,8 @@ public class UserHandler {
             final User user = AAAIDMLightModule.getStore().deleteUser(id);
 
             if (user == null) {
-                return new IDMError(404,
-                        String.format("Error deleting user.  " +
-                                      "Couldn't find user with id %s", id),
-                                      "").response();
+                return new IDMError(404, String.format("Error deleting user.  " + "Couldn't find user with id %s", id),
+                        "").response();
             }
         } catch (IDMStoreException se) {
             return internalError("deleting", se);
@@ -323,67 +332,70 @@ public class UserHandler {
     /**
      * Creates a <code>Response</code> related to an internal server error.
      *
-     * @param verbal such as "creating", "deleting", "updating"
-     * @param e The exception, which is propagated in the response
+     * @param verbal
+     *            such as "creating", "deleting", "updating"
+     * @param ex
+     *            The exception, which is propagated in the response
      * @return A response containing internal error with specific reasoning
      */
-    private Response internalError(final String verbal, final Exception e) {
-        LOG.error("There was an internal error {} the user", verbal, e);
-        return new IDMError(500,
-                String.format("There was an internal error %s the user", verbal),
-                e.getMessage()).response();
+    private Response internalError(final String verbal, final Exception ex) {
+        LOG.error("There was an internal error {} the user", verbal, ex);
+        return new IDMError(500, String.format("There was an internal error %s the user", verbal), ex.getMessage())
+                .response();
     }
 
     /**
      * Creates a <code>Response</code> related to the user not providing a
      * required field.
      *
-     * @param fieldName the name of the field which is missing
+     * @param fieldName
+     *            the name of the field which is missing
      * @return A response explaining that the request is missing a field
      */
     private Response missingRequiredField(final String fieldName) {
 
         return new IDMError(400,
-                String.format("%s is required to create the user account.  " +
-                              "Please provide a %s in your payload.", fieldName, fieldName),
-                              "").response();
+                String.format("%s is required to create the user account.  " + "Please provide a %s in your payload.",
+                        fieldName, fieldName),
+                "").response();
     }
 
     /**
      * Creates a <code>Response</code> related to the user providing a field
      * that is too long.
      *
-     * @param fieldName the name of the field that is too long
-     * @param maxFieldLength the maximum length of <code>fieldName</code>
+     * @param fieldName
+     *            the name of the field that is too long
+     * @param maxFieldLength
+     *            the maximum length of <code>fieldName</code>
      * @return A response containing the bad field and the maximum field length
      */
     private Response providedFieldTooLong(final String fieldName, final int maxFieldLength) {
-
-        return new IDMError(400,
-                getProvidedFieldTooLongMessage(fieldName, maxFieldLength),
-                "").response();
+        return new IDMError(400, getProvidedFieldTooLongMessage(fieldName, maxFieldLength), "").response();
     }
 
     /**
      * Creates the client-facing message related to the user providing a field
      * that is too long.
      *
-     * @param fieldName the name of the field that is too long
-     * @param maxFieldLength the maximum length of <code>fieldName</code>
-     * @return
+     * @param fieldName
+     *            the name of the field that is too long
+     * @param maxFieldLength
+     *            the maximum length of <code>fieldName</code>
+     * @return a response containing the too long field and its length
      */
-    private static String getProvidedFieldTooLongMessage(final String fieldName,
-            final int maxFieldLength) {
+    private static String getProvidedFieldTooLongMessage(final String fieldName, final int maxFieldLength) {
 
-        return String.format("The provided %s field is too long.  " +
-                             "The max length is %s.", fieldName, maxFieldLength);
+        return String.format("The provided %s field is too long.  " + "The max length is %s.", fieldName,
+                maxFieldLength);
     }
 
     /**
      * Prepares a user account for output by redacting the appropriate fields.
      * This method side-effects the <code>user</code> parameter.
      *
-     * @param user the user account which will have fields redacted
+     * @param user
+     *            the user account which will have fields redacted
      */
     private static void redactUserPasswordInfo(final User user) {
         user.setPassword(REDACTED_PASSWORD);
@@ -391,9 +403,10 @@ public class UserHandler {
     }
 
     /**
-     * Validate the input field length
+     * Validate the input field length.
      *
      * @param inputField
+     *            the field to check
      * @return true if input field bigger than the MAX_FIELD_LEN
      */
     private boolean checkInputFieldLength(final String inputField) {
index 44fadf7af72237fe4a5416b01b815cb404974c1d..9b58eb07ca2c09d5453a9f5633362290134223d9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -11,7 +11,6 @@ package org.opendaylight.aaa.idm.persistence;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -34,7 +33,7 @@ import org.opendaylight.yang.gen.v1.config.aaa.authn.idmlight.rev151204.AAAIDMLi
 public class PasswordHashTest {
 
     @Before
-    public void before() throws IDMStoreException{
+    public void before() throws IDMStoreException {
         IIDMStore store = Mockito.mock(IIDMStore.class);
         AAAIDMLightModule.setStore(store);
         Domain domain = new Domain();
@@ -42,36 +41,37 @@ public class PasswordHashTest {
         domain.setDomainid("sdn");
 
         Mockito.when(store.readDomain("sdn")).thenReturn(domain);
-        Creds c = new Creds();
-        Users users = new Users();
+        Creds creds = new Creds();
+
         User user = new User();
         user.setName("admin");
-        user.setUserid(c.username());
+        user.setUserid(creds.username());
         user.setDomainid("sdn");
         user.setSalt("ABCD");
-        user.setPassword(SHA256Calculator.getSHA256(c.password(),user.getSalt()));
+        user.setPassword(SHA256Calculator.getSHA256(creds.password(), user.getSalt()));
         List<User> lu = new LinkedList<>();
         lu.add(user);
+        Users users = new Users();
         users.setUsers(lu);
 
-        Grants grants = new Grants();
         Grant grant = new Grant();
-        List<Grant> g = new ArrayList<>();
-        g.add(grant);
+        List<Grant> listOfGrants = new ArrayList<>();
+        listOfGrants.add(grant);
         grant.setDomainid("sdn");
         grant.setRoleid("admin");
         grant.setUserid("admin");
-        grants.setGrants(g);
+        Grants grants = new Grants();
+        grants.setGrants(listOfGrants);
         Role role = new Role();
         role.setRoleid("admin");
         role.setName("admin");
         Mockito.when(store.readRole("admin")).thenReturn(role);
-        Mockito.when(store.getUsers(c.username(), c.domain())).thenReturn(users);
-        Mockito.when(store.getGrants(c.domain(), c.username())).thenReturn(grants);
+        Mockito.when(store.getUsers(creds.username(), creds.domain())).thenReturn(users);
+        Mockito.when(store.getGrants(creds.domain(), creds.username())).thenReturn(grants);
     }
 
     @Test
-    public void testPasswordHash(){
+    public void testPasswordHash() {
         IdmLightProxy proxy = new IdmLightProxy();
         proxy.authenticate(new Creds());
     }
@@ -81,10 +81,12 @@ public class PasswordHashTest {
         public String username() {
             return "admin";
         }
+
         @Override
         public String password() {
             return "admin";
         }
+
         @Override
         public String domain() {
             return "sdn";
index 60483b4eace89874d9b3f94bdbe11c50ea8bd812..5db25f9de99b6c825a682e6121de121ac77c55a3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Inocybe Technologies and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.UniformInterfaceException;
 import java.util.HashMap;
@@ -23,22 +24,22 @@ import org.opendaylight.aaa.api.model.Domains;
 import org.opendaylight.aaa.api.model.IDMError;
 import org.opendaylight.aaa.api.model.Roles;
 
-public class DomainHandlerTest extends HandlerTest{
+public class DomainHandlerTest extends HandlerTest {
 
     @Test
     public void testDomainHandler() {
-        //check default domains
+        // check default domains
         Domains domains = resource().path("/v1/domains").get(Domains.class);
         assertNotNull(domains);
         assertEquals(1, domains.getDomains().size());
         assertTrue(domains.getDomains().get(0).getName().equals("sdn"));
 
-        //check existing domain
+        // check existing domain
         Domain domain = resource().path("/v1/domains/0").get(Domain.class);
         assertNotNull(domain);
         assertTrue(domain.getName().equals("sdn"));
 
-        //check not exist domain
+        // check not exist domain
         try {
             resource().path("/v1/domains/5").get(IDMError.class);
             fail("Should failed with 404!");
@@ -50,15 +51,17 @@ public class DomainHandlerTest extends HandlerTest{
 
         // check create domain
         Map<String, String> domainData = new HashMap<String, String>();
-        domainData.put("name","dom1");
-        domainData.put("description","test dom");
-        domainData.put("enabled","true");
-        ClientResponse clientResponse = resource().path("/v1/domains").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, domainData);
+        domainData.put("name", "dom1");
+        domainData.put("description", "test dom");
+        domainData.put("enabled", "true");
+        ClientResponse clientResponse = resource().path("/v1/domains").type(MediaType.APPLICATION_JSON)
+                .post(ClientResponse.class, domainData);
         assertEquals(201, clientResponse.getStatus());
 
         // check update domain data
-        domainData.put("name","dom1Update");
-        clientResponse = resource().path("/v1/domains/1").type(MediaType.APPLICATION_JSON).put(ClientResponse.class, domainData);
+        domainData.put("name", "dom1Update");
+        clientResponse = resource().path("/v1/domains/1").type(MediaType.APPLICATION_JSON).put(ClientResponse.class,
+                domainData);
         assertEquals(200, clientResponse.getStatus());
         domain = resource().path("/v1/domains/1").get(Domain.class);
         assertNotNull(domain);
@@ -66,28 +69,33 @@ public class DomainHandlerTest extends HandlerTest{
 
         // check create grant
         Map<String, String> grantData = new HashMap<String, String>();
-        grantData.put("roleid","1");
-        clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
+        grantData.put("roleid", "1");
+        clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON)
+                .post(ClientResponse.class, grantData);
         assertEquals(201, clientResponse.getStatus());
 
         // check create existing grant
-        clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
+        clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON)
+                .post(ClientResponse.class, grantData);
         assertEquals(403, clientResponse.getStatus());
 
         // check create grant with invalid domain id
-        clientResponse = resource().path("/v1/domains/5/users/0/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
+        clientResponse = resource().path("/v1/domains/5/users/0/roles").type(MediaType.APPLICATION_JSON)
+                .post(ClientResponse.class, grantData);
         assertEquals(404, clientResponse.getStatus());
 
         // check validate user (admin)
         Map<String, String> usrPwdData = new HashMap<String, String>();
-        usrPwdData.put("username","admin");
-        usrPwdData.put("userpwd","admin");
-        clientResponse = resource().path("/v1/domains/0/users/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrPwdData);
+        usrPwdData.put("username", "admin");
+        usrPwdData.put("userpwd", "admin");
+        clientResponse = resource().path("/v1/domains/0/users/roles").type(MediaType.APPLICATION_JSON)
+                .post(ClientResponse.class, usrPwdData);
         assertEquals(200, clientResponse.getStatus());
 
         // check validate user (admin) with wrong password
-        usrPwdData.put("userpwd","1234");
-        clientResponse = resource().path("/v1/domains/0/users/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrPwdData);
+        usrPwdData.put("userpwd", "1234");
+        clientResponse = resource().path("/v1/domains/0/users/roles").type(MediaType.APPLICATION_JSON)
+                .post(ClientResponse.class, usrPwdData);
         assertEquals(401, clientResponse.getStatus());
 
         // check get user (admin) roles
@@ -126,24 +134,22 @@ public class DomainHandlerTest extends HandlerTest{
             assertTrue(resp.getEntity(IDMError.class).getMessage().contains("Not found! Domain id"));
         }
 
-        // Bug 8382:  if a domain id is specified, 400 is returned
+        // Bug 8382: if a domain id is specified, 400 is returned
         domainData = new HashMap<>();
-        domainData.put("name","dom1");
-        domainData.put("description","test dom");
-        domainData.put("domainid","dom1");
-        domainData.put("enabled","true");
-        clientResponse = resource().path("/v1/domains").
-                type(MediaType.APPLICATION_JSON).
-                post(ClientResponse.class, domainData);
+        domainData.put("name", "dom1");
+        domainData.put("description", "test dom");
+        domainData.put("domainid", "dom1");
+        domainData.put("enabled", "true");
+        clientResponse = resource().path("/v1/domains").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
+                domainData);
         assertEquals(400, clientResponse.getStatus());
 
-        // Bug 8382:  if a grant id is specified, 400 is returned
+        // Bug 8382: if a grant id is specified, 400 is returned
         grantData = new HashMap<>();
-        grantData.put("roleid","1");
+        grantData.put("roleid", "1");
         grantData.put("grantid", "grantid");
-        clientResponse = resource().path("/v1/domains/1/users/0/roles").
-                type(MediaType.APPLICATION_JSON).
-                post(ClientResponse.class, grantData);
+        clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON)
+                .post(ClientResponse.class, grantData);
         assertEquals(400, clientResponse.getStatus());
     }
 }
index 770659f4e39135cef4d5035daeecaccab47eeac0..9c05ce28b0e911b95feeae5ea6ce4911300be21e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Inocybe Technologies and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -18,7 +18,6 @@ import org.opendaylight.aaa.idm.IdmLightApplication;
 import org.opendaylight.yang.gen.v1.config.aaa.authn.idmlight.rev151204.AAAIDMLightModule;
 import org.slf4j.bridge.SLF4JBridgeHandler;
 
-
 public abstract class HandlerTest extends JerseyTest {
 
     protected IDMTestStore testStore = new IDMTestStore();
@@ -26,10 +25,11 @@ public abstract class HandlerTest extends JerseyTest {
     @Override
     protected AppDescriptor configure() {
         return new WebAppDescriptor.Builder()
-                                   .initParam(WebComponent.RESOURCE_CONFIG_CLASS, IdmLightApplication.class.getName())
-                                   .initParam("com.sun.jersey.config.feature.Trace", "true")
-                                   .initParam("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter")
-                                   .build();
+                .initParam(WebComponent.RESOURCE_CONFIG_CLASS, IdmLightApplication.class.getName())
+                .initParam("com.sun.jersey.config.feature.Trace", "true")
+                .initParam("com.sun.jersey.spi.container.ContainerResponseFilters",
+                           "com.sun.jersey.api.container.filter.LoggingFilter")
+                .build();
     }
 
     @Before
index 5baad9903cc43d48d70699a93920c7a4d10a5e75..1ae581ebe32a02c1f77bfc0984652fc940a65c13 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Inocybe Technologies and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -10,7 +10,6 @@ package org.opendaylight.aaa.idm.rest.test;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import org.opendaylight.aaa.api.IDMStoreException;
 import org.opendaylight.aaa.api.IIDMStore;
 import org.opendaylight.aaa.api.model.Domain;
@@ -42,7 +41,7 @@ public class IDMTestStore implements IIDMStore {
 
     @Override
     public Domain readDomain(String domainid) throws IDMStoreException {
-        for(Domain dom : domains)  {
+        for (Domain dom : domains) {
             if (dom.getDomainid().equals(domainid)) {
                 return dom;
             }
@@ -52,7 +51,7 @@ public class IDMTestStore implements IIDMStore {
 
     @Override
     public Domain deleteDomain(String domainid) throws IDMStoreException {
-        for(Domain dom : domains)  {
+        for (Domain dom : domains) {
             if (dom.getDomainid().equals(domainid)) {
                 domains.remove(dom);
                 return dom;
@@ -63,7 +62,7 @@ public class IDMTestStore implements IIDMStore {
 
     @Override
     public Domain updateDomain(Domain domain) throws IDMStoreException {
-        for(Domain dom : domains)  {
+        for (Domain dom : domains) {
             if (dom.getDomainid().equals(domain.getDomainid())) {
                 domains.remove(dom);
                 domains.add(domain);
@@ -75,7 +74,7 @@ public class IDMTestStore implements IIDMStore {
 
     @Override
     public Domains getDomains() throws IDMStoreException {
-        Domains doms =  new Domains();
+        Domains doms = new Domains();
         doms.setDomains(domains);
         return doms;
     }
@@ -136,7 +135,7 @@ public class IDMTestStore implements IIDMStore {
 
     @Override
     public User readUser(String userid) throws IDMStoreException {
-        for(User usr : users) {
+        for (User usr : users) {
             if (usr.getUserid().equals(userid)) {
                 return usr;
             }
@@ -146,7 +145,7 @@ public class IDMTestStore implements IIDMStore {
 
     @Override
     public User deleteUser(String userid) throws IDMStoreException {
-        for(User usr : users) {
+        for (User usr : users) {
             if (usr.getUserid().equals(userid)) {
                 users.remove(usr);
                 return usr;
@@ -157,7 +156,7 @@ public class IDMTestStore implements IIDMStore {
 
     @Override
     public User updateUser(User user) throws IDMStoreException {
-        for(User usr : users) {
+        for (User usr : users) {
             if (usr.getUserid().equals(user.getUserid())) {
                 users.remove(usr);
                 users.add(user);
@@ -179,20 +178,21 @@ public class IDMTestStore implements IIDMStore {
         Users usrs = new Users();
         User user = null;
         Domain domain = null;
-        for(User usr : users) {
+        for (User usr : users) {
             if (usr.getName().equals(username)) {
                 user = usr;
                 break;
             }
         }
-        for(Domain dom : domains) {
+        for (Domain dom : domains) {
             if (dom.getDomainid().equals(domainId)) {
                 domain = dom;
                 break;
             }
         }
-        if (user == null || domain == null)
+        if (user == null || domain == null) {
             return usrs;
+        }
         for (Grant grant : grants) {
             if (grant.getUserid().equals(user.getUserid()) && grant.getDomainid().equals(domain.getDomainid())) {
                 List<User> usrList = new ArrayList<User>();
@@ -221,6 +221,17 @@ public class IDMTestStore implements IIDMStore {
         return null;
     }
 
+    @Override
+    public Grant readGrant(String domainid, String userid, String roleid) throws IDMStoreException {
+        for (Grant grant : grants) {
+            if (grant.getDomainid().equals(domainid) && grant.getUserid().equals(userid)
+                    && grant.getRoleid().equals(roleid)) {
+                return grant;
+            }
+        }
+        return null;
+    }
+
     @Override
     public Grant deleteGrant(String grantid) throws IDMStoreException {
         for (Grant grant : grants) {
@@ -258,16 +269,6 @@ public class IDMTestStore implements IIDMStore {
         return usrGrants;
     }
 
-    @Override
-    public Grant readGrant(String domainid, String userid, String roleid) throws IDMStoreException {
-        for (Grant grant : grants) {
-            if (grant.getDomainid().equals(domainid) && grant.getUserid().equals(userid) && grant.getRoleid().equals(roleid)) {
-                return grant;
-            }
-        }
-        return null;
-    }
-
     @Override
     public boolean isMainNodeInCluster() {
         return true;
index 2db408b6da159ae4b556ab9be513a93128740361..ab26a18f2ed6d61e53f969a422771318ba5c1640 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Inocybe Technologies and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.UniformInterfaceException;
 import java.util.HashMap;
@@ -23,12 +24,11 @@ import org.opendaylight.aaa.api.model.IDMError;
 import org.opendaylight.aaa.api.model.Role;
 import org.opendaylight.aaa.api.model.Roles;
 
-
-public class RoleHandlerTest extends HandlerTest{
+public class RoleHandlerTest extends HandlerTest {
 
     @Test
     public void testRoleHandler() {
-        //check default roles
+        // check default roles
         Roles roles = resource().path("/v1/roles").get(Roles.class);
         assertNotNull(roles);
         List<Role> roleList = roles.getRoles();
@@ -37,12 +37,12 @@ public class RoleHandlerTest extends HandlerTest{
             assertTrue(role.getName().equals("admin") || role.getName().equals("user"));
         }
 
-        //check existing role
+        // check existing role
         Role role = resource().path("/v1/roles/0").get(Role.class);
         assertNotNull(role);
         assertTrue(role.getName().equals("admin"));
 
-        //check not exist Role
+        // check not exist Role
         try {
             resource().path("/v1/roles/5").get(IDMError.class);
             fail("Should failed with 404!");
@@ -54,16 +54,18 @@ public class RoleHandlerTest extends HandlerTest{
 
         // check create Role
         Map<String, String> roleData = new HashMap<String, String>();
-        roleData.put("name","role1");
-        roleData.put("description","test Role");
-        roleData.put("domainid","0");
-        ClientResponse clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, roleData);
+        roleData.put("name", "role1");
+        roleData.put("description", "test Role");
+        roleData.put("domainid", "0");
+        ClientResponse clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON)
+                .post(ClientResponse.class, roleData);
         assertEquals(201, clientResponse.getStatus());
 
         // check create Role missing name data
         roleData.remove("name");
         try {
-            clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, roleData);
+            clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
+                    roleData);
             assertEquals(404, clientResponse.getStatus());
         } catch (UniformInterfaceException e) {
             ClientResponse resp = e.getResponse();
@@ -71,8 +73,9 @@ public class RoleHandlerTest extends HandlerTest{
         }
 
         // check update Role data
-        roleData.put("name","role1Update");
-        clientResponse = resource().path("/v1/roles/2").type(MediaType.APPLICATION_JSON).put(ClientResponse.class, roleData);
+        roleData.put("name", "role1Update");
+        clientResponse = resource().path("/v1/roles/2").type(MediaType.APPLICATION_JSON).put(ClientResponse.class,
+                roleData);
         assertEquals(200, clientResponse.getStatus());
         role = resource().path("/v1/roles/2").get(Role.class);
         assertNotNull(role);
@@ -92,15 +95,14 @@ public class RoleHandlerTest extends HandlerTest{
             assertTrue(resp.getEntity(IDMError.class).getMessage().contains("role id not found"));
         }
 
-        // Bug 8382:  if a role id is specified, 400 is returned
+        // Bug 8382: if a role id is specified, 400 is returned
         roleData = new HashMap<String, String>();
-        roleData.put("name","role1");
-        roleData.put("description","test Role");
-        roleData.put("domainid","0");
+        roleData.put("name", "role1");
+        roleData.put("description", "test Role");
+        roleData.put("domainid", "0");
         roleData.put("roleid", "roleid");
-        clientResponse = resource().path("/v1/roles").
-                type(MediaType.APPLICATION_JSON).
-                post(ClientResponse.class, roleData);
+        clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
+                roleData);
         assertEquals(400, clientResponse.getStatus());
     }
 }
index 0e4a8a70545ce797f8e6a99f990a4e178acbb58d..f04bb461eca6b946e7a3d6208d503c36145d2a43 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Inocybe Technologies and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,7 +8,10 @@
 
 package org.opendaylight.aaa.idm.rest.test;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.UniformInterfaceException;
@@ -25,7 +28,7 @@ public class UserHandlerTest extends HandlerTest {
 
     @Test
     public void testUserHandler() {
-        //check default users
+        // check default users
         Users users = resource().path("/v1/users").get(Users.class);
         assertNotNull(users);
         List<User> usrList = users.getUsers();
@@ -34,12 +37,12 @@ public class UserHandlerTest extends HandlerTest {
             assertTrue(usr.getName().equals("admin") || usr.getName().equals("user"));
         }
 
-        //check existing user
+        // check existing user
         User usr = resource().path("/v1/users/0").get(User.class);
         assertNotNull(usr);
         assertTrue(usr.getName().equals("admin"));
 
-        //check not exist user
+        // check not exist user
         try {
             resource().path("/v1/users/5").get(IDMError.class);
             fail("Should failed with 404!");
@@ -51,19 +54,21 @@ public class UserHandlerTest extends HandlerTest {
 
         // check create user
         Map<String, String> usrData = new HashMap<String, String>();
-        usrData.put("name","usr1");
-        usrData.put("description","test user");
-        usrData.put("enabled","true");
-        usrData.put("email","user1@usr.org");
-        usrData.put("password","ChangeZbadPa$$w0rd");
-        usrData.put("domainid","0");
-        ClientResponse clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrData);
+        usrData.put("name", "usr1");
+        usrData.put("description", "test user");
+        usrData.put("enabled", "true");
+        usrData.put("email", "user1@usr.org");
+        usrData.put("password", "ChangeZbadPa$$w0rd");
+        usrData.put("domainid", "0");
+        ClientResponse clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON)
+                .post(ClientResponse.class, usrData);
         assertEquals(201, clientResponse.getStatus());
 
         // check create user missing name data
         usrData.remove("name");
         try {
-            clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrData);
+            clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
+                    usrData);
             assertEquals(400, clientResponse.getStatus());
         } catch (UniformInterfaceException e) {
             ClientResponse resp = e.getResponse();
@@ -71,8 +76,9 @@ public class UserHandlerTest extends HandlerTest {
         }
 
         // check update user data
-        usrData.put("name","usr1Update");
-        clientResponse = resource().path("/v1/users/2").type(MediaType.APPLICATION_JSON).put(ClientResponse.class, usrData);
+        usrData.put("name", "usr1Update");
+        clientResponse = resource().path("/v1/users/2").type(MediaType.APPLICATION_JSON).put(ClientResponse.class,
+                usrData);
         assertEquals(200, clientResponse.getStatus());
         usr = resource().path("/v1/users/2").get(User.class);
         assertNotNull(usr);
@@ -92,19 +98,17 @@ public class UserHandlerTest extends HandlerTest {
             assertTrue(resp.getEntity(IDMError.class).getMessage().contains("Couldn't find user"));
         }
 
-        // Bug 8382:  if a user id is specified, 400 is returned
+        // Bug 8382: if a user id is specified, 400 is returned
         usrData = new HashMap<String, String>();
-        usrData.put("name","usr1");
-        usrData.put("description","test user");
-        usrData.put("enabled","true");
-        usrData.put("email","user1@usr.org");
-        usrData.put("password","ChangeZbadPa$$w0rd");
+        usrData.put("name", "usr1");
+        usrData.put("description", "test user");
+        usrData.put("enabled", "true");
+        usrData.put("email", "user1@usr.org");
+        usrData.put("password", "ChangeZbadPa$$w0rd");
         usrData.put("userid", "userid");
-        usrData.put("domainid","0");
-        clientResponse = resource().path("/v1/users").
-                type(MediaType.APPLICATION_JSON).
-                post(ClientResponse.class, usrData);
+        usrData.put("domainid", "0");
+        clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
+                usrData);
         assertEquals(400, clientResponse.getStatus());
     }
-
 }