Fix checkstyle issues to enforce it 32/63232/6
authorDavid Suarez <david.suarez.fuentes@gmail.com>
Sun, 11 Mar 2018 15:37:20 +0000 (16:37 +0100)
committerTom Pantelis <tompantelis@gmail.com>
Mon, 19 Mar 2018 15:10:48 +0000 (11:10 -0400)
Change-Id: I77b3e119c7cd972f1f2f141f5adfdeab6c518ead
Signed-off-by: David Suarez <david.suarez.fuentes@gmail.com>
43 files changed:
aaa-authn-api/src/main/java/org/opendaylight/aaa/api/AuthenticationException.java
aaa-shiro/impl/pom.xml
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/authenticator/ODLAuthenticator.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/datastore/mdsal/MdsalTokenStore.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/provider/GsonProvider.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/ServiceProxy.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/accounting/Accounter.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/filters/AAAShiroFilter.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/filters/AuthenticationListener.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/filters/AuthenticationTokenUtils.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/filters/MoonOAuthFilter.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/filters/ODLHttpAuthenticationFilter.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/moon/MoonPrincipal.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/moon/MoonTokenEndpoint.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/principal/ODLPrincipalImpl.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/KeystoneAuthRealm.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/MDSALDynamicAuthorizationFilter.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/MdsalRealm.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/MoonRealm.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/ODLActiveDirectoryRealm.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/ODLJdbcRealm.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/ODLJndiLdapRealm.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/ODLJndiLdapRealmAuthNOnly.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/TokenAuthRealm.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/mapping/api/GroupsToRolesMappingStrategy.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/util/TokenUtils.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/util/http/SimpleHttpClient.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/util/http/SimpleHttpRequest.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/util/http/UntrustedSSL.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/util/http/header/HeaderUtils.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/tokenauthrealm/auth/AuthenticationBuilder.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/tokenauthrealm/auth/ClaimBuilder.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/tokenauthrealm/auth/HttpBasicAuth.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/tokenauthrealm/auth/PasswordCredentialBuilder.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/ServiceProxyTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/TestAppender.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/filters/AuthenticationListenerTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/filters/AuthenticationTokenUtilsTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/realm/MDSALDynamicAuthorizationFilterTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/realm/ODLJndiLdapRealmTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/realm/TokenAuthRealmTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/realm/mapping/impl/BestAttemptGroupToRolesMappingStrategyTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/realm/util/http/SimpleHttpRequestTest.java

index c6a288606df1ead78aa686e5e035261a1a340b63..ab029d837ee551c2a248b368c53fcb87f1dc3c6a 100644 (file)
@@ -25,4 +25,7 @@ public class AuthenticationException extends RuntimeException {
         super(msg, cause);
     }
 
+    public AuthenticationException(Throwable throwable) {
+        super(throwable);
+    }
 }
index 33e636cfe57175671cbdc9ec083cef5aa4f1ac80..7997fe84c08b3e0a3df228f9ff20c2bd10fd5f6e 100644 (file)
@@ -215,6 +215,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
     <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.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
index fd287e9c7758ced66432c82dac5cd75323808e65..62d755fd2f3a55738b7a92968790eb457d6ae7f3 100644 (file)
@@ -8,6 +8,9 @@
 
 package org.opendaylight.aaa.authenticator;
 
+import java.nio.charset.Charset;
+import java.util.Base64;
+import javax.servlet.http.HttpServletRequest;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.authc.AuthenticationException;
 import org.apache.shiro.authc.UsernamePasswordToken;
@@ -16,10 +19,6 @@ import org.jolokia.osgi.security.Authenticator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.servlet.http.HttpServletRequest;
-import java.nio.charset.Charset;
-import java.util.Base64;
-
 /**
  * AAA hook for <code>odl-jolokia</code> configured w/ <code>org.jolokia.authMode=service-all</code>.
  */
