You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2017/11/14 22:45:24 UTC

[isis] 01/03: ISIS-1714: default implementation of UserProfileService.

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

danhaywood pushed a commit to branch ISIS-1759
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 7c95d76c72d1243999277fff85e330889ee13f23
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Nov 14 17:59:37 2017 +0000

    ISIS-1714: default implementation of UserProfileService.
---
 ..._presentation-layer-spi_UserProfileService.adoc |  7 ++++---
 .../userprof/UserProfileServiceDefault.java        | 22 ++++++++++++++++++++++
 .../wicket/ui/components/header/HeaderPanel.java   |  6 ++----
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_UserProfileService.adoc b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_UserProfileService.adoc
index 0c22838..b361cd6 100644
--- a/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_UserProfileService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/rgsvc/_rgsvc_presentation-layer-spi_UserProfileService.adoc
@@ -33,9 +33,10 @@ In the future this API may be expanded; one obvious possibility is to return a p
 
 == Implementation
 
-There is no default implementation of this service provided by the core Apache Isis framework.
+(As of `1.16.0-SNAPSHOT`) the framework provides a default implementation of this service, `o.a.i.core.runtime.services.UserProfileServiceDefault`.
+This simply returns the user's name as the user's profile name.
 
-An example implementation can be found in the (non-ASF)
+An example implementation can also be found in the (non-ASF)
 http://github.com/isisaddons/isis-app-todoapp[Isis addons' todoapp]:
 
 image::{_imagesdir}reference-services-spi/UserProfileService/todoapp.png[width="800px",link="{_imagesdir}reference-services-spi/UserProfileService/todoapp.png"]
@@ -43,5 +44,5 @@ image::{_imagesdir}reference-services-spi/UserProfileService/todoapp.png[width="
 
 [NOTE]
 ====
-Currently this feature is not integrated with Apache Isis' authentication mechanisms; the information provided is purely metadata provided for presentation purposes only.
+This feature does not integrate with Apache Isis' authentication mechanisms; the information returned is used purely for presentation purposes.
 ====
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/userprof/UserProfileServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/userprof/UserProfileServiceDefault.java
new file mode 100644
index 0000000..e10be0f
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/userprof/UserProfileServiceDefault.java
@@ -0,0 +1,22 @@
+package org.apache.isis.core.runtime.services.userprof;
+
+import javax.inject.Inject;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.services.userprof.UserProfileService;
+import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
+
+@DomainService(nature = NatureOfService.DOMAIN)
+public class UserProfileServiceDefault implements UserProfileService {
+
+    @Programmatic
+    @Override
+    public String userProfileName() {
+        return authenticationSessionProvider.getAuthenticationSession().getUserName();
+    }
+
+    @Inject
+    AuthenticationSessionProvider authenticationSessionProvider;
+}
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/header/HeaderPanel.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/header/HeaderPanel.java
index bd38ff1..4e3a00c 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/header/HeaderPanel.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/header/HeaderPanel.java
@@ -20,8 +20,6 @@ package org.apache.isis.viewer.wicket.ui.components.header;
 
 import java.util.Locale;
 
-import com.google.inject.name.Named;
-
 import org.apache.wicket.Component;
 import org.apache.wicket.MarkupContainer;
 import org.apache.wicket.Page;
@@ -107,8 +105,7 @@ public class HeaderPanel extends PanelAbstract<Model<String>> {
                 }
                 try {
                     final UserProfileService userProfileService = lookupService(UserProfileService.class);
-                    final String userProfileName = userProfileService != null ? userProfileService.userProfileName() : null;
-                    return userProfileName != null? userProfileName: getAuthenticationSession().getUserName();
+                    return userProfileService.userProfileName();
                 } catch (final Exception e) {
                     return getAuthenticationSession().getUserName();
                 }
@@ -135,4 +132,5 @@ public class HeaderPanel extends PanelAbstract<Model<String>> {
         container.add(menuBarComponent);
 
     }
+
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.