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 2018/12/17 21:04:22 UTC
[isis] 04/04: ISIS-2040: Add stub classes for new module
'security-pac4j'.
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
commit 8920b67dc37e39192fd15b0e0ff42d4ea460e316
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Dec 17 21:58:57 2018 +0100
ISIS-2040: Add stub classes for new module 'security-pac4j'.
Task-Url: https://issues.apache.org/jira/browse/ISIS-2040
---
core/plugins/security-pac4j/pom.xml | 2 +-
.../Pac4jAuthenticationManagerInstaller.java} | 11 ++--
.../pac4j/authentication/Pac4jAuthenticator.java | 72 ++++++++++++++++++++++
.../Pac4jAuthorizationManagerInstaller.java} | 22 +++----
.../pac4j/authorization/Pac4jAuthorizor.java | 66 ++++++++++++++++++++
.../ShiroAuthenticationManagerInstaller.java | 2 +-
core/pom.xml | 7 +++
.../core/runtime/system/context/IsisContext.java | 10 +++
...sisComponentProviderHelper_UsingInstallers.java | 8 ++-
9 files changed, 177 insertions(+), 23 deletions(-)
diff --git a/core/plugins/security-pac4j/pom.xml b/core/plugins/security-pac4j/pom.xml
index c939ef3..46f312d 100644
--- a/core/plugins/security-pac4j/pom.xml
+++ b/core/plugins/security-pac4j/pom.xml
@@ -67,7 +67,7 @@
<dependency>
<groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-commons</artifactId>
+ <artifactId>isis-core-security</artifactId>
<scope>compile</scope>
</dependency>
diff --git a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java b/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authentication/Pac4jAuthenticationManagerInstaller.java
similarity index 78%
copy from core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java
copy to core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authentication/Pac4jAuthenticationManagerInstaller.java
index a6a1d41..3a978c5 100644
--- a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java
+++ b/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authentication/Pac4jAuthenticationManagerInstaller.java
@@ -16,26 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.security.shiro.authentication;
+package org.apache.isis.security.pac4j.authentication;
import java.util.List;
import org.apache.isis.commons.internal.collections._Lists;
import org.apache.isis.core.security.authentication.manager.AuthenticationManagerStandardInstallerAbstractForDfltRuntime;
import org.apache.isis.core.security.authentication.standard.Authenticator;
-import org.apache.isis.security.shiro.ShiroAuthenticatorOrAuthorizor;
-public class ShiroAuthenticationManagerInstaller
+public class Pac4jAuthenticationManagerInstaller
extends AuthenticationManagerStandardInstallerAbstractForDfltRuntime {
- public static String NAME = "shiro";
+ public static String NAME = "pac4j";
- public ShiroAuthenticationManagerInstaller() {
+ public Pac4jAuthenticationManagerInstaller() {
super(NAME);
}
@Override
protected List<Authenticator> createAuthenticators() {
- return _Lists.<Authenticator> of(new ShiroAuthenticatorOrAuthorizor());
+ return _Lists.singleton(new Pac4jAuthenticator());
}
}
diff --git a/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authentication/Pac4jAuthenticator.java b/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authentication/Pac4jAuthenticator.java
new file mode 100644
index 0000000..bac47dd
--- /dev/null
+++ b/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authentication/Pac4jAuthenticator.java
@@ -0,0 +1,72 @@
+/*
+ * 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.pac4j.authentication;
+
+import org.apache.isis.commons.internal.exceptions._Exceptions;
+import org.apache.isis.core.security.authentication.AuthenticationRequest;
+import org.apache.isis.core.security.authentication.AuthenticationSession;
+import org.apache.isis.core.security.authentication.standard.Authenticator;
+
+public class Pac4jAuthenticator implements Authenticator {
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ System.out.println("!!! Pac4jAuthenticator.init");
+ }
+
+ @Override
+ public void shutdown() {
+ // TODO Auto-generated method stub
+
+ System.out.println("!!! Pac4jAuthenticator.shutdown");
+
+ }
+
+ @Override
+ public boolean canAuthenticate(Class<? extends AuthenticationRequest> authenticationRequestClass) {
+ // TODO Auto-generated method stub
+
+ System.out.println("!!! Pac4jAuthenticator.canAuthenticate authenticationRequestClass="+authenticationRequestClass);
+
+
+ _Exceptions.dumpStackTrace(System.out, 0, 1000);
+
+ return true;
+ }
+
+ @Override
+ public AuthenticationSession authenticate(AuthenticationRequest request, String code) {
+
+ System.out.println("!!! Pac4jAuthenticator.authenticate request=" + request + ", code="+code);
+
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void logout(AuthenticationSession session) {
+ // TODO Auto-generated method stub
+
+ System.out.println("!!! Pac4jAuthenticator.logout session="+session);
+
+ }
+
+}
diff --git a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java b/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authorization/Pac4jAuthorizationManagerInstaller.java
similarity index 53%
copy from core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java
copy to core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authorization/Pac4jAuthorizationManagerInstaller.java
index a6a1d41..9115ca9 100644
--- a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java
+++ b/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authorization/Pac4jAuthorizationManagerInstaller.java
@@ -16,26 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.security.shiro.authentication;
+package org.apache.isis.security.pac4j.authorization;
-import java.util.List;
+import org.apache.isis.core.security.authorization.standard.AuthorizationManagerStandardInstallerAbstract;
+import org.apache.isis.core.security.authorization.standard.Authorizor;
-import org.apache.isis.commons.internal.collections._Lists;
-import org.apache.isis.core.security.authentication.manager.AuthenticationManagerStandardInstallerAbstractForDfltRuntime;
-import org.apache.isis.core.security.authentication.standard.Authenticator;
-import org.apache.isis.security.shiro.ShiroAuthenticatorOrAuthorizor;
+public class Pac4jAuthorizationManagerInstaller extends AuthorizationManagerStandardInstallerAbstract {
-public class ShiroAuthenticationManagerInstaller
-extends AuthenticationManagerStandardInstallerAbstractForDfltRuntime {
+ public static String NAME = "pac4j";
- public static String NAME = "shiro";
-
- public ShiroAuthenticationManagerInstaller() {
+ public Pac4jAuthorizationManagerInstaller() {
super(NAME);
}
@Override
- protected List<Authenticator> createAuthenticators() {
- return _Lists.<Authenticator> of(new ShiroAuthenticatorOrAuthorizor());
+ protected Authorizor createAuthorizor() {
+ return new Pac4jAuthorizor();
}
+
}
diff --git a/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authorization/Pac4jAuthorizor.java b/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authorization/Pac4jAuthorizor.java
new file mode 100644
index 0000000..a6a561c
--- /dev/null
+++ b/core/plugins/security-pac4j/src/main/java/org/apache/isis/security/pac4j/authorization/Pac4jAuthorizor.java
@@ -0,0 +1,66 @@
+/*
+ * 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.pac4j.authorization;
+
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.core.security.authorization.standard.Authorizor;
+
+public class Pac4jAuthorizor implements Authorizor {
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+ System.out.println("!!! Pac4jAuthorizor.init");
+ }
+
+ @Override
+ public void shutdown() {
+ // TODO Auto-generated method stub
+ System.out.println("!!! Pac4jAuthorizor.shutdown");
+ }
+
+ @Override
+ public boolean isVisibleInAnyRole(Identifier identifier) {
+ System.out.println("!!! Pac4jAuthorizor.isVisibleInAnyRole identifier="+identifier);
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public boolean isUsableInAnyRole(Identifier identifier) {
+ System.out.println("!!! Pac4jAuthorizor.isUsableInAnyRole identifier="+identifier);
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public boolean isVisibleInRole(String role, Identifier identifier) {
+ System.out.println("!!! Pac4jAuthorizor.isVisibleInRole role="+role+", identifier="+identifier);
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public boolean isUsableInRole(String role, Identifier identifier) {
+ System.out.println("!!! Pac4jAuthorizor.isUsableInRole role="+role+", identifier="+identifier);
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+}
diff --git a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java b/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java
index a6a1d41..90f1053 100644
--- a/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java
+++ b/core/plugins/security-shiro/src/main/java/org/apache/isis/security/shiro/authentication/ShiroAuthenticationManagerInstaller.java
@@ -36,6 +36,6 @@ extends AuthenticationManagerStandardInstallerAbstractForDfltRuntime {
@Override
protected List<Authenticator> createAuthenticators() {
- return _Lists.<Authenticator> of(new ShiroAuthenticatorOrAuthorizor());
+ return _Lists.singleton(new ShiroAuthenticatorOrAuthorizor());
}
}
diff --git a/core/pom.xml b/core/pom.xml
index b4bef29..36c385a 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -1367,6 +1367,12 @@ ${license.additional-notes}
<dependency>
<groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-plugins-security-pac4j</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
<artifactId>isis-core-plugins-security-shiro</artifactId>
<version>${project.version}</version>
</dependency>
@@ -2485,6 +2491,7 @@ ${license.additional-notes}
<module>plugins/jaxrs-resteasy-4</module>
<module>plugins/jdo-datanucleus-4</module>
<module>plugins/jdo-datanucleus-5</module>
+ <module>plugins/security-pac4j</module>
<module>plugins/security-shiro</module>
<!-- to break cyclic dependencies some tests needed to be moved to their own modules -->
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
index 7454c9d..23dace6 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
@@ -36,6 +36,7 @@ import org.apache.isis.core.plugins.environment.IsisSystemEnvironment;
import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
import org.apache.isis.core.runtime.system.session.IsisSession;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
+import org.apache.isis.core.security.authentication.AuthenticationSession;
/**
* Provides static access to current context's singletons
@@ -167,6 +168,15 @@ public interface IsisContext {
return Optional.ofNullable(getSessionFactory().getCurrentSession())
.map(IsisSession::getPersistenceSession);
}
+
+ /**
+ * @return framework's current AuthenticationSession (if any)
+ * @throws IllegalStateException if IsisSessionFactory not initialized
+ */
+ public static Optional<AuthenticationSession> getAuthenticationSession() {
+ return Optional.ofNullable(getSessionFactory().getCurrentSession())
+ .map(IsisSession::getAuthenticationSession);
+ }
/**
* @return framework's IsisConfiguration
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisComponentProviderHelper_UsingInstallers.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisComponentProviderHelper_UsingInstallers.java
index a07934d..0c8126a 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisComponentProviderHelper_UsingInstallers.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisComponentProviderHelper_UsingInstallers.java
@@ -110,7 +110,7 @@ class IsisComponentProviderHelper_UsingInstallers {
* @deprecated - intention is to replace in future using CDI
*/
- @Deprecated
+ @Deprecated //FIXME [2039] remove installers
static class InstallerLookup implements ApplicationScopedComponent {
private static final Logger LOG = LoggerFactory.getLogger(InstallerLookup.class);
@@ -124,8 +124,12 @@ class IsisComponentProviderHelper_UsingInstallers {
final List<String> installerClassNames = _Lists.of(
"org.apache.isis.core.security.authentication.BypassAuthenticationManagerInstaller", // bypass
- "org.apache.isis.security.shiro.authentication.ShiroAuthenticationManagerInstaller", // shiro
"org.apache.isis.core.security.authorization.BypassAuthorizationManagerInstaller", // bypass
+
+ "org.apache.isis.security.pac4j.authentication.Pac4jAuthenticationManagerInstaller", // pac4j
+ "org.apache.isis.security.pac4j.authorization.Pac4jAuthorizationManagerInstaller", // pac4j
+
+ "org.apache.isis.security.shiro.authentication.ShiroAuthenticationManagerInstaller", // shiro
"org.apache.isis.security.shiro.authorization.ShiroAuthorizationManagerInstaller" // shiro
);