@@ -34,8 +33,7 @@ public class ODLAuthenticator implements Authenticator {
             final String authorization = httpServletRequest.getHeader("Authorization");
             if (authorization != null && authorization.startsWith("Basic")) {
                 final String base64Creds = authorization.substring("Basic".length()).trim();
-                String credentials = new String(Base64.getDecoder().decode(base64Creds),
-                        Charset.forName("UTF-8"));
+                String credentials = new String(Base64.getDecoder().decode(base64Creds), Charset.forName("UTF-8"));
                 final String[] values = credentials.split(":", 2);
                 final Subject subject = SecurityUtils.getSubject();
                 UsernamePasswordToken upt = new UsernamePasswordToken();
@@ -46,7 +44,7 @@ public class ODLAuthenticator implements Authenticator {
             }
         } catch (final ArrayIndexOutOfBoundsException e) {
             LOG.trace("Jolokia Authentication attempt unsuccessful; formatting issue basic auth credentials");
-        } catch(final AuthenticationException e) {
+        } catch (final AuthenticationException e) {
             LOG.trace("Jolokia Authentication attempt unsuccessful; Couldn't authenticate the subject");
         }
         return false;
index 5ad82dc87b7ac8c98c318f32695fa914d3455dbd..74a129a8f54080c147ed2c475760bebdd6c033c9 100644 (file)
@@ -12,7 +12,7 @@ import org.opendaylight.aaa.api.Authentication;
 import org.opendaylight.aaa.api.TokenStore;
 
 /**
- * Implementation of the mdsal AAA token store
+ * Implementation of the mdsal AAA token store.
  */
 public class MdsalTokenStore implements AutoCloseable, TokenStore {
 
index 991a0802a131d702518bd50db50d768cdfade046..cc9b7324adab78f2ca2486e8aaba0cdc202dbcef 100644 (file)
@@ -9,14 +9,16 @@ package org.opendaylight.aaa.provider;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -24,8 +26,6 @@ import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
 
 // Taken from https://memorynotfound.com/jaxrs-jersey-gson-serializer-deserializer/
 @Provider
@@ -76,23 +76,23 @@ public class GsonProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<
     }
 
     @Override
-    public long getSize(T t, Class<?> type, Type genericType,
+    public long getSize(T type, Class<?> theClass, Type genericType,
                         Annotation[] annotations, MediaType mediaType) {
         return -1;
     }
 
     @Override
-    public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations,
+    public void writeTo(T type, Class<?> theClass, Type genericType, Annotation[] annotations,
                         MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
                         OutputStream entityStream) throws IOException, WebApplicationException {
 
         PrintWriter printWriter = new PrintWriter(entityStream);
         try {
             String json;
-            if (ui.getQueryParameters().containsKey(PRETTY_PRINT)){
-                json = prettyGson.toJson(t);
+            if (ui.getQueryParameters().containsKey(PRETTY_PRINT)) {
+                json = prettyGson.toJson(type);
             } else {
-                json = gson.toJson(t);
+                json = gson.toJson(type);
             }
             printWriter.write(json);
             printWriter.flush();
index 180628ce1d2be551d4fa1999d05de3c80f3fb600..4c3c70837f378d3ab67b4aa02e1d952e7fb5b0ef 100644 (file)
@@ -20,10 +20,12 @@ import org.slf4j.LoggerFactory;
  * disabled by default in order to support workflows such as the feature
  * <code>odl-restconf-noauth</code>.
  *
+ * <p>
  * The AAA service is enabled through installing the <code>odl-aaa-shiro</code>
  * feature. The blueprint Provider in <code>aaa-shiro-act</code> enables AAA
  * through the ServiceProxy, which in turn enables the AAAFilter.
  *
+ * <p>
  * ServiceProxy is a singleton; access to the ServiceProxy is granted through
  * the <code>getInstance()</code> function.
  *
@@ -32,7 +34,7 @@ import org.slf4j.LoggerFactory;
  *      web,xml</a>
  * @see <code>AAAFilter</code>
  */
-public class ServiceProxy {
+public final class ServiceProxy {
 
     private static final Logger LOG = LoggerFactory.getLogger(ServiceProxy.class);
 
@@ -41,15 +43,17 @@ public class ServiceProxy {
     private AAAFilter filter;
 
     /**
-     * private for singleton pattern
+     * private for singleton pattern.
      */
     private ServiceProxy() {
-        final String INFO_MESSAGE = "Creating the ServiceProxy";
-        LOG.info(INFO_MESSAGE);
+        final String infoMessage = "Creating the ServiceProxy";
+        LOG.info(infoMessage);
     }
 
     /**
-     * @return ServiceProxy, a feature level singleton
+     * Returns the single instance.
+     *
+     * @return ServiceProxy, a feature level singleton.
      */
     public static ServiceProxy getInstance() {
         return instance;
@@ -73,13 +77,13 @@ public class ServiceProxy {
     /**
      * Extract whether the service is enabled.
      *
-     * @param filter
+     * @param aaaFilter
      *            register an optional Filter for callback if enable state
      *            changes
      * @return Whether the service is enabled
      */
-    public synchronized boolean getEnabled(final AAAFilter filter) {
-        this.filter = filter;
+    public synchronized boolean getEnabled(final AAAFilter aaaFilter) {
+        this.filter = aaaFilter;
         return enabled;
     }
 }
index bb917363f203c0600f97711ab148a8859e664b6e..17228735afd7544e33f5878bc67cf0788aeb44f4 100644 (file)
@@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
  * Accounter is a common place to output AAA messages. Use this class through
  * invoking <code>Logger.output("message")</code>.
  */
-public class Accounter {
+public final class Accounter {
 
     private static final Logger LOG = LoggerFactory.getLogger(Accounter.class);
 
@@ -26,7 +26,7 @@ public class Accounter {
     }
 
     /**
-     * Account for a particular <code>message</code>
+     * Account for a particular <code>message</code>.
      *
      * @param message A message for the aggregated AAA log.
      */
index 1219a5edf4274fef033909076f10bfbcc9842bbc..0045a2ddccdd22dea09828929383c33601e50474 100644 (file)
@@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory;
  * is that <code>AAAFilter</code> was designed to support the existing noauth
  * mechanism, while this filter cannot be disabled.
  *
+ * <p>
  * This class is also responsible for delivering debug information; to enable these
  * debug statements, please issue the following in the karaf shell:
  *
index ed13b5029c38a9464115538801a45b2f245d6c18..f99e47d0b5cc49bf0285dbf50ddf57e6e68ad594 100644 (file)
@@ -34,7 +34,8 @@ public class AuthenticationListener implements org.apache.shiro.authc.Authentica
     }
 
     @Override
-    public void onFailure(final AuthenticationToken authenticationToken, final AuthenticationException e) {
+    public void onFailure(final AuthenticationToken authenticationToken,
+                          final AuthenticationException authenticationException) {
         if (LOG.isDebugEnabled()) {
             LOG.debug(AuthenticationTokenUtils.generateUnsuccessfulAuthenticationMessage(authenticationToken));
         }
index 824adec0f484b099268b9665be82eea6566b079a..b29d1f9b311f4cbafe1f2500699582b115b3f467 100644 (file)
@@ -15,10 +15,10 @@ import org.apache.shiro.authc.UsernamePasswordToken;
 /**
  * Utility methods for forming audit trail output based on an <code>AuthenticationToken</code>.
  */
-public class AuthenticationTokenUtils {
+public final class AuthenticationTokenUtils {
 
     /**
-     * default value used in messaging when the "user" field is unparsable from the HTTP REST request
+     * default value used in messaging when the "user" field is unparsable from the HTTP REST request.
      */
     static final String DEFAULT_USERNAME = "an unknown user";
 
index 7f0de764b63c0c7aca4616afcae5a7fd93f8f589..5c3182e0aa8b3b175da7aefd968fc2137dbee69b 100644 (file)
@@ -41,7 +41,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * MoonOAuthFilter filters oauth1 requests form token based authentication
+ * MoonOAuthFilter filters oauth1 requests form token based authentication.
  *
  * @author Alioune BA alioune.ba@orange.com
  */
@@ -65,7 +65,8 @@ public class MoonOAuthFilter extends AuthenticatingFilter {
     }
 
     @Override
-    protected UsernamePasswordToken createToken(final ServletRequest request, final ServletResponse response) throws Exception {
+    protected UsernamePasswordToken createToken(final ServletRequest request,
+                                                final ServletResponse response) throws Exception {
         final HttpServletRequest httpRequest;
         final OAuthRequest oauthRequest;
         try {
@@ -86,7 +87,7 @@ public class MoonOAuthFilter extends AuthenticatingFilter {
 
     @Override
     protected boolean onLoginSuccess(final AuthenticationToken token, final Subject subject,
-            final ServletRequest request, final ServletResponse response) throws Exception {
+                                     final ServletRequest request, final ServletResponse response) throws Exception {
 
         final HttpServletResponse httpResponse;
         try {
@@ -110,8 +111,9 @@ public class MoonOAuthFilter extends AuthenticatingFilter {
     }
 
     @Override
-    protected boolean onLoginFailure(final AuthenticationToken token, final AuthenticationException e,
-            final ServletRequest request, final ServletResponse response) {
+    protected boolean onLoginFailure(final AuthenticationToken token,
+                                     final AuthenticationException authenticationException,
+                                     final ServletRequest request, final ServletResponse response) {
 
         final HttpServletResponse resp;
         try {
@@ -125,6 +127,7 @@ public class MoonOAuthFilter extends AuthenticatingFilter {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected boolean executeLogin(final ServletRequest request, final ServletResponse response) throws Exception {
 
         final HttpServletRequest req;
@@ -147,8 +150,8 @@ public class MoonOAuthFilter extends AuthenticatingFilter {
             if (req.getServletPath().equals(TOKEN_GRANT_ENDPOINT)) {
                 final UsernamePasswordToken token = createToken(request, response);
                 if (token == null) {
-                    final String msg = "A valid non-null AuthenticationToken " +
-                            "must be created in order to execute a login attempt.";
+                    final String msg = "A valid non-null AuthenticationToken "
+                            "must be created in order to execute a login attempt.";
                     throw new IllegalStateException(msg);
                 }
                 try {
@@ -167,35 +170,34 @@ public class MoonOAuthFilter extends AuthenticatingFilter {
             error(resp, SC_UNAUTHORIZED, e.getMessage());
         } catch (final OAuthProblemException oe) {
             error(resp, oe);
-        } catch (final Exception e) {
+        } catch (final RuntimeException e) {
             error(resp, e);
         }
         return false;
     }
 
-    private void oauthAccessTokenResponse(final HttpServletResponse resp, final Claim claim, final String clientId, final String token)
-            throws OAuthSystemException, IOException {
+    private void oauthAccessTokenResponse(final HttpServletResponse resp, final Claim claim, final String clientId,
+                                          final String token) throws OAuthSystemException, IOException {
 
         if (claim == null) {
             throw new AuthenticationException(UNAUTHORIZED);
         }
 
         // Cache this token...
-        final Authentication auth = new AuthenticationBuilder(new ClaimBuilder(claim).setClientId(
-                clientId).build()).setExpiration(tokenExpiration()).build();
+        final Authentication auth = new AuthenticationBuilder(new ClaimBuilder(claim).setClientId(clientId).build())
+                .setExpiration(tokenExpiration()).build();
         tokenStore.put(token, auth);
 
         final OAuthResponse r = OAuthASResponse.tokenResponse(SC_CREATED).setAccessToken(token)
-                                         .setTokenType(TokenType.BEARER.toString())
-                                         .setExpiresIn(Long.toString(auth.expiration()))
-                                         .buildJSONMessage();
+                .setTokenType(TokenType.BEARER.toString()).setExpiresIn(Long.toString(auth.expiration()))
+                .buildJSONMessage();
         write(resp, r);
     }
 
-    private void write(final HttpServletResponse resp, final OAuthResponse r) throws IOException {
-        resp.setStatus(r.getResponseStatus());
+    private void write(final HttpServletResponse resp, final OAuthResponse response) throws IOException {
+        resp.setStatus(response.getResponseStatus());
         PrintWriter pw = resp.getWriter();
-        pw.print(r.getBody());
+        pw.print(response.getBody());
         pw.flush();
         pw.close();
     }
@@ -205,37 +207,35 @@ public class MoonOAuthFilter extends AuthenticatingFilter {
     }
 
     /**
-     * Utility method used to emit an error OAuthResponse with the given HTTP code
+     * Utility method used to emit an error OAuthResponse with the given HTTP code.
      */
     private void error(final HttpServletResponse resp, final int httpCode, final String error) {
         try {
-            final OAuthResponse r = OAuthResponse.errorResponse(httpCode).setError(error)
-                                           .buildJSONMessage();
+            final OAuthResponse r = OAuthResponse.errorResponse(httpCode).setError(error).buildJSONMessage();
             write(resp, r);
         } catch (final IOException | OAuthSystemException ex) {
             LOG.error("Failed to write the error ", ex);
         }
     }
 
-    private void error(final HttpServletResponse resp, final OAuthProblemException e) {
+    private void error(final HttpServletResponse resp, final OAuthProblemException oauthProblemException) {
         try {
-            final OAuthResponse r = OAuthResponse.errorResponse(SC_BAD_REQUEST).error(e)
-                                           .buildJSONMessage();
+            final OAuthResponse r = OAuthResponse.errorResponse(SC_BAD_REQUEST).error(oauthProblemException)
+                    .buildJSONMessage();
             write(resp, r);
         } catch (final IOException | OAuthSystemException ex) {
             LOG.error("Failed to write the error ", ex);
         }
     }
 
-    private void error(final HttpServletResponse resp, final Exception e) {
+    private void error(final HttpServletResponse resp, final Exception exception) {
         try {
             final OAuthResponse r = OAuthResponse.errorResponse(SC_INTERNAL_SERVER_ERROR)
-                                           .setError(e.getClass().getName())
-                                           .setErrorDescription(e.getMessage()).buildJSONMessage();
+                    .setError(exception.getClass().getName()).setErrorDescription(exception.getMessage())
+                    .buildJSONMessage();
             write(resp, r);
         } catch (final IOException | OAuthSystemException ex) {
             LOG.error("Failed to write the error ", ex);
         }
     }
-
 }
index 49903db9d27b3a3b79d56e4a7013c4078b605f72..4797945e225beaab30fdff9ebcafdb4d15fff215 100644 (file)
@@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
  * Extends <code>BasicHttpAuthenticationFilter</code> to include ability to
  * authenticate OAuth2 tokens.
  *
+ * <p>
  * This behavior is enabled by default for backwards compatibility. To disable
  * OAuth2 functionality, just comment out the following line from the
  * <code>etc/shiro.ini</code> file:
index 97553a86e3dad5f0b0800d4fc7788638d2fbea84..1c2dbe48163e0ae698daa73eac48b48124ad0e3d 100644 (file)
@@ -15,7 +15,7 @@ import java.util.Set;
 import org.opendaylight.aaa.api.Claim;
 
 /**
- * MoonPrincipal contains all user's information returned by moon on successful authentication
+ * MoonPrincipal contains all user's information returned by moon on successful authentication.
  *
  * @author Alioune BA alioune.ba@orange.com
  */
@@ -27,7 +27,6 @@ public class MoonPrincipal {
     private final ImmutableSet<String> roles;
     private final String token;
 
-
     public MoonPrincipal(final String username, final String domain, final String userId,
             final Set<String> roles, final String token) {
 
@@ -38,13 +37,13 @@ public class MoonPrincipal {
         this.token = token;
     }
 
-    public MoonPrincipal createODLPrincipal(final String username, final String domain,
-            final String userId, final Set<String> roles, final String token) {
+    public MoonPrincipal createODLPrincipal(final String userName, final String theDomain,
+            final String theUserId, final Set<String> theRoles, final String theToken) {
 
-        return new MoonPrincipal(username, domain, userId, roles,token);
+        return new MoonPrincipal(userName, theDomain, theUserId, theRoles,theToken);
     }
 
-    public Claim principalToClaim () {
+    public Claim principalToClaim() {
         return new MoonClaim("", this.getUserId(), this.getUsername(), this.getDomain(), this.getRoles());
     }
 
@@ -64,7 +63,7 @@ public class MoonPrincipal {
         return this.roles;
     }
 
-    public String getToken(){
+    public String getToken() {
         return this.token;
     }
 
index e64790b8944af9a1e4058358ed102edce37f8168..b5290fea3fbc4004519f8144b5926430ee1c6ce8 100644 (file)
@@ -7,13 +7,10 @@
  */
 package org.opendaylight.aaa.shiro.moon;
 
-
 import java.io.IOException;
-
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -30,5 +27,4 @@ public class MoonTokenEndpoint extends HttpServlet {
     protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
         LOG.info("MoonTokenEndpoint Servlet doPost: {} {}", req.getServletPath(), req.getRequestURI());
     }
-
 }
index 0dac19ed9d9713e4ad08101c36f5bb13153e9bb6..4ade9b93367630c0d5bcf39c71a46c22803e6776 100644 (file)
@@ -16,7 +16,7 @@ import org.opendaylight.aaa.api.shiro.principal.ODLPrincipal;
  * An ODL specific principal which stores some critical information about the user
  * making the auth request.
  */
-public class ODLPrincipalImpl implements ODLPrincipal {
+public final class ODLPrincipalImpl implements ODLPrincipal {
 
     private final String username;
     private final String domain;
index a21e67ebe164130eae738fa0881f0c4f045265fc..0b1906a1965fb205c414dab6a9cf55163e6d1877 100644 (file)
@@ -94,6 +94,7 @@ public class KeystoneAuthRealm extends AuthorizingRealm {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:AvoidHidingCauseException")
     protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken authenticationToken) {
         try {
             final boolean hasSslVerification = getSslVerification();
index ff3c01d9deb71918382e4cc00b5bf61663c871c2..c316442eaa333ee6e3430bd72c9a3abae0fca49c 100644 (file)
@@ -72,11 +72,11 @@ public class MDSALDynamicAuthorizationFilter extends AuthorizationFilter {
         final Optional<HttpAuthorization> authorizationOptional;
         try {
             authorizationOptional = getHttpAuthzContainer(dataBroker);
-        } catch(ExecutionException | InterruptedException e) {
+        } catch (ExecutionException | InterruptedException e) {
             // Something went completely wrong trying to read the authz container.  Deny access.
             LOG.debug("Error accessing the Http Authz Container", e);
             return false;
-        } catch(final ReadFailedException e) {
+        } catch (final ReadFailedException e) {
             // The MDSAL read attempt failed.  fail-closed to prevent unauthorized access
             LOG.warn("MDSAL attempt to read Http Authz Container failed, disallowing access", e);
             return false;
@@ -92,16 +92,17 @@ public class MDSALDynamicAuthorizationFilter extends AuthorizationFilter {
 
         final HttpAuthorization httpAuthorization = authorizationOptional.get();
         final Policies policies = httpAuthorization.getPolicies();
-        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies> policiesList =
-                policies.getPolicies();
-        if(policiesList.isEmpty()) {
+        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                .policies.Policies>
+                policiesList = policies.getPolicies();
+        if (policiesList.isEmpty()) {
             // The authorization container exists, but no rules are present.  Allow access.
             LOG.debug("Exiting successfully early since no authorization rules exist");
             return true;
         }
 
-        for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies policy :
-                policiesList) {
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                .policies.Policies policy : policiesList) {
             final String resource = policy.getResource();
             final boolean pathsMatch = pathsMatch(resource, requestURI);
             if (pathsMatch) {
@@ -113,9 +114,9 @@ public class MDSALDynamicAuthorizationFilter extends AuthorizationFilter {
                     final String role = permission.getRole();
                     LOG.trace("role={}", role);
                     final List<Permissions.Actions> actions = permission.getActions();
-                    for(Permissions.Actions action : actions) {
+                    for (Permissions.Actions action : actions) {
                         LOG.trace("action={}", action.getName());
-                        if(action.getName().equalsIgnoreCase(method)) {
+                        if (action.getName().equalsIgnoreCase(method)) {
                             final boolean hasRole = subject.hasRole(role);
                             LOG.trace("hasRole({})={}", role, hasRole);
                             if (hasRole) {
index dac069171b03a491b37f334180d1a8d4bacdae7a..3d4db766e5a3bf6a335a26a75245c73de4d53f30 100644 (file)
@@ -73,14 +73,16 @@ public class MdsalRealm extends AuthorizingRealm {
 
             // iterate through and determine the appropriate roles based on the programmed grants
             final Grants grants = auth.getGrants();
-            final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.authentication.grants.Grants> grantsList = grants.getGrants();
-            for (Grant grant : grantsList ) {
+            final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.authentication
+                    .grants.Grants> grantsList = grants.getGrants();
+            for (Grant grant : grantsList) {
                 if (grant.getUserid().equals(odlPrincipal.getUserId())) {
                     final Roles roles = auth.getRoles();
                     if (roles != null) {
-                        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.authentication.roles.Roles> rolesList =
-                                roles.getRoles();
-                        for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.authentication.roles.Roles role : rolesList) {
+                        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214
+                                .authentication.roles.Roles> rolesList = roles.getRoles();
+                        for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214
+                                .authentication.roles.Roles role : rolesList) {
                             if (role.getRoleid().equals(grant.getRoleid())) {
                                 authRoles.add(role.getRoleid());
                             }
@@ -98,7 +100,7 @@ public class MdsalRealm extends AuthorizingRealm {
      * @return the <code>authentication</code> container
      */
     private Optional<Authentication> getAuthenticationContainer() {
-        try (final ReadOnlyTransaction ro = dataBroker.newReadOnlyTransaction()) {
+        try (ReadOnlyTransaction ro = dataBroker.newReadOnlyTransaction()) {
             final CheckedFuture<Optional<Authentication>, ReadFailedException> result =
                     ro.read(LogicalDatastoreType.CONFIGURATION, AUTH_IID);
 
@@ -119,21 +121,23 @@ public class MdsalRealm extends AuthorizingRealm {
         if (opt.isPresent()) {
             final Authentication auth = opt.get();
             final Users users = auth.getUsers();
-            final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.authentication.users.Users> usersList =
-                    users.getUsers();
-            for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.authentication.users.Users u : usersList) {
+            final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.authentication
+                    .users.Users> usersList = users.getUsers();
+            for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.authentication.users
+                    .Users u : usersList) {
                 final String inputUsername = HeaderUtils.extractUsername(username);
                 final String domainId = HeaderUtils.extractDomain(username);
                 final String inputUserId = String.format("%s@%s", inputUsername, domainId);
                 final boolean userEnabled = u.isEnabled();
-                if(!userEnabled) {
+                if (!userEnabled) {
                     LOG.trace("userId={} is skipped because it is disabled", u.getUserid());
                 }
-                if(userEnabled && u.getUserid().equals(inputUserId)) {
+                if (userEnabled && u.getUserid().equals(inputUserId)) {
                     final String inputPassword = TokenUtils.extractPassword(authenticationToken);
                     final String hashedInputPassword = SHA256Calculator.getSHA256(inputPassword, u.getSalt());
                     if (hashedInputPassword.equals(u.getPassword())) {
-                        final ODLPrincipal odlPrincipal = ODLPrincipalImpl.createODLPrincipal(inputUsername,domainId,inputUserId);
+                        final ODLPrincipal odlPrincipal = ODLPrincipalImpl
+                                .createODLPrincipal(inputUsername, domainId, inputUserId);
                         return new SimpleAuthenticationInfo(odlPrincipal, inputPassword, getName());
                     }
                 }
index 85a6b417a1f297956b13920f1313f7c14fddf7db..14c3d516aa1c475091d8205afd936dc665284fcc 100644 (file)
@@ -49,7 +49,8 @@ public class MoonRealm extends AuthorizingRealm {
     }
 
     @Override
-    protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken authenticationToken) throws AuthenticationException {
+    protected AuthenticationInfo doGetAuthenticationInfo(
+            final AuthenticationToken authenticationToken) throws AuthenticationException {
         final String username;
         final String password;
         final String domain = MOON_DEFAULT_DOMAIN;
@@ -71,9 +72,9 @@ public class MoonRealm extends AuthorizingRealm {
 
         password = new String(upt.getPassword());
 
-        final MoonPrincipal moonPrincipal = moonAuthenticate(username,password,domain);
-        if (moonPrincipal != null){
-            return new SimpleAuthenticationInfo(moonPrincipal, password.toCharArray(),getName());
+        final MoonPrincipal moonPrincipal = moonAuthenticate(username, password, domain);
+        if (moonPrincipal != null) {
+            return new SimpleAuthenticationInfo(moonPrincipal, password.toCharArray(), getName());
         } else {
             return null;
         }
@@ -105,7 +106,8 @@ public class MoonRealm extends AuthorizingRealm {
         final String url = String.format("http://%s:%s/moon/auth/tokens", server, port);
         LOG.debug("Moon server is at: {}:{} and will be accessed through {}", server, port, url);
         final WebResource webResource = client.resource(url);
-        final String input = "{\"username\": \""+ username + "\"," + "\"password\":" + "\"" + password + "\"," + "\"project\":" + "\"" + domain + "\"" + "}";
+        final String input = "{\"username\": \"" + username + "\"," + "\"password\":" + "\"" + password + "\","
+                + "\"project\":" + "\"" + domain + "\"" + "}";
         final ClientResponse response = webResource.type("application/json").post(ClientResponse.class, input);
         output = response.getEntity(String.class);
 
index 5227c6d2180ebea05eebcd753a1f2b312d382328..b4d7353b2abebfd5cee056d6322d239d68f12b73 100644 (file)
@@ -18,6 +18,7 @@ import org.slf4j.LoggerFactory;
  * package, <code>org.opendaylightaaa.shiro.realm</code>, which enables easier
  * import by consuming servlets.
  *
+ * <p>
  * To enable the <code>ODLActiveDirectoryRealm</code>, modify the realms
  * declaration in <code>etc/shiro.ini</code> as follows:
  * <code>adRealm = ODLActiveDirectoryRealm
index d280c20c3d2886441035fc20e1b2cafaa1331c0a..1bbeffa5b8dad626dc9c90908a1ca02cc9673089 100644 (file)
@@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory;
  * JDBC-supporting data source.  This can ease deployment with existing OSS
  * systems.
  *
+ * <p>
  * To enabled the <code>ODLJdbcRealm</code>, modify the realms declaration in
  * <code>etc/shiro.ini</code> as follows:
  * <code>
index dbef0c9be32c7905ebc95d1d002ac506a5699e91..08853a9b9ee1864371a1911d1958133e5b24dafc 100644 (file)
@@ -44,15 +44,17 @@ import org.slf4j.LoggerFactory;
  * additional Authorization capabilities.  To enable this Realm, add the
  * following to <code>shiro.ini</code>:
  *
- *<code>#ldapRealm = ODLJndiLdapRealmAuthNOnly
- *#ldapRealm.userDnTemplate = uid={0},ou=People,dc=DOMAIN,dc=TLD
- *#ldapRealm.contextFactory.url = ldap://URL:389
- *#ldapRealm.searchBase = dc=DOMAIN,dc=TLD
- *#ldapRealm.ldapAttributeForComparison = objectClass
- *# The CSV list of enabled realms.  In order to enable a realm, add it to the
- *# list below:
+ * <p>
+ * <code>#ldapRealm = ODLJndiLdapRealmAuthNOnly
+ * #ldapRealm.userDnTemplate = uid={0},ou=People,dc=DOMAIN,dc=TLD
+ * #ldapRealm.contextFactory.url = ldap://URL:389
+ * #ldapRealm.searchBase = dc=DOMAIN,dc=TLD
+ * #ldapRealm.ldapAttributeForComparison = objectClass
+ * # The CSV list of enabled realms.  In order to enable a realm, add it to the
+ * # list below:
  * securityManager.realms = $tokenAuthRealm, $ldapRealm</code>
  *
+ * <p>
  * The values above are specific to the deployed LDAP domain.  If the defaults
  * are not sufficient, alternatives can be derived through enabling
  * <code>TRACE</code> level logging.  To enable <code>TRACE</code> level
@@ -61,8 +63,8 @@ import org.slf4j.LoggerFactory;
  *
  * @see <code>org.apache.shiro.realm.ldap.JndiLdapRealm</code>
  * @see <a
- *      href="https://shiro.apache.org/static/1.2.3/apidocs/org/apache/shiro/realm/ldap/JndiLdapRealm.html">Shiro
- *      documentation</a>
+ * href="https://shiro.apache.org/static/1.2.3/apidocs/org/apache/shiro/realm/ldap/JndiLdapRealm.html">Shiro
+ * documentation</a>
  */
 public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
 
@@ -91,8 +93,8 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
     /**
      * Strategy to determine how groups are mapped to roles.
      */
-    private static final GroupsToRolesMappingStrategy GROUPS_TO_ROLES_MAPPING_STRATEGY =
-            new BestAttemptGroupToRolesMappingStrategy();
+    private static final GroupsToRolesMappingStrategy GROUPS_TO_ROLES_MAPPING_STRATEGY
+            new BestAttemptGroupToRolesMappingStrategy();
 
     /**
      * The searchBase for the ldap query, which indicates the LDAP realms to
@@ -127,8 +129,7 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
      * .apache.shiro.authc.AuthenticationToken)
      */
     @Override
-    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
-            throws AuthenticationException {
+    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
 
         // Delegates all AuthN lookup responsibility to the super class
         try {
@@ -142,10 +143,9 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
     }
 
     /**
-     * Logs an incoming LDAP connection
+     * Logs an incoming LDAP connection.
      *
-     * @param username
-     *            the requesting user
+     * @param username the requesting user
      */
     protected void logIncomingConnection(final String username) {
         LOG.info("AAA LDAP connection from {}", username);
@@ -153,13 +153,12 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
     }
 
     /**
-     * Extracts the username from <code>token</code>
+     * Extracts the username from <code>token</code>.
      *
      * @param token Encoded token which could contain a username
      * @return The extracted username
-     * @throws ClassCastException
-     *             The incoming token is not username/password (i.e., X.509
-     *             certificate)
+     * @throws ClassCastException The incoming token is not username/password (i.e., X.509
+     *                            certificate)
      */
     public static String getUsername(AuthenticationToken token) throws ClassCastException {
         if (null == token) {
@@ -168,26 +167,13 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
         return (String) token.getPrincipal();
     }
 
-    @Override
-    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
-
-        AuthorizationInfo ai = null;
-        try {
-            ai = this.queryForAuthorizationInfo(principals, getContextFactory());
-        } catch (NamingException e) {
-            LOG.error("Unable to query for AuthZ info", e);
-        }
-        return ai;
-    }
-
     /**
-     * extracts a username from <code>principals</code>
+     * extracts a username from <code>principals</code>.
      *
      * @param principals A single principal extracted for the username
      * @return The username if possible
-     * @throws ClassCastException
-     *             the PrincipalCollection contains an element that is not in
-     *             username/password form (i.e., X.509 certificate)
+     * @throws ClassCastException the PrincipalCollection contains an element that is not in
+     *                            username/password form (i.e., X.509 certificate)
      */
     protected String getUsername(final PrincipalCollection principals) throws ClassCastException {
 
@@ -197,6 +183,18 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
         return (String) getAvailablePrincipal(principals);
     }
 
+    @Override
+    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
+
+        AuthorizationInfo ai = null;
+        try {
+            ai = this.queryForAuthorizationInfo(principals, getContextFactory());
+        } catch (NamingException e) {
+            LOG.error("Unable to query for AuthZ info", e);
+        }
+        return ai;
+    }
+
     /*
      * (non-Javadoc)
      *
@@ -206,11 +204,13 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
      *
      * <code>/** = authcBasic, roles[person]</code>
      *
-     * @see org.apache.shiro.realm.ldap.JndiLdapRealm#queryForAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection, org.apache.shiro.realm.ldap.LdapContextFactory)
+     * @see org.apache.shiro.realm.ldap.JndiLdapRealm#queryForAuthorizationInfo(org.apache.shiro.subject
+     * .PrincipalCollection, org.apache.shiro.realm.ldap.LdapContextFactory)
      */
     @Override
     protected AuthorizationInfo queryForAuthorizationInfo(PrincipalCollection principals,
-            LdapContextFactory ldapContextFactory) throws NamingException {
+                                                          LdapContextFactory ldapContextFactory) throws
+            NamingException {
 
         AuthorizationInfo authorizationInfo = null;
         try {
@@ -241,22 +241,22 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
      * extracts the Set of roles associated with a user based on the username
      * and ldap context (server).
      *
-     * @param username The username for the request
+     * @param username    The username for the request
      * @param ldapContext The specific system context provided by <code>shiro.ini</code>
      * @return A set of roles
      * @throws NamingException If the ldap search fails
      */
-    protected Set<String> getRoleNamesForUser(final String username, final LdapContext ldapContext)
-            throws NamingException {
+    protected Set<String> getRoleNamesForUser(final String username,
+                                              final LdapContext ldapContext) throws NamingException {
 
         final Set<String> roleNames = new LinkedHashSet<String>();
         final SearchControls searchControls = createSearchControls();
 
         LOG.debug("Asking the configured LDAP about which groups uid=\"{}\" belongs to using "
-                + "searchBase=\"{}\" ldapAttributeForComparison=\"{}\"",
-                username, searchBase, ldapAttributeForComparison);
-        final NamingEnumeration<SearchResult> answer = ldapContext.search(searchBase,
-                String.format("%s=%s", UID, username), searchControls);
+                          + "searchBase=\"{}\" ldapAttributeForComparison=\"{}\"", username, searchBase,
+                  ldapAttributeForComparison);
+        final NamingEnumeration<SearchResult> answer = ldapContext
+                .search(searchBase, String.format("%s=%s", UID, username), searchControls);
 
         while (answer.hasMoreElements()) {
             final SearchResult searchResult = answer.next();
@@ -268,30 +268,30 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
                     LOG.debug("LDAP returned \"{}\" attribute for \"{}\"", attr.getID(), username);
                     if (attr.getID().equals(ldapAttributeForComparison)) {
                         final Collection<String> groupNamesExtractedFromLdap = LdapUtils.getAllAttributeValues(attr);
-                        final Map<String, Set<String>> groupsToRoles = this.GROUPS_TO_ROLES_MAPPING_STRATEGY.mapGroupsToRoles(
-                                groupNamesExtractedFromLdap, ROLE_NAMES_DELIMITER, groupRolesMap);
+                        final Map<String, Set<String>> groupsToRoles = this.GROUPS_TO_ROLES_MAPPING_STRATEGY
+                                .mapGroupsToRoles(groupNamesExtractedFromLdap, ROLE_NAMES_DELIMITER, groupRolesMap);
 
                         final Collection<String> roleNamesFromLdapGroups;
                         // map the groups
                         if (groupRolesMap != null) {
                             roleNamesFromLdapGroups = new HashSet<>();
-                            for (String  rolesKey : groupsToRoles.keySet()) {
+                            for (String rolesKey : groupsToRoles.keySet()) {
                                 roleNamesFromLdapGroups.addAll(groupsToRoles.get(rolesKey));
                             }
                             if (LOG.isDebugEnabled()) {
                                 for (String group : groupsToRoles.keySet()) {
                                     LOG.debug("Mapped the \"{}\" LDAP group to \"{}\" ODL role for \"{}\"", group,
-                                            groupsToRoles.get(group), username);
+                                              groupsToRoles.get(group), username);
                                 }
                             }
                         } else {
-                            LOG.debug("Since groupRolesMap was unspecified, no mapping is attempted so " +
-                                    "the role names are set to the extracted group names");
+                            LOG.debug("Since groupRolesMap was unspecified, no mapping is attempted so "
+                                              + "the role names are set to the extracted group names");
                             roleNamesFromLdapGroups = groupNamesExtractedFromLdap;
                             if (LOG.isDebugEnabled()) {
                                 for (String group : groupNamesExtractedFromLdap) {
-                                    LOG.debug("Mapped the \"{}\" LDAP group to \"{}\" ODL role for \"{}\"",
-                                            group, group, username);
+                                    LOG.debug("Mapped the \"{}\" LDAP group to \"{}\" ODL role for \"{}\"", group,
+                                              group, username);
                                 }
                             }
                         }
@@ -305,7 +305,7 @@ public class ODLJndiLdapRealm extends JndiLdapRealm implements Nameable {
     }
 
     /**
-     * A utility method to help create the search controls for the LDAP lookup
+     * A utility method to help create the search controls for the LDAP lookup.
      *
      * @return A generic set of search controls for LDAP scoped to subtree
      */
index 878cc51f43fe97e29fece56570f7cb9bee1aaf5a..fefc17ac8af33321d5d35ad71551f324f1935756 100644 (file)
@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
  * without worrying about resolving LDAP attributes (groups) to OpenDaylight
  * roles.
  *
+ * <p>
  * The motivation for subclassing Shiro's implementation is two-fold: 1) Enhance
  * the default logging of Shiro. This allows us to more easily log incoming
  * connections, providing some security auditing. 2) Provide a common package in
@@ -69,7 +70,7 @@ public class ODLJndiLdapRealmAuthNOnly extends JndiLdapRealm {
     }
 
     /**
-     * Logs an incoming LDAP connection
+     * Logs an incoming LDAP connection.
      *
      * @param username
      *            the requesting user
@@ -81,7 +82,7 @@ public class ODLJndiLdapRealmAuthNOnly extends JndiLdapRealm {
     }
 
     /**
-     * Extracts the username from <code>token</code>
+     * Extracts the username from <code>token</code>.
      *
      * @param token Which possibly contains a username
      * @return the username if it can be extracted
index 1e42b98e39ee4aa11d5dbbf1daca2380e692a570..c024778372783ccec0cfdde24f8bba9a9ec4d6a2 100644 (file)
@@ -41,29 +41,30 @@ import org.slf4j.LoggerFactory;
 public class TokenAuthRealm extends AuthorizingRealm {
 
     /**
-     * The unique identifying name for <code>TokenAuthRealm</code>
+     * The unique identifying name for <code>TokenAuthRealm</code>.
      */
     private static final String TOKEN_AUTH_REALM_DEFAULT_NAME = "TokenAuthRealm";
 
     /**
-     * The message that is displayed if no <code>TokenAuth</code> interface is
-     * available yet
+     * The message that is displayed if no <code>TokenAuth</code> interface is available yet.
      */
-    private static final String AUTHENTICATION_SERVICE_UNAVAILABLE_MESSAGE = "{\"error\":\"Authentication service unavailable\"}";
+    private static final String AUTHENTICATION_SERVICE_UNAVAILABLE_MESSAGE =
+            "{\"error\":\"Authentication service unavailable\"}";
 
     /**
-     * The message that is displayed if credentials are missing or malformed
+     * The message that is displayed if credentials are missing or malformed.
      */
     private static final String FATAL_ERROR_DECODING_CREDENTIALS = "{\"error\":\"Unable to decode credentials\"}";
 
     /**
-     * The message that is displayed if non-Basic Auth is attempted
+     * The message that is displayed if non-Basic Auth is attempted.
      */
-    private static final String FATAL_ERROR_BASIC_AUTH_ONLY = "{\"error\":\"Only basic authentication is supported by TokenAuthRealm\"}";
+    private static final String FATAL_ERROR_BASIC_AUTH_ONLY
+            = "{\"error\":\"Only basic authentication is supported by TokenAuthRealm\"}";
 
     /**
      * The purposefully generic message displayed if <code>TokenAuth</code> is
-     * unable to validate the given credentials
+     * unable to validate the given credentials.
      */
     private static final String UNABLE_TO_AUTHENTICATE = "{\"error\":\"Could not authenticate\"}";
 
@@ -97,7 +98,7 @@ public class TokenAuthRealm extends AuthorizingRealm {
         try {
             odlPrincipal = (ODLPrincipal) primaryPrincipal;
             return new SimpleAuthorizationInfo(odlPrincipal.getRoles());
-        } catch(ClassCastException e) {
+        } catch (ClassCastException e) {
             LOG.error("Couldn't decode authorization request", e);
         }
         return new SimpleAuthorizationInfo();
@@ -114,8 +115,8 @@ public class TokenAuthRealm extends AuthorizingRealm {
      * .apache.shiro.authc.AuthenticationToken)
      */
     @Override
-    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken)
-            throws AuthenticationException {
+    protected AuthenticationInfo doGetAuthenticationInfo(
+            AuthenticationToken authenticationToken) throws AuthenticationException {
 
         final String username;
         final String password;
@@ -148,8 +149,7 @@ public class TokenAuthRealm extends AuthorizingRealm {
                         LOG.debug("Authentication attempt successful");
                         authenticationService.set(auth);
                         final ODLPrincipal odlPrincipal = ODLPrincipalImpl.createODLPrincipal(auth);
-                        return new SimpleAuthenticationInfo(odlPrincipal, password.toCharArray(),
-                                getName());
+                        return new SimpleAuthenticationInfo(odlPrincipal, password.toCharArray(), getName());
                     }
                 } catch (AuthenticationException ae) {
                     LOG.debug("Authentication attempt unsuccessful");
index 0b98f042fb17d09a89e94531c051672f9f0ae2ef..bb485d6ba729e6975a3271e8306653cf746ebb12 100644 (file)
@@ -20,11 +20,11 @@ public interface GroupsToRolesMappingStrategy {
     /**
      * Convert LDAP groups to ODL roles.
      *
-     * @param groups A collection of String groups extracted from making an LDAP query.
-     * @param delimeter A separator to allow multiple target roles.
+     * @param groups        A collection of String groups extracted from making an LDAP query.
+     * @param delimiter     A separator to allow multiple target roles.
      * @param groupRolesMap The association between groups to roles
      * @return A <code>non-null</code> map with group as the key and roles as the value
      */
-    Map<String, Set<String>> mapGroupsToRoles(final Collection<String> groups, final String delimeter,
-                                              final Map<String, String> groupRolesMap);
+    Map<String, Set<String>> mapGroupsToRoles(Collection<String> groups, String delimiter,
+                                              Map<String, String> groupRolesMap);
 }
index 03f52d3ff08f922922ff7fadcaf58d8f0104166e..3623702f874ab57a8c5df7c8b68c938738711be9 100644 (file)
@@ -14,14 +14,16 @@ import org.apache.shiro.authc.UsernamePasswordToken;
 /**
  * Utilities for manipulating <code>AuthenticationToken</code> instances from Shiro.
  */
-public class TokenUtils {
+public final class TokenUtils {
+
+    private TokenUtils() {
+    }
+
     /**
-     * extract the username from an <code>AuthenticationToken</code>
+     * extract the username from an <code>AuthenticationToken</code>.
      *
-     * @param authenticationToken
-     * @return
-     * @throws ClassCastException
-     * @throws NullPointerException
+     * @param authenticationToken authentication token
+     * @return string with the user name
      */
     public static String extractUsername(final AuthenticationToken authenticationToken)
             throws ClassCastException, NullPointerException {
@@ -30,12 +32,10 @@ public class TokenUtils {
     }
 
     /**
-     * extract the password from an <code>AuthenticationToken</code>
+     * extract the password from an <code>AuthenticationToken</code>.
      *
-     * @param authenticationToken
-     * @return
-     * @throws ClassCastException
-     * @throws NullPointerException
+     * @param authenticationToken authentication token
+     * @return string with the extracted password
      */
     public static String extractPassword(final AuthenticationToken authenticationToken)
             throws ClassCastException, NullPointerException {
index 09e2040d4553aab934cb0865e6ec8057ae90caab..f88d17868c5e05a82eb2261b9294263c29872da2 100644 (file)
@@ -21,6 +21,8 @@ import javax.net.ssl.SSLContext;
  * An utility that represents an HTTP client that allows to make
  * HTTP requests.
  */
+//Suppressed so UT's can mock it using Mockito.
+@SuppressWarnings("checkstyle:FinalClass")
 public class SimpleHttpClient {
 
     private final Client client;
@@ -60,22 +62,22 @@ public class SimpleHttpClient {
         /**
          * Sets the SSLContext to be used for SSL requests.
          *
-         * @param sslContext the SSLContext.
+         * @param context the SSLContext.
          * @return self, the client builder.
          */
-        public Builder sslContext(final SSLContext sslContext) {
-            this.sslContext = sslContext;
+        public Builder sslContext(final SSLContext context) {
+            this.sslContext = context;
             return this;
         }
 
         /**
          * Sets the hostname verifier the request is made with.
          *
-         * @param hostnameVerifier the hostname verifier.
+         * @param verifier the hostname verifier.
          * @return self, the client builder.
          */
-        public Builder hostnameVerifier(final HostnameVerifier hostnameVerifier) {
-            this.hostnameVerifier = hostnameVerifier;
+        public Builder hostnameVerifier(final HostnameVerifier verifier) {
+            this.hostnameVerifier = verifier;
             return this;
         }
 
index 9777cb461a8bd5a22f0449348c631bf2b20d804f..1393e760073a408de89221ad7586afe709c0c927 100644 (file)
@@ -26,6 +26,8 @@ import javax.ws.rs.core.Response;
  *
  * @param <T> the return type of the request.
  */
+// Suppressed so UT's can mock it using Mockito.
+@SuppressWarnings("checkstyle:FinalClass")
 public class SimpleHttpRequest<T> {
     private final Client client;
     private final Class<T> outputType;
@@ -34,7 +36,7 @@ public class SimpleHttpRequest<T> {
     private String method;
     private MediaType mediaType;
     private Object entity;
-    private Map<String, String> queryParams = new HashMap<>();
+    private final Map<String, String> queryParams = new HashMap<>();
 
     private SimpleHttpRequest(final Client client, final Class<T> outputType) {
         this.client = client;
@@ -86,7 +88,7 @@ public class SimpleHttpRequest<T> {
     }
 
     public static class Builder<T> {
-        private SimpleHttpRequest<T> request;
+        private final SimpleHttpRequest<T> request;
 
         Builder(Client client, Class<T> outputType) {
             request = new SimpleHttpRequest<>(client, outputType);
index 29d24b02be0ea5efce463a864fb2f5eb0eb54516..2f9a5fb912524bbb01e36e0b55b1872a92fe8021 100644 (file)
@@ -20,17 +20,17 @@ import org.opendaylight.aaa.cert.impl.KeyStoreConstant;
  * Container for an SSL context that allows untrusted access and a hostname
  * verifier that accepts any hostname.
  */
-public class UntrustedSSL {
+public final class UntrustedSSL {
 
     private UntrustedSSL() {}
 
-    private static class InsecureHostnameVerifier {
+    private static final class InsecureHostnameVerifier {
         private static final HostnameVerifier INSTANCE = (hostname, session) -> true;
 
         private InsecureHostnameVerifier() {}
     }
 
-    private static class InsecureTrustManager {
+    private static final class InsecureTrustManager {
         private static final TrustManager[] INSTANCE = new TrustManager[] {
             new X509TrustManager() {
                 private final X509Certificate[] empty = new X509Certificate[] {};
@@ -56,7 +56,7 @@ public class UntrustedSSL {
         private InsecureTrustManager() {}
     }
 
-    private static class InsecureSSLContext {
+    private static final class InsecureSSLContext {
         private static final SSLContext INSTANCE = buildSSLContext();
 
         private InsecureSSLContext() {}
index 48e6149e8dee7b7eddc8c905242c796e621d6d27..13ef267b4307d5ea93497d2c6a6ba3b117fa9468 100644 (file)
@@ -18,13 +18,17 @@ import org.opendaylight.aaa.shiro.tokenauthrealm.auth.HttpBasicAuth;
 /**
  * Utilities for HTTP header manipulation.
  */
-public class HeaderUtils {
+public final class HeaderUtils {
 
     public static final String USERNAME_DOMAIN_SEPARATOR = "@";
 
+    private HeaderUtils() {
+    }
+
     /**
+     * Returns a string containing the encoded token.
      *
-     * @param credentialToken
+     * @param credentialToken token to encode
      * @return Base64 encoded token
      */
     public static String getEncodedToken(final String credentialToken) {
@@ -36,17 +40,18 @@ public class HeaderUtils {
      *
      * @param username The request username
      * @param password The request password
-     * @param domain The request domain
+     * @param domain   The request domain
      * @return <code>username:password:domain</code>
      */
     public static String getUsernamePasswordDomainString(final String username, final String password,
                                                          final String domain) {
-        return username + HttpBasicAuth.AUTH_SEP + password  + HttpBasicAuth.AUTH_SEP + domain;
+        return username + HttpBasicAuth.AUTH_SEP + password + HttpBasicAuth.AUTH_SEP + domain;
     }
 
     /**
+     * Returns a string with the authorization header.
      *
-     * @param encodedToken
+     * @param encodedToken encoded token
      * @return Basic <code>encodedToken</code>
      */
     public static String getTokenAuthHeader(final String encodedToken) {
@@ -54,13 +59,14 @@ public class HeaderUtils {
     }
 
     /**
+     * Returns a map with all the list of headers for the given token.
      *
-     * @param tokenAuthHeader
+     * @param tokenAuthHeader token authorization header
      * @return a map with the basic auth header
      */
     public static Map<String, List<String>> formHeadersWithToken(final String tokenAuthHeader) {
-        final Map<String, List<String>> headers = new HashMap<String, List<String>>();
-        final List<String> headerValue = new ArrayList<String>();
+        final Map<String, List<String>> headers = new HashMap<>();
+        final List<String> headerValue = new ArrayList<>();
         headerValue.add(tokenAuthHeader);
         headers.put(HttpBasicAuth.AUTH_HEADER, headerValue);
         return headers;
@@ -72,7 +78,7 @@ public class HeaderUtils {
      *
      * @param username Username from the request
      * @param password Password from the request
-     * @param domain Domain from the request
+     * @param domain   Domain from the request
      * @return input map for <code>TokenAuth.validate()</code>
      */
     public static Map<String, List<String>> formHeaders(final String username, final String password,
@@ -84,28 +90,28 @@ public class HeaderUtils {
     }
 
     /**
-     * Extract username from the form <code>user</code> or <code>user@domain</code>
+     * Extract username from the form <code>user</code> or <code>user@domain</code>.
      *
      * @param possiblyQualifiedUsername <code>user</code> or <code>user@domain</code>
      * @return username
      */
     public static String extractUsername(final String possiblyQualifiedUsername) {
         if (possiblyQualifiedUsername.contains(USERNAME_DOMAIN_SEPARATOR)) {
-            final String [] qualifiedUserArray = possiblyQualifiedUsername.split(USERNAME_DOMAIN_SEPARATOR);
+            final String[] qualifiedUserArray = possiblyQualifiedUsername.split(USERNAME_DOMAIN_SEPARATOR);
             return qualifiedUserArray[0];
         }
         return possiblyQualifiedUsername;
     }
 
     /**
-     * Extract domain from the form <code>user</code> or <code>user@domain</code>
+     * Extract domain from the form <code>user</code> or <code>user@domain</code>.
      *
      * @param possiblyQualifiedUsername <code>user</code> or <code>user@domain</code>
      * @return the domain or <code>HttpBasicAuth.DEFAULT_DOMAIN</code>
      */
     public static String extractDomain(final String possiblyQualifiedUsername) {
         if (possiblyQualifiedUsername.contains(USERNAME_DOMAIN_SEPARATOR)) {
-            final String [] qualifiedUserArray = possiblyQualifiedUsername.split(USERNAME_DOMAIN_SEPARATOR);
+            final String[] qualifiedUserArray = possiblyQualifiedUsername.split(USERNAME_DOMAIN_SEPARATOR);
             return qualifiedUserArray[1];
         }
         return HttpBasicAuth.DEFAULT_DOMAIN;
index 5df15f3d2cd2b8a828e02d98e154a8a6eaa663a8..94019ab89ce83363d0b5299006823005a5abbde7 100644 (file)
@@ -7,15 +7,12 @@
  */
 package org.opendaylight.aaa.shiro.tokenauthrealm.auth;
 
-import static org.opendaylight.aaa.shiro.tokenauthrealm.util.EqualUtil.areEqual;
-import static org.opendaylight.aaa.shiro.tokenauthrealm.util.HashCodeUtil.hash;
-
 import java.io.Serializable;
 import java.util.Set;
 import org.opendaylight.aaa.api.Authentication;
 import org.opendaylight.aaa.api.Claim;
-import org.opendaylight.aaa.shiro.tokenauthrealm.util.HashCodeUtil;
 import org.opendaylight.aaa.shiro.tokenauthrealm.util.EqualUtil;
+import org.opendaylight.aaa.shiro.tokenauthrealm.util.HashCodeUtil;
 
 /**
  * A builder for the authentication context.
@@ -100,11 +97,12 @@ public class AuthenticationBuilder {
                 return false;
             }
             Authentication authentication = (Authentication) object;
-            return EqualUtil.areEqual(expiration, authentication.expiration()) && EqualUtil.areEqual(claim.roles(), authentication.roles())
-                    && EqualUtil.areEqual(claim.domain(), authentication.domain())
-                    && EqualUtil.areEqual(claim.userId(), authentication.userId())
-                    && EqualUtil.areEqual(claim.user(), authentication.user())
-                    && EqualUtil.areEqual(claim.clientId(), authentication.clientId());
+            return EqualUtil.areEqual(expiration, authentication.expiration()) && EqualUtil
+                    .areEqual(claim.roles(), authentication.roles()) && EqualUtil
+                    .areEqual(claim.domain(), authentication.domain()) && EqualUtil
+                    .areEqual(claim.userId(), authentication.userId()) && EqualUtil
+                    .areEqual(claim.user(), authentication.user()) && EqualUtil
+                    .areEqual(claim.clientId(), authentication.clientId());
         }
 
         @Override
index aee8aee034273a7a762e5886e366814daf6471c1..0c1fa5749791d36c9b63e0a2f9fa71b953e57cde 100644 (file)
@@ -62,8 +62,8 @@ public class ClaimBuilder {
         return this;
     }
 
-    public ClaimBuilder addRoles(Set<String> roles) {
-        for (String role : roles) {
+    public ClaimBuilder addRoles(Set<String> theRoles) {
+        for (String role : theRoles) {
             addRole(role);
         }
         return this;
index 9e1f07ab9e20445e387bb565d4952080673d0c81..d7d6bdd0753cb26f016d0694fd9f17da264b58a2 100644 (file)
@@ -123,7 +123,7 @@ public class HttpBasicAuth implements TokenAuth {
                     final String message = "Login Attempt in Bad Format."
                             + " Please provide user:password in Base64 format.";
                     LOG.info(message);
-                    throw new AuthenticationException(message);
+                    throw new AuthenticationException(message, e);
                 }
             }
         }
index fcb5193c28c5fde691b145cdb56e1d07d1aa9d0b..d9e2674d62e4864007fbd94baf8b960032d5c8a3 100644 (file)
@@ -7,12 +7,9 @@
  */
 package org.opendaylight.aaa.shiro.tokenauthrealm.auth;
 
-import static org.opendaylight.aaa.shiro.tokenauthrealm.util.EqualUtil.areEqual;
-import static org.opendaylight.aaa.shiro.tokenauthrealm.util.HashCodeUtil.hash;
-
 import org.opendaylight.aaa.api.PasswordCredentials;
-import org.opendaylight.aaa.shiro.tokenauthrealm.util.HashCodeUtil;
 import org.opendaylight.aaa.shiro.tokenauthrealm.util.EqualUtil;
+import org.opendaylight.aaa.shiro.tokenauthrealm.util.HashCodeUtil;
 
 /**
  * {@link PasswordCredentials} builder.
index 170eaaa35baeefa79fb9080eac687c34abc73e03..7ee0a4193c97684b32a493b0602bb445ba5676b0 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
-import org.opendaylight.aaa.shiro.ServiceProxy;
 import org.opendaylight.aaa.shiro.filters.AAAFilter;
 
 public class ServiceProxyTest {
index ff3600785223defb92343502c757e8f17c5e5db4..61c5fed425e1a0a8b9432b1fe32f6efc51a48e90 100644 (file)
@@ -22,7 +22,7 @@ import java.util.Vector;
 public class TestAppender extends AppenderBase<LoggingEvent> {
 
     /**
-     * stores all log events in memory, instead of file
+     * stores all log events in memory, instead of file.
      */
     private List<LoggingEvent> events = new Vector<>();
 
@@ -34,15 +34,15 @@ public class TestAppender extends AppenderBase<LoggingEvent> {
     private static volatile TestAppender currentInstance;
 
     /**
-     * keeps track of the current instance
+     * keeps track of the current instance.
      */
     public TestAppender() {
         currentInstance = this;
     }
 
     @Override
-    protected void append(final LoggingEvent e) {
-        events.add(e);
+    protected void append(final LoggingEvent loggingEvent) {
+        events.add(loggingEvent);
     }
 
     /**
index d3b6844709046e875c12ca6fef030f295050869d..350c08a3c092ba431b0d3ea05fe96336cd7ad6b4 100644 (file)
@@ -8,12 +8,11 @@
 
 package org.opendaylight.aaa.shiro.filters;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
 
 import ch.qos.logback.classic.spi.LoggingEvent;
 
 import java.util.List;
-
 import org.apache.shiro.authc.AuthenticationException;
 import org.apache.shiro.authc.SimpleAuthenticationInfo;
 import org.apache.shiro.authc.UsernamePasswordToken;
index 461283cdd476a07e4b0d3396fb4f4dff726ac8c7..cf462590d85386acc9c50bc4582122d6a08b5e40 100644 (file)
@@ -8,7 +8,9 @@
 
 package org.opendaylight.aaa.shiro.filters;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import org.apache.shiro.authc.AuthenticationToken;
 import org.apache.shiro.authc.UsernamePasswordToken;
index d7e27b0bd8e093575e1a89840775d7cfe9ab671d..f3d4c7a9875e331500740570731acef67a1d0b01 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 /**
  * Tests the Dynamic Authorization Filter.
  */
+@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
 public class MDSALDynamicAuthorizationFilterTest {
 
     @Before
@@ -51,21 +52,25 @@ public class MDSALDynamicAuthorizationFilterTest {
     }
 
     // test helper method to generate some cool mdsal data
-    private DataBroker getTestData(final String resource, final String role,
-                                   final String description, final Permissions.Actions actions) throws Exception {
+    private DataBroker getTestData(final String resource, final String role, final String description,
+                                   final Permissions.Actions actions) throws Exception {
 
         final List<Permissions.Actions> actionsList = Lists.newArrayList(actions);
         final Permissions permissions = mock(Permissions.class);
         when(permissions.getRole()).thenReturn(role);
         when(permissions.getActions()).thenReturn(actionsList);
         final List<Permissions> permissionsList = Lists.newArrayList(permissions);
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies innerPolicies =
-                mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies.class);
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                .policies.Policies
+                innerPolicies = mock(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                        .policies.Policies.class);
         when(innerPolicies.getResource()).thenReturn(resource);
         when(innerPolicies.getDescription()).thenReturn(description);
         when(innerPolicies.getPermissions()).thenReturn(permissionsList);
-        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies> policiesList =
-                Lists.newArrayList(innerPolicies);
+        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                .policies.Policies>
+                policiesList = Lists.newArrayList(innerPolicies);
         final Policies policies = mock(Policies.class);
         when(policies.getPolicies()).thenReturn(policiesList);
         final HttpAuthorization httpAuthorization = mock(HttpAuthorization.class);
@@ -90,8 +95,8 @@ public class MDSALDynamicAuthorizationFilterTest {
         //
         // Ensure that data can be extracted appropriately.
         final DataBroker dataBroker = getTestData();
-        final Optional<HttpAuthorization> httpAuthorizationOptional =
-                MDSALDynamicAuthorizationFilter.getHttpAuthzContainer(dataBroker);
+        final Optional<HttpAuthorization> httpAuthorizationOptional = MDSALDynamicAuthorizationFilter
+                .getHttpAuthzContainer(dataBroker);
 
         assertNotNull(httpAuthorizationOptional);
         final HttpAuthorization authz = httpAuthorizationOptional.get();
@@ -152,8 +157,8 @@ public class MDSALDynamicAuthorizationFilterTest {
 
         final Optional<DataObject> dataObjectOptional = mock(Optional.class);
         when(dataObjectOptional.isPresent()).thenReturn(false);
-        final CheckedFuture<Optional<DataObject>, ReadFailedException> cf =
-                Futures.immediateFailedCheckedFuture(new ReadFailedException("Test Fail"));
+        final CheckedFuture<Optional<DataObject>, ReadFailedException> cf = Futures
+                .immediateFailedCheckedFuture(new ReadFailedException("Test Fail"));
         final ReadOnlyTransaction rot = mock(ReadOnlyTransaction.class);
         when(rot.read(any(), any())).thenReturn(cf);
         final DataBroker dataBroker = mock(DataBroker.class);
@@ -241,9 +246,9 @@ public class MDSALDynamicAuthorizationFilterTest {
         //
         // Create some mock data which has a couple of rules which may/may not match.  This
         // test ensures the correct application of said rules.
-        final List<Permissions.Actions> actionsList = Lists.newArrayList(Permissions.Actions.Get,
-                Permissions.Actions.Delete, Permissions.Actions.Patch, Permissions.Actions.Put,
-                Permissions.Actions.Post);
+        final List<Permissions.Actions> actionsList = Lists
+                .newArrayList(Permissions.Actions.Get, Permissions.Actions.Delete, Permissions.Actions.Patch,
+                              Permissions.Actions.Put, Permissions.Actions.Post);
         final String role = "admin";
         final String resource = "/**";
         final String resource2 = "/specialendpoint/**";
@@ -252,21 +257,28 @@ public class MDSALDynamicAuthorizationFilterTest {
         when(permissions.getRole()).thenReturn(role);
         when(permissions.getActions()).thenReturn(actionsList);
         final List<Permissions> permissionsList = Lists.newArrayList(permissions);
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies innerPolicies =
-                mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies.class);
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                .policies.Policies
+                innerPolicies = mock(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                        .policies.Policies.class);
         when(innerPolicies.getResource()).thenReturn(resource);
         when(innerPolicies.getDescription()).thenReturn(description);
         when(innerPolicies.getPermissions()).thenReturn(permissionsList);
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies innerPolicies2 =
-                mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies.class);
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                .policies.Policies
+                innerPolicies2 = mock(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                        .policies.Policies.class);
         when(innerPolicies2.getResource()).thenReturn(resource2);
         final Permissions permissions2 = mock(Permissions.class);
         when(permissions2.getRole()).thenReturn("dog");
         when(permissions2.getActions()).thenReturn(actionsList);
         when(innerPolicies2.getPermissions()).thenReturn(Lists.newArrayList(permissions2));
         when(innerPolicies2.getDescription()).thenReturn("Specialized Rule");
-        List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies> policiesList =
-                Lists.newArrayList(innerPolicies, innerPolicies2);
+        List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                .policies.Policies>
+                policiesList = Lists.newArrayList(innerPolicies, innerPolicies2);
         final Policies policies = mock(Policies.class);
         when(policies.getPolicies()).thenReturn(policiesList);
         final HttpAuthorization httpAuthorization = mock(HttpAuthorization.class);
@@ -337,10 +349,9 @@ public class MDSALDynamicAuthorizationFilterTest {
         final String role = "admin";
         final String resource = "/**";
         final String description = "Test description";
-        final List<Permissions.Actions> actionsList = Lists.newArrayList(
-                Permissions.Actions.Get, Permissions.Actions.Put, Permissions.Actions.Delete,
-                Permissions.Actions.Patch, Permissions.Actions.Post
-        );
+        final List<Permissions.Actions> actionsList = Lists
+                .newArrayList(Permissions.Actions.Get, Permissions.Actions.Put, Permissions.Actions.Delete,
+                              Permissions.Actions.Patch, Permissions.Actions.Post);
         final Permissions permissions = mock(Permissions.class);
         when(permissions.getRole()).thenReturn(role);
         when(permissions.getActions()).thenReturn(actionsList);
@@ -348,13 +359,17 @@ public class MDSALDynamicAuthorizationFilterTest {
         when(permissions2.getRole()).thenReturn("user");
         when(permissions2.getActions()).thenReturn(Lists.newArrayList(Permissions.Actions.Get));
         final List<Permissions> permissionsList = Lists.newArrayList(permissions, permissions2);
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies innerPolicies =
-                mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies.class);
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                .policies.Policies
+                innerPolicies = mock(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                        .policies.Policies.class);
         when(innerPolicies.getResource()).thenReturn(resource);
         when(innerPolicies.getDescription()).thenReturn(description);
         when(innerPolicies.getPermissions()).thenReturn(permissionsList);
-        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization.policies.Policies> policiesList =
-                Lists.newArrayList(innerPolicies);
+        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.aaa.rev161214.http.authorization
+                .policies.Policies>
+                policiesList = Lists.newArrayList(innerPolicies);
         final Policies policies = mock(Policies.class);
         when(policies.getPolicies()).thenReturn(policiesList);
         final HttpAuthorization httpAuthorization = mock(HttpAuthorization.class);
index 87fa2127490c8cbbc11b04b7135a01701cf98ff6..665d2cdb59db4c0d8ef2f4827d93b6620ca1692a 100644 (file)
@@ -39,13 +39,11 @@ import org.junit.Test;
 public class ODLJndiLdapRealmTest {
 
     /**
-     * throw-away anonymous test class
+     * throw-away anonymous test class.
      */
     class TestNamingEnumeration implements NamingEnumeration<SearchResult> {
 
-        /**
-         * state variable
-         */
+        // State variable
         boolean first = true;
 
         /**
@@ -56,7 +54,7 @@ public class ODLJndiLdapRealmTest {
                 "objectClass", "engineering"));
 
         /**
-         * returns true the first time, then false for subsequent calls
+         * returns true the first time, then false for subsequent calls.
          */
         @Override
         public boolean hasMoreElements() {
@@ -64,7 +62,7 @@ public class ODLJndiLdapRealmTest {
         }
 
         /**
-         * returns <code>searchResult</code> then null for subsequent calls
+         * returns <code>searchResult</code> then null for subsequent calls.
          */
         @Override
         public SearchResult nextElement() {
@@ -76,14 +74,14 @@ public class ODLJndiLdapRealmTest {
         }
 
         /**
-         * does nothing because close() doesn't require any special behavior
+         * does nothing because close() doesn't require any special behavior.
          */
         @Override
         public void close() throws NamingException {
         }
 
         /**
-         * returns true the first time, then false for subsequent calls
+         * returns true the first time, then false for subsequent calls.
          */
         @Override
         public boolean hasMore() throws NamingException {
@@ -91,7 +89,7 @@ public class ODLJndiLdapRealmTest {
         }
 
         /**
-         * returns <code>searchResult</code> then null for subsequent calls
+         * returns <code>searchResult</code> then null for subsequent calls.
          */
         @Override
         public SearchResult next() throws NamingException {
@@ -101,22 +99,19 @@ public class ODLJndiLdapRealmTest {
             }
             return null;
         }
-    };
+    }
 
     /**
-     * throw away test class
+     * throw away test class.
      *
      * @author ryan
      */
     class TestPrincipalCollection implements PrincipalCollection {
-        /**
-     *
-     */
         private static final long serialVersionUID = -1236759619455574475L;
 
         Vector<String> collection = new Vector<String>();
 
-        public TestPrincipalCollection(String element) {
+        TestPrincipalCollection(String element) {
             collection.add(element);
         }
 
@@ -167,7 +162,7 @@ public class ODLJndiLdapRealmTest {
             // TODO Auto-generated method stub
             return null;
         }
-    };
+    }
 
     @Test
     public void testGetUsernameAuthenticationToken() {
index 56c108268caf260d5181ff4a523a06f457f08466..c5adb5ee9defde0cf0397268ed7c79b6f599ae06 100644 (file)
@@ -54,7 +54,8 @@ public class TokenAuthRealmTest {
         final String password = "password";
         final String domain = "domain";
         final String expectedUsernamePasswordString = "user:password:domain";
-        assertEquals(expectedUsernamePasswordString, HeaderUtils.getUsernamePasswordDomainString(username, password, domain));
+        assertEquals(expectedUsernamePasswordString, HeaderUtils.getUsernamePasswordDomainString(
+                username, password, domain));
     }
 
     @Test
@@ -67,8 +68,8 @@ public class TokenAuthRealmTest {
 
     @Test
     public void testGetTokenAuthHeader() {
-        final String encodedCredentials = HeaderUtils.getEncodedToken(HeaderUtils.getUsernamePasswordDomainString("user1",
-                "password", "sdn"));
+        final String encodedCredentials = HeaderUtils.getEncodedToken(HeaderUtils.getUsernamePasswordDomainString(
+                "user1", "password", "sdn"));
         final String expectedTokenAuthHeader = "Basic " + encodedCredentials;
         assertEquals(expectedTokenAuthHeader, HeaderUtils.getTokenAuthHeader(encodedCredentials));
     }
index e626823e5d9ff2f0382f3e5a95ef0883e0973254..aa416da841aceae861ded3265c041c8795457a93 100644 (file)
@@ -8,7 +8,8 @@
 
 package org.opendaylight.aaa.shiro.realm.mapping.impl;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
index 65813c928a3489db5814db8b92cf4f9d6cf8bcdc..6660359e9701809755445cbd5d7b96f15b704b8f 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.aaa.shiro.realm.util.http;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 
 import com.sun.jersey.api.client.Client;