This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit f83eae67d88224c05b780255b832f68ae6531ad6
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jun 24 16:42:28 2019 +0100

    Clean-up. No functional change.
---
 .../apache/catalina/realm/UserDatabaseRealm.java   | 95 +++++++++-------------
 1 file changed, 39 insertions(+), 56 deletions(-)

diff --git a/java/org/apache/catalina/realm/UserDatabaseRealm.java 
b/java/org/apache/catalina/realm/UserDatabaseRealm.java
index 9ec96af..064ac59 100644
--- a/java/org/apache/catalina/realm/UserDatabaseRealm.java
+++ b/java/org/apache/catalina/realm/UserDatabaseRealm.java
@@ -14,11 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina.realm;
 
-
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -34,31 +31,26 @@ import org.apache.catalina.UserDatabase;
 import org.apache.catalina.Wrapper;
 import org.apache.tomcat.util.ExceptionUtils;
 
-
 /**
- * <p>Implementation of {@link org.apache.catalina.Realm} that is based on an 
implementation of
- * {@link UserDatabase} made available through the global JNDI resources
- * configured for this instance of Catalina.  Set the <code>resourceName</code>
- * parameter to the global JNDI resources name for the configured instance
- * of <code>UserDatabase</code> that we should consult.</p>
+ * Implementation of {@link org.apache.catalina.Realm} that is based on an
+ * implementation of {@link UserDatabase} made available through the global 
JNDI
+ * resources configured for this instance of Catalina. Set the
+ * <code>resourceName</code> parameter to the global JNDI resources name for 
the
+ * configured instance of <code>UserDatabase</code> that we should consult.
  *
  * @author Craig R. McClanahan
  * @since 4.1
  */
