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 2015/03/30 12:13:51 UTC
[1/3] isis git commit: ISIS-1129: new SudoService
Repository: isis
Updated Branches:
refs/heads/master 8fd10256f -> 7838addc3
ISIS-1129: new SudoService
- SudoService and implementation in runtime
- updates to DomainObjectContainerDefault
- deprecate SwitchUserService.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/3a3c7d44
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/3a3c7d44
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/3a3c7d44
Branch: refs/heads/master
Commit: 3a3c7d44393731a54eaa7e811ba1edf4ea1e9401
Parents: 8fd1025
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon Mar 30 10:42:50 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Mar 30 10:42:50 2015 +0100
----------------------------------------------------------------------
.../fixtures/switchuser/SwitchUserService.java | 5 +
.../switchuser/SwitchUserServiceAware.java | 9 +-
.../isis/applib/services/sudo/SudoService.java | 66 +++++++++++
.../container/DomainObjectContainerDefault.java | 35 +++++-
.../runtime/fixtures/SwitchUserServiceImpl.java | 21 +++-
.../overrideuser/SudoServiceDefault.java | 110 +++++++++++++++++++
6 files changed, 232 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/3a3c7d44/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserService.java b/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserService.java
index 98adbb1..2d20aa7 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserService.java
@@ -21,6 +21,7 @@ package org.apache.isis.applib.fixtures.switchuser;
import java.util.List;
import org.apache.isis.applib.fixtures.AbstractFixture;
+import org.apache.isis.applib.services.sudo.SudoService;
/**
* Not intended to be used directly; decouples the {@link AbstractFixture},
@@ -30,12 +31,16 @@ import org.apache.isis.applib.fixtures.AbstractFixture;
* <p>
* A suitable implementation is injected into {@link AbstractFixture} when
* installed.
+ *
+ * @deprecated - use instead {@link SudoService}.
*/
+@Deprecated
public interface SwitchUserService {
/**
* Switches the current user with the list of specified roles.
*/
+ @Deprecated
void switchUser(String username, String... roles);
/**
http://git-wip-us.apache.org/repos/asf/isis/blob/3a3c7d44/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserServiceAware.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserServiceAware.java b/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserServiceAware.java
index 883a1dd..dee03f3 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserServiceAware.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/fixtures/switchuser/SwitchUserServiceAware.java
@@ -19,15 +19,12 @@
package org.apache.isis.applib.fixtures.switchuser;
-import org.apache.isis.applib.fixtures.AbstractFixture;
-
/**
* Implement if require {@link SwitchUserService} to be injected into fixture.
- *
- * <p>
- * Most fixtures will subclass from {@link AbstractFixture} which does indeed
- * implement this interface.
+ *
+ * @deprecated - use instead OverrideUserService
*/
+@Deprecated
public interface SwitchUserServiceAware {
void setService(SwitchUserService switchUserService);
http://git-wip-us.apache.org/repos/asf/isis/blob/3a3c7d44/core/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java b/core/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java
new file mode 100644
index 0000000..21f7d1c
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.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.applib.services.sudo;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.annotation.Programmatic;
+
+/**
+ * Intended only for use by fixture scripts and integration tests, allows a block of code to execute
+ * while the {@link org.apache.isis.applib.DomainObjectContainer container}'s
+ * {@link DomainObjectContainer#getUser() getUser()} method returns the specified user/role as the effective user.
+ */
+public interface SudoService {
+
+ /**
+ * Executes the supplied block, with the {@link DomainObjectContainer} returning the specified user.
+ *
+ * <p>
+ * The roles of this user will be the same as the currently logged-in user.
+ * </p>
+ */
+ @Programmatic
+ void sudo(String username, final Runnable runnable);
+
+ /**
+ * Executes the supplied block, with the {@link DomainObjectContainer} returning the specified user.
+ *
+ * <p>
+ * The roles of this user will be the same as the currently logged-in user.
+ * </p>
+ */
+ @Programmatic
+ <T> T sudo(String username, final Callable<T> callable);
+
+ /**
+ * Executes the supplied block, with the {@link DomainObjectContainer} returning the specified user with the specified roles.
+ */
+ @Programmatic
+ void sudo(String username, List<String> roles, final Runnable runnable);
+
+ /**
+ * Executes the supplied block, with the {@link DomainObjectContainer} returning the specified user with the specified roles.
+ */
+ @Programmatic
+ <T> T sudo(String username, List<String> roles, final Callable<T> callable);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/3a3c7d44/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
index fc07851..fe88552 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
@@ -43,6 +43,7 @@ import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerComposite;
import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerForType;
import org.apache.isis.applib.services.i18n.TranslatableString;
import org.apache.isis.applib.services.i18n.TranslationService;
+import org.apache.isis.applib.services.sudo.SudoService;
import org.apache.isis.applib.services.wrapper.WrapperFactory;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
@@ -344,15 +345,43 @@ public class DomainObjectContainerDefault implements DomainObjectContainer, Quer
//region > security
+ private final ThreadLocal<String> overrideUser = new ThreadLocal<>();
+ private final ThreadLocal<List<String>> overrideRoles = new ThreadLocal<>();
+
+ /**
+ * Not API; for use by the implementation of {@link SudoService}.
+ */
+ @Programmatic
+ public void overrideUser(final String user) {
+ this.overrideUser.set(user);
+ }
+ /**
+ * Not API; for use by the implementation of {@link SudoService}.
+ */
+ @Programmatic
+ public void overrideUserAndRoles(final String user, final List<String> roles) {
+ this.overrideUser.set(user);
+ this.overrideRoles.set(roles);
+ }
+ /**
+ * Not API; for use by the implementation of {@link SudoService}.
+ */
+ @Programmatic
+ public void resetOverrides() {
+ this.overrideUser.set(null);
+ this.overrideRoles.set(null);
+ }
+
@Programmatic
@Override
public UserMemento getUser() {
final AuthenticationSession session = getAuthenticationSessionProvider().getAuthenticationSession();
- final String name = session.getUserName();
- final List<RoleMemento> roleMementos = asRoleMementos(session.getRoles());
+ final String username = overrideUser.get() != null? overrideUser.get() : session.getUserName();
+ final List<String> roles = overrideRoles.get() != null ? overrideRoles.get() : session.getRoles();
+ final List<RoleMemento> roleMementos = asRoleMementos(roles);
- final UserMemento user = new UserMemento(name, roleMementos);
+ final UserMemento user = new UserMemento(username, roleMementos);
return user;
}
http://git-wip-us.apache.org/repos/asf/isis/blob/3a3c7d44/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/SwitchUserServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/SwitchUserServiceImpl.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/SwitchUserServiceImpl.java
index 5368443..6e9e04b 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/SwitchUserServiceImpl.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/SwitchUserServiceImpl.java
@@ -20,40 +20,51 @@
package org.apache.isis.core.runtime.fixtures;
import java.util.List;
-
+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.fixtures.LogonFixture;
import org.apache.isis.applib.fixtures.switchuser.SwitchUserService;
import org.apache.isis.applib.fixtures.switchuser.SwitchUserServiceAware;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
import org.apache.isis.core.runtime.fixtures.authentication.AuthenticationRequestLogonFixture;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
+@DomainService(
+ nature = NatureOfService.DOMAIN
+)
public class SwitchUserServiceImpl implements SwitchUserService {
- public SwitchUserServiceImpl() {
- }
-
+ @Programmatic
@Override
public void switchUser(final String username, final List<String> roles) {
switchUser(new LogonFixture(username, roles));
}
+ @Programmatic
@Override
public void switchUser(final String username, final String... roles) {
switchUser(new LogonFixture(username, roles));
}
private void switchUser(final LogonFixture logonFixture) {
+ reopenSession(new AuthenticationRequestLogonFixture(logonFixture));
+ }
+
+ private void reopenSession(final AuthenticationRequest authRequest) {
getTransactionManager().endTransaction();
IsisContext.closeSession();
- final AuthenticationRequestLogonFixture authRequest = new AuthenticationRequestLogonFixture(logonFixture);
final AuthenticationSession session = getAuthenticationManager().authenticate(authRequest);
IsisContext.openSession(session);
getTransactionManager().startTransaction();
}
+
+ @Deprecated
+ @Programmatic
public void injectInto(final Object fixture) {
if (fixture instanceof SwitchUserServiceAware) {
final SwitchUserServiceAware serviceAware = (SwitchUserServiceAware) fixture;
http://git-wip-us.apache.org/repos/asf/isis/blob/3a3c7d44/core/runtime/src/main/java/org/apache/isis/core/runtime/services/overrideuser/SudoServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/overrideuser/SudoServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/overrideuser/SudoServiceDefault.java
new file mode 100644
index 0000000..caa8afd
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/overrideuser/SudoServiceDefault.java
@@ -0,0 +1,110 @@
+/*
+ * 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.core.runtime.services.overrideuser;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import org.apache.isis.applib.DomainObjectContainer;
+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.sudo.SudoService;
+import org.apache.isis.core.metamodel.services.container.DomainObjectContainerDefault;
+
+@DomainService(
+ nature = NatureOfService.DOMAIN
+)
+public class SudoServiceDefault implements SudoService {
+
+ private DomainObjectContainerDefault containerDefault;
+
+ @Programmatic
+ @PostConstruct
+ public void init() {
+ if(container instanceof DomainObjectContainerDefault) {
+ containerDefault = (DomainObjectContainerDefault) container;
+ }
+ }
+
+ @Programmatic
+ @Override
+ public void sudo(final String user, final Runnable runnable) {
+ ensureContainerOk();
+ try {
+ containerDefault.overrideUser(user);
+ runnable.run();
+ } finally {
+ containerDefault.resetOverrides();
+ }
+ }
+
+ @Programmatic
+ @Override
+ public <T> T sudo(final String user, final Callable<T> callable) {
+ ensureContainerOk();
+ try {
+ containerDefault.overrideUser(user);
+ return callable.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ containerDefault.resetOverrides();
+ }
+ }
+
+ @Programmatic
+ @Override
+ public void sudo(final String username, final List<String> roles, final Runnable runnable) {
+ ensureContainerOk();
+ try {
+ containerDefault.overrideUserAndRoles(username, roles);
+ runnable.run();
+ } finally {
+ containerDefault.resetOverrides();
+ }
+ }
+
+ @Programmatic
+ @Override
+ public <T> T sudo(final String username, final List<String> roles, final Callable<T> callable) {
+ ensureContainerOk();
+ try {
+ containerDefault.overrideUserAndRoles(username, roles);
+ return callable.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ containerDefault.resetOverrides();
+ }
+ }
+
+ private void ensureContainerOk() {
+ if(containerDefault == null) {
+ throw new IllegalStateException("DomainObjectContainer does not support the user being overridden");
+ }
+ }
+
+
+ @Inject
+ private DomainObjectContainer container;
+
+}
[2/3] isis git commit: ISIS-1052: removing HasLongId from applib
Posted by da...@apache.org.
ISIS-1052: removing HasLongId from applib
... this was introduced during earlier work on supporting polymorphic associations, eventually implemented outside of isis via the isisaddons' isis-module-poly module.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/44268762
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/44268762
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/44268762
Branch: refs/heads/master
Commit: 44268762bff77cfb8198a1623f6737750baa2ead
Parents: 3a3c7d4
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon Mar 30 10:43:50 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Mar 30 10:43:50 2015 +0100
----------------------------------------------------------------------
.../apache/isis/applib/services/HasLongId.java | 25 --------------------
1 file changed, 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/44268762/core/applib/src/main/java/org/apache/isis/applib/services/HasLongId.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/HasLongId.java b/core/applib/src/main/java/org/apache/isis/applib/services/HasLongId.java
deleted file mode 100644
index b59b9cc..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/services/HasLongId.java
+++ /dev/null
@@ -1,25 +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.applib.services;
-
-/**
- * To support polymorphic relationships.
- */
-public interface HasLongId {
-
- Long __isis_getId();
-}
[3/3] isis git commit: ISIS-1052: trivial improvements to the stack
trace shown in the Wicket viewer's error page,
to make it easier to distinguish the "caused By" inner exceptions.
Posted by da...@apache.org.
ISIS-1052: trivial improvements to the stack trace shown in the Wicket viewer's error page, to make it easier to distinguish the "caused By" inner exceptions.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/7838addc
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/7838addc
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/7838addc
Branch: refs/heads/master
Commit: 7838addc3606391947c5b7df099e6eb821d7afe2
Parents: 4426876
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon Mar 30 10:45:57 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Mar 30 10:45:57 2015 +0100
----------------------------------------------------------------------
.../isis/viewer/wicket/ui/errors/ExceptionModel.java | 9 ++++++++-
.../isis/viewer/wicket/ui/errors/StackTraceDetail.java | 11 ++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/7838addc/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java
----------------------------------------------------------------------
diff --git a/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java b/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java
index 8c87bf2..936c3fd 100644
--- a/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java
+++ b/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java
@@ -121,11 +121,18 @@ public class ExceptionModel extends ModelAbstract<List<StackTraceDetail>> {
private static List<StackTraceDetail> asStackTrace(Throwable ex) {
List<StackTraceDetail> stackTrace = Lists.newArrayList();
List<Throwable> causalChain = Throwables.getCausalChain(ex);
+ boolean firstTime = true;
for(Throwable cause: causalChain) {
+ if(!firstTime) {
+ stackTrace.add(StackTraceDetail.spacer());
+ stackTrace.add(StackTraceDetail.causedBy());
+ stackTrace.add(StackTraceDetail.spacer());
+ } else {
+ firstTime = false;
+ }
stackTrace.add(StackTraceDetail.exceptionClassName(cause));
stackTrace.add(StackTraceDetail.exceptionMessage(cause));
addStackTraceElements(cause, stackTrace);
- cause = cause.getCause();
}
return stackTrace;
}
http://git-wip-us.apache.org/repos/asf/isis/blob/7838addc/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/StackTraceDetail.java
----------------------------------------------------------------------
diff --git a/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/StackTraceDetail.java b/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/StackTraceDetail.java
index c0cd16b..9f73c4a 100644
--- a/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/StackTraceDetail.java
+++ b/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/StackTraceDetail.java
@@ -47,10 +47,19 @@ public class StackTraceDetail implements Serializable {
return new StackTraceDetail(StackTraceDetail.Type.STACKTRACE_ELEMENT, buf.toString());
}
+ public static StackTraceDetail spacer() {
+ return new StackTraceDetail(Type.LITERAL, "");
+ }
+
+ public static StackTraceDetail causedBy() {
+ return new StackTraceDetail(Type.LITERAL, "Caused by:");
+ }
+
enum Type {
EXCEPTION_CLASS_NAME,
EXCEPTION_MESSAGE,
- STACKTRACE_ELEMENT
+ STACKTRACE_ELEMENT,
+ LITERAL
}
private final Type type;
private final String line;