You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/08/04 09:53:55 UTC

[isis] branch v2 updated: ISIS-2156 minor refactoring

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

ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/v2 by this push:
     new d363b22  ISIS-2156 minor refactoring
d363b22 is described below

commit d363b22c300f270fe45111a7f3fbfb0ee068055b
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun Aug 4 11:53:37 2019 +0200

    ISIS-2156 minor refactoring
---
 .../shiro/authentication/ShiroAuthenticator.java   |  1 +
 .../AuthenticationSessionStrategyBasicAuth.java    |  2 +-
 .../standard/AuthenticationManagerStandard.java    | 15 +++++---
 .../standard/AuthenticatorFuncs.java               | 40 ----------------------
 4 files changed, 12 insertions(+), 46 deletions(-)

diff --git a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticator.java b/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticator.java
index e51681e..420609a 100644
--- a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticator.java
+++ b/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticator.java
@@ -105,6 +105,7 @@ public class ShiroAuthenticator implements Authenticator {
         if(securityManager == null) {
             return null;
         }
+        
         final AuthenticationToken token = asAuthenticationToken(request);
 
         final Subject currentSubject = SecurityUtils.getSubject();
diff --git a/core/runtime-web/src/main/java/org/apache/isis/webapp/auth/AuthenticationSessionStrategyBasicAuth.java b/core/runtime-web/src/main/java/org/apache/isis/webapp/auth/AuthenticationSessionStrategyBasicAuth.java
index 24db9e1..eb5e5b9 100644
--- a/core/runtime-web/src/main/java/org/apache/isis/webapp/auth/AuthenticationSessionStrategyBasicAuth.java
+++ b/core/runtime-web/src/main/java/org/apache/isis/webapp/auth/AuthenticationSessionStrategyBasicAuth.java
@@ -49,9 +49,9 @@ public class AuthenticationSessionStrategyBasicAuth extends AuthenticationSessio
             final HttpServletRequest httpServletRequest, 
             final HttpServletResponse httpServletResponse) {
 
-        //FIXME[2156] do this somewhere else (more coupled with shiro) 
         // Basic auth should never create sessions! 
         // However, telling this Shiro here, is a fragile approach.
+        //TODO[2156] do this somewhere else (more coupled with shiro)
         httpServletRequest.setAttribute(
                 "org.apache.shiro.subject.support.DefaultSubjectContext.SESSION_CREATION_ENABLED", 
                 Boolean.FALSE);
diff --git a/core/security/src/main/java/org/apache/isis/security/authentication/standard/AuthenticationManagerStandard.java b/core/security/src/main/java/org/apache/isis/security/authentication/standard/AuthenticationManagerStandard.java
index d025b5a..b7de778 100644
--- a/core/security/src/main/java/org/apache/isis/security/authentication/standard/AuthenticationManagerStandard.java
+++ b/core/security/src/main/java/org/apache/isis/security/authentication/standard/AuthenticationManagerStandard.java
@@ -19,7 +19,6 @@
 
 package org.apache.isis.security.authentication.standard;
 
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -31,6 +30,7 @@ import javax.inject.Inject;
 import org.apache.isis.applib.services.registry.ServiceRegistry;
 import org.apache.isis.applib.util.ToString;
 import org.apache.isis.commons.exceptions.IsisException;
+import org.apache.isis.commons.internal.base._NullSafe;
 import org.apache.isis.commons.internal.collections._Lists;
 import org.apache.isis.commons.internal.collections._Maps;
 import org.apache.isis.security.authentication.AuthenticationRequest;
@@ -104,25 +104,30 @@ public class AuthenticationManagerStandard implements AuthenticationManager {
 
     @Override
     public synchronized final AuthenticationSession authenticate(final AuthenticationRequest request) {
+        
         if (request == null) {
             return null;
         }
 
-        final Collection<Authenticator> compatibleAuthenticators = 
-                _Lists.filter(authenticators, AuthenticatorFuncs.compatibleWith(request));
+        val compatibleAuthenticators = _NullSafe.stream(authenticators)
+                .filter(authenticator->authenticator.canAuthenticate(request.getClass()))
+                .collect(Collectors.toList());
+                
         if (compatibleAuthenticators.size() == 0) {
             throw new NoAuthenticatorException("No authenticator available for processing " + request.getClass().getName());
         }
+        
         for (final Authenticator authenticator : compatibleAuthenticators) {
-            final AuthenticationSession authSession = authenticator.authenticate(request, getUnusedRandomCode());
+            val authSession = authenticator.authenticate(request, getUnusedRandomCode());
             if (authSession != null) {
                 userByValidationCode.put(authSession.getValidationCode(), authSession.getUserName());
                 return authSession;
             }
         }
+        
         return null;
     }
-
+    
     private String getUnusedRandomCode() {
         String code;
         do {
diff --git a/core/security/src/main/java/org/apache/isis/security/authentication/standard/AuthenticatorFuncs.java b/core/security/src/main/java/org/apache/isis/security/authentication/standard/AuthenticatorFuncs.java
deleted file mode 100644
index b8a5273..0000000
--- a/core/security/src/main/java/org/apache/isis/security/authentication/standard/AuthenticatorFuncs.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-
-package org.apache.isis.security.authentication.standard;
-
-import java.util.function.Predicate;
-
-import org.apache.isis.security.authentication.AuthenticationRequest;
-
-public final class AuthenticatorFuncs {
-
-    private AuthenticatorFuncs() {
-    }
-
-    public static Predicate<Authenticator> compatibleWith(final AuthenticationRequest request) {
-        return new Predicate<Authenticator>() {
-            @Override
-            public boolean test(final Authenticator authenticator) {
-                return authenticator.canAuthenticate(request.getClass());
-            }
-        };
-    }
-
-}