-public class UserDatabaseRealm
-    extends RealmBase {
-
+public class UserDatabaseRealm extends RealmBase {
 
     // ----------------------------------------------------- Instance Variables
 
-
     /**
-     * The <code>UserDatabase</code> we will use to authenticate users
-     * and identify associated roles.
+     * The <code>UserDatabase</code> we will use to authenticate users and
+     * identify associated roles.
      */
     protected UserDatabase database = null;
 
-
     /**
      * Descriptive information about this Realm implementation.
      * @deprecated This will be removed in Tomcat 9 onwards.
@@ -68,8 +60,8 @@ public class UserDatabaseRealm
 
 
     /**
-     * The global JNDI name of the <code>UserDatabase</code> resource
-     * we will be utilizing.
+     * The global JNDI name of the <code>UserDatabase</code> resource we will 
be
+     * utilizing.
      */
     protected String resourceName = "UserDatabase";
 
@@ -77,38 +69,33 @@ public class UserDatabaseRealm
     // ------------------------------------------------------------- Properties
 
     /**
-     * @return the global JNDI name of the <code>UserDatabase</code> resource
-     * we will be using.
+     * @return the global JNDI name of the <code>UserDatabase</code> resource 
we
+     *         will be using.
      */
     public String getResourceName() {
-
         return resourceName;
-
     }
 
 
     /**
-     * Set the global JNDI name of the <code>UserDatabase</code> resource
-     * we will be using.
+     * Set the global JNDI name of the <code>UserDatabase</code> resource we
+     * will be using.
      *
      * @param resourceName The new global JNDI name
      */
     public void setResourceName(String resourceName) {
-
         this.resourceName = resourceName;
-
     }
 
 
     // --------------------------------------------------------- Public Methods
 
-
     /**
      * Return <code>true</code> if the specified Principal has the specified
      * security role, within the context of this Realm; otherwise return
-     * <code>false</code>. This implementation returns <code>true</code>
-     * if the <code>User</code> has the role, or if any <code>Group</code>
-     * that the <code>User</code> is a member of has the role.
+     * <code>false</code>. This implementation returns <code>true</code> if the
+     * <code>User</code> has the role, or if any <code>Group</code> that the
+     * <code>User</code> is a member of has the role.
      *
      * @param principal Principal for whom the role is to be checked
      * @param role Security role to be checked
@@ -121,41 +108,41 @@ public class UserDatabaseRealm
             if (realRole != null)
                 role = realRole;
         }
-        if( principal instanceof GenericPrincipal) {
-            GenericPrincipal gp = (GenericPrincipal)principal;
-            if(gp.getUserPrincipal() instanceof User) {
+        if (principal instanceof GenericPrincipal) {
+            GenericPrincipal gp = (GenericPrincipal) principal;
+            if (gp.getUserPrincipal() instanceof User) {
                 principal = gp.getUserPrincipal();
             }
         }
-        if(! (principal instanceof User) ) {
-            //Play nice with SSO and mixed Realms
+        if (!(principal instanceof User)) {
+            // Play nice with SSO and mixed Realms
             return super.hasRole(null, principal, role);
         }
-        if("*".equals(role)) {
+        if ("*".equals(role)) {
             return true;
-        } else if(role == null) {
+        } else if (role == null) {
             return false;
         }
-        User user = (User)principal;
+        User user = (User) principal;
         Role dbrole = database.findRole(role);
-        if(dbrole == null) {
+        if (dbrole == null) {
             return false;
         }
-        if(user.isInRole(dbrole)) {
+        if (user.isInRole(dbrole)) {
             return true;
         }
         Iterator<Group> groups = user.getGroups();
-        while(groups.hasNext()) {
+        while (groups.hasNext()) {
             Group group = groups.next();
-            if(group.isInRole(dbrole)) {
+            if (group.isInRole(dbrole)) {
                 return true;
             }
         }
         return false;
     }
 
-    // ------------------------------------------------------ Protected Methods
 
+    // ------------------------------------------------------ Protected Methods
 
     @Override
     @Deprecated
@@ -186,21 +173,21 @@ public class UserDatabaseRealm
     protected Principal getPrincipal(String username) {
 
         User user = database.findUser(username);
-        if(user == null) {
+        if (user == null) {
             return null;
         }
 
         List<String> roles = new ArrayList<>();
         Iterator<Role> uroles = user.getRoles();
-        while(uroles.hasNext()) {
+        while (uroles.hasNext()) {
             Role role = uroles.next();
             roles.add(role.getName());
         }
         Iterator<Group> groups = user.getGroups();
-        while(groups.hasNext()) {
+        while (groups.hasNext()) {
             Group group = groups.next();
             uroles = group.getRoles();
-            while(uroles.hasNext()) {
+            while (uroles.hasNext()) {
                 Role role = uroles.next();
                 roles.add(role.getName());
             }
@@ -211,14 +198,13 @@ public class UserDatabaseRealm
 
     // ------------------------------------------------------ Lifecycle Methods
 
-
     /**
      * Prepare for the beginning of active use of the public methods of this
      * component and implement the requirements of
      * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
      *
      * @exception LifecycleException if this component detects a fatal error
-     *  that prevents this component from being used
+     *                that prevents this component from being used
      */
     @Override
     protected void startInternal() throws LifecycleException {
@@ -228,14 +214,12 @@ public class UserDatabaseRealm
             database = (UserDatabase) context.lookup(resourceName);
         } catch (Throwable e) {
             ExceptionUtils.handleThrowable(e);
-            containerLog.error(sm.getString("userDatabaseRealm.lookup",
-                                            resourceName),
-                               e);
+            containerLog.error(sm.getString("userDatabaseRealm.lookup", 
resourceName), e);
             database = null;
         }
         if (database == null) {
-            throw new LifecycleException
-                (sm.getString("userDatabaseRealm.noDatabase", resourceName));
+            throw new LifecycleException(
+                    sm.getString("userDatabaseRealm.noDatabase", 
resourceName));
         }
 
         super.startInternal();
@@ -248,7 +232,7 @@ public class UserDatabaseRealm
      * {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
      *
      * @exception LifecycleException if this component detects a fatal error
-     *  that needs to be reported
+     *                that needs to be reported
      */
     @Override
     protected void stopInternal() throws LifecycleException {
@@ -258,6 +242,5 @@ public class UserDatabaseRealm
 
         // Release reference to our user database
         database = null;
-
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to