Fix various warnings 02/94402/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Jan 2021 13:04:33 +0000 (14:04 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Jan 2021 13:36:57 +0000 (14:36 +0100)
Cleanup isFoo() callers and perform some drive-by cleanups.

Change-Id: I5c6f6330d9156e9d3804b5e9fe6e212b7f5f3d7d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
aaa-cert/src/main/java/org/opendaylight/aaa/cert/impl/AaaCertRpcServiceImpl.java
aaa-cert/src/main/java/org/opendaylight/aaa/cert/impl/CertificateManagerService.java
aaa-cert/src/test/java/org/opendaylight/aaa/cert/test/AaaCertRpcServiceImplTest.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/ODLJndiLdapRealm.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/filters/AuthenticationTokenUtilsTest.java

index b662b1d416e10fc4ff871e69d77a0e4691d736d7..7078317656dcb354bc5b375bc34b8bcaf1ee3902 100644 (file)
@@ -53,8 +53,8 @@ public class AaaCertRpcServiceImpl implements AaaCertRpcService {
 
     public AaaCertRpcServiceImpl(final AaaCertServiceConfig aaaCertServiceConfig, final DataBroker dataBroker,
             final AAAEncryptionService encryptionSrv) {
-        if (aaaCertServiceConfig.isUseConfig()) {
-            if (aaaCertServiceConfig.isUseMdsal()) {
+        if (aaaCertServiceConfig.getUseConfig()) {
+            if (aaaCertServiceConfig.getUseMdsal()) {
                 aaaCertProvider = new DefaultMdsalSslData(new AaaCertMdsalProvider(dataBroker, encryptionSrv),
                         aaaCertServiceConfig.getBundleName(), aaaCertServiceConfig.getCtlKeystore(),
                         aaaCertServiceConfig.getTrustKeystore());
index 79cc53318c0bfe447f184a64d706a026a8952fe0..df51257fb658e2f8ab373aa529e9c8d258378f93 100644 (file)
@@ -66,7 +66,7 @@ public class CertificateManagerService implements ICertificateManager {
         if (aaaCertServiceConfig == null) {
             throw new IllegalArgumentException("Certificate Manager service configuration is null");
         }
-        if (aaaCertServiceConfig.isUseConfig()) {
+        if (aaaCertServiceConfig.getUseConfig()) {
             if (aaaCertServiceConfig.getCtlKeystore() != null
                     && aaaCertServiceConfig.getCtlKeystore().getStorePassword() != null
                     && aaaCertServiceConfig.getCtlKeystore().getStorePassword().isEmpty()) {
@@ -81,7 +81,7 @@ public class CertificateManagerService implements ICertificateManager {
                 aaaCertServiceConfig = new AaaCertServiceConfigBuilder(aaaCertServiceConfig).setCtlKeystore(ctlKeystore)
                         .setTrustKeystore(trustKeystore).build();
             }
-            if (aaaCertServiceConfig.isUseMdsal()) {
+            if (aaaCertServiceConfig.getUseMdsal()) {
                 aaaCertProvider = new DefaultMdsalSslData(new AaaCertMdsalProvider(dataBroker, encryptionSrv),
                         aaaCertServiceConfig.getBundleName(), aaaCertServiceConfig.getCtlKeystore(),
                         aaaCertServiceConfig.getTrustKeystore());
index e7792062e3f159895a1eabb035efaaa392846f3e..e2786a522d5c8b17f3c673993aa948d928838fe8 100644 (file)
@@ -109,8 +109,8 @@ public class AaaCertRpcServiceImplTest {
         aaaEncryptionService = aaaEncryptionServiceInit;
 
         final AaaCertServiceConfig aaaCertServiceConfigInit = mock(AaaCertServiceConfig.class);
-        when(aaaCertServiceConfigInit.isUseConfig()).thenReturn(true);
-        when(aaaCertServiceConfigInit.isUseMdsal()).thenReturn(true);
+        when(aaaCertServiceConfigInit.getUseConfig()).thenReturn(true);
+        when(aaaCertServiceConfigInit.getUseMdsal()).thenReturn(true);
         when(aaaCertServiceConfigInit.getBundleName()).thenReturn(BUNDLE_NAME);
         aaaCertServiceConfig = aaaCertServiceConfigInit;
 
index 6b11845b0738709e46ac7ce0814a8610ca8e8cac..b5cfabba76e257f90c2ae9a111bfcd86bb659975 100644 (file)
@@ -141,7 +141,7 @@ public class MdsalRealm extends AuthorizingRealm implements Destroyable {
                 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();
+                final boolean userEnabled = u.getEnabled();
                 if (!userEnabled) {
                     LOG.trace("userId={} is skipped because it is disabled", u.getUserid());
                 }
index 1b11767204d1bc392e623c2686a214b4b94c922e..7f8beaa4003c815046a4c06e317b9240e0525a33 100644 (file)
@@ -126,8 +126,8 @@ public class ODLJndiLdapRealm extends DefaultLdapRealm {
      * .apache.shiro.authc.AuthenticationToken)
      */
     @Override
-    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
-
+    protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token)
+            throws AuthenticationException {
         // Delegates all AuthN lookup responsibility to the super class
         try {
             final String username = getUsername(token);
@@ -135,8 +135,8 @@ public class ODLJndiLdapRealm extends DefaultLdapRealm {
             return super.doGetAuthenticationInfo(token);
         } catch (ClassCastException e) {
             LOG.info("Couldn't service the LDAP connection", e);
+            return null;
         }
-        return null;
     }
 
     /**
@@ -156,11 +156,8 @@ public class ODLJndiLdapRealm extends DefaultLdapRealm {
      * @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) {
-            return null;
-        }
-        return (String) token.getPrincipal();
+    public static String getUsername(final AuthenticationToken token) throws ClassCastException {
+        return token == null ? null : (String) token.getPrincipal();
     }
 
     /**
@@ -172,15 +169,11 @@ public class ODLJndiLdapRealm extends DefaultLdapRealm {
      *                            username/password form (i.e., X.509 certificate)
      */
     protected String getUsername(final PrincipalCollection principals) throws ClassCastException {
-
-        if (null == principals) {
-            return null;
-        }
-        return (String) getAvailablePrincipal(principals);
+        return principals == null ? null : (String) getAvailablePrincipal(principals);
     }
 
     @Override
-    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
+    protected AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) {
 
         AuthorizationInfo ai = null;
         try {
@@ -204,9 +197,8 @@ public class ODLJndiLdapRealm extends DefaultLdapRealm {
      * .PrincipalCollection, org.apache.shiro.realm.ldap.LdapContextFactory)
      */
     @Override
-    protected AuthorizationInfo queryForAuthorizationInfo(PrincipalCollection principals,
-                                                          LdapContextFactory ldapContextFactory) throws
-            NamingException {
+    protected AuthorizationInfo queryForAuthorizationInfo(final PrincipalCollection principals,
+            final LdapContextFactory ldapContextFactory) throws NamingException {
 
         AuthorizationInfo authorizationInfo = null;
         try {
@@ -227,10 +219,7 @@ public class ODLJndiLdapRealm extends DefaultLdapRealm {
     }
 
     public static AuthorizationInfo buildAuthorizationInfo(final Set<String> roleNames) {
-        if (null == roleNames) {
-            return null;
-        }
-        return new SimpleAuthorizationInfo(roleNames);
+        return roleNames == null ? null : new SimpleAuthorizationInfo(roleNames);
     }
 
     /**
@@ -242,8 +231,8 @@ public class ODLJndiLdapRealm extends DefaultLdapRealm {
      * @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<>();
         final SearchControls searchControls = createSearchControls();
@@ -264,7 +253,7 @@ public class ODLJndiLdapRealm extends DefaultLdapRealm {
                     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
+                        final Map<String, Set<String>> groupsToRoles = GROUPS_TO_ROLES_MAPPING_STRATEGY
                                 .mapGroupsToRoles(groupNamesExtractedFromLdap, ROLE_NAMES_DELIMITER, groupRolesMap);
 
                         final Collection<String> roleNamesFromLdapGroups;
index cf462590d85386acc9c50bc4582122d6a08b5e40..6b007b51a15959a5c888816740daec7b3644e2ea 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.aaa.shiro.filters;
 
 import static org.junit.Assert.assertEquals;
@@ -20,11 +19,11 @@ import org.junit.Test;
  * Tests authentication token output utilities.
  */
 public class AuthenticationTokenUtilsTest {
-
     /**
      * A sample non-UsernamePasswordToken implementation for testing.
      */
     private final class NotUsernamePasswordToken implements AuthenticationToken {
+        private static final long serialVersionUID = -1L;
 
         @Override
         public Object getPrincipal() {