Author: angela
Date: Mon Apr 15 11:20:24 2019
New Revision: 1857565

URL: http://svn.apache.org/viewvc?rev=1857565&view=rev
Log:
OAK-8231 : Unreachable code in LoginModuleImpl.getLoginId

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImpl.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImplTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImpl.java?rev=1857565&r1=1857564&r2=1857565&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImpl.java
 Mon Apr 15 11:20:24 2019
@@ -203,27 +203,16 @@ public final class LoginModuleImpl exten
         }
 
         String uid = null;
-        if (credentials != null) {
-            if (credentials instanceof SimpleCredentials) {
-                uid = ((SimpleCredentials) credentials).getUserID();
-            } else if (credentials instanceof GuestCredentials) {
-                uid = getAnonymousId();
-            } else if (credentials instanceof ImpersonationCredentials) {
-                Credentials bc = ((ImpersonationCredentials) 
credentials).getBaseCredentials();
-                if (bc instanceof SimpleCredentials) {
-                    uid = ((SimpleCredentials) bc).getUserID();
-                }
-            } else {
-                try {
-                    NameCallback callback = new NameCallback("User-ID: ");
-                    callbackHandler.handle(new Callback[] { callback });
-                    uid = callback.getName();
-                } catch (IOException | UnsupportedCallbackException e) {
-                    onError();
-                    log.error(e.getMessage(), e);
-                }
+        if (credentials instanceof SimpleCredentials) {
+            uid = ((SimpleCredentials) credentials).getUserID();
+        } else if (credentials instanceof GuestCredentials) {
+            uid = getAnonymousId();
+        } else if (credentials instanceof ImpersonationCredentials) {
+            Credentials bc = ((ImpersonationCredentials) 
credentials).getBaseCredentials();
+            if (bc instanceof SimpleCredentials) {
+                uid = ((SimpleCredentials) bc).getUserID();
             }
-        }
+        } // null or other (unsupported) type of credentials (see 
SUPPORTED_CREDENTIALS)
 
         if (uid == null) {
             uid = getSharedLoginName();

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImplTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImplTest.java?rev=1857565&r1=1857564&r2=1857565&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImplTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImplTest.java
 Mon Apr 15 11:20:24 2019
@@ -35,6 +35,7 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.authentication.ConfigurationUtil;
 import 
org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials;
 import 
org.apache.jackrabbit.oak.spi.security.authentication.PreAuthenticatedLogin;
+import 
org.apache.jackrabbit.oak.spi.security.authentication.callback.CredentialsCallback;
 import 
org.apache.jackrabbit.oak.spi.security.authentication.callback.RepositoryCallback;
 import org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory;
 import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
@@ -254,6 +255,29 @@ public class LoginModuleImplTest extends
     }
 
     @Test
+    public void LoginUnsupportedCredentials() throws Exception {
+        Credentials unsupportedCredentials = mock(Credentials.class);
+
+        CallbackHandler cbh = callbacks -> {
+            for (Callback callback : callbacks) {
+                if (callback instanceof RepositoryCallback) {
+                    ((RepositoryCallback) 
callback).setSecurityProvider(getSecurityProvider());
+                    ((RepositoryCallback) 
callback).setContentRepository(getContentRepository());
+                } else if (callback instanceof CredentialsCallback) {
+                    ((CredentialsCallback) 
callback).setCredentials(unsupportedCredentials);
+                } else {
+                    throw new UnsupportedCallbackException(callback);
+                }
+            }
+        };
+
+        Subject subject = new Subject(false, ImmutableSet.of(), 
ImmutableSet.of(unsupportedCredentials), ImmutableSet.of());
+        LoginModuleImpl lm = new LoginModuleImpl();
+        lm.initialize(subject, cbh, Maps.newHashMap(), Maps.newHashMap());
+        assertFalse(lm.login());
+    }
+
+    @Test
     public void testLoginPreAuthenticated() throws Exception {
         Authentication authentication = mock(Authentication.class);
         
when(authentication.authenticate(any(Credentials.class))).thenReturn(true).getMock();


Reply via email to