summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Campo2008-01-17 09:57:17 (EST)
committerChristian Campo2008-01-17 09:57:17 (EST)
commitcd468f15eecda0c82b1c2eefa36703dd47b36a5d (patch)
tree7b745250bd86735da5e2d078e90d12fa19241afb
parent6a2ff902497415affcc690cb6ee3ea7e17247324 (diff)
downloadorg.eclipse.riena-cd468f15eecda0c82b1c2eefa36703dd47b36a5d.zip
org.eclipse.riena-cd468f15eecda0c82b1c2eefa36703dd47b36a5d.tar.gz
org.eclipse.riena-cd468f15eecda0c82b1c2eefa36703dd47b36a5d.tar.bz2
initial checkin
-rw-r--r--org.eclipse.riena.security.common/.classpath7
-rw-r--r--org.eclipse.riena.security.common/.project28
-rw-r--r--org.eclipse.riena.security.common/META-INF/MANIFEST.MF20
-rw-r--r--org.eclipse.riena.security.common/about.html24
-rw-r--r--org.eclipse.riena.security.common/build.properties4
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/Activator.java101
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SecurityCallHook.java73
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SimpleSubjectHolder.java76
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SubjectHolderService.java46
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectChangeListener.java26
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectHolder.java52
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectHolderService.java22
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/NotAuthorizedFailure.java65
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/SecurityFailure.java87
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/SubjectChangeEvent.java50
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationException.java36
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationFailure.java87
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationTicket.java90
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/Callback2CredentialConverter.java167
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/ClientLogin.java82
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/IAuthenticationService.java100
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/SimplePrincipal.java117
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/AbstractCredential.java26
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/ChoiceCredential.java53
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/ConfirmationCredential.java53
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/CustomCredential.java32
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/LanguageCredential.java34
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/NameCredential.java39
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/PasswordCredential.java42
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/TextInputCredential.java41
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/TextOutputCredential.java35
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/IAuthorizationService.java23
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/IPermissionCache.java30
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/PermissionClassFactory.java21
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/PolicyProvider.java32
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/RienaPolicy.java152
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/internal/PermissionCache.java119
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/policies/TestPermission.java49
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/ISessionHolder.java47
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/ISessionHolderService.java22
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/Session.java58
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/internal/SimpleSessionHolder.java53
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/internal/SimpleSessionHolderService.java46
-rw-r--r--org.eclipse.riena.security.server/.classpath7
-rw-r--r--org.eclipse.riena.security.server/.project28
-rw-r--r--org.eclipse.riena.security.server/META-INF/MANIFEST.MF15
-rw-r--r--org.eclipse.riena.security.server/about.html24
-rw-r--r--org.eclipse.riena.security.server/build.properties4
-rw-r--r--org.eclipse.riena.security.server/src/org/eclipse/riena/internal/security/server/Activator.java94
-rw-r--r--org.eclipse.riena.security.server/src/org/eclipse/riena/internal/security/server/SecurityServiceHook.java276
-rw-r--r--org.eclipse.riena.security.server/src/org/eclipse/riena/security/server/session/ISessionService.java89
-rw-r--r--org.eclipse.riena.security.server/src/org/eclipse/riena/security/server/session/SessionFailure.java87
-rw-r--r--org.eclipse.riena.tests/.classpath7
-rw-r--r--org.eclipse.riena.tests/.project28
-rw-r--r--org.eclipse.riena.tests/META-INF/MANIFEST.MF23
-rw-r--r--org.eclipse.riena.tests/OSGI-INF/permissions.perm16
-rw-r--r--org.eclipse.riena.tests/about.html24
-rw-r--r--org.eclipse.riena.tests/build.properties5
-rw-r--r--org.eclipse.riena.tests/config/projekte.security268
-rw-r--r--org.eclipse.riena.tests/config/sample_jaas.config9
-rw-r--r--org.eclipse.riena.tests/config/sampleazn.policy41
-rw-r--r--org.eclipse.riena.tests/lib/samplePolicy.jarbin0 -> 2062 bytes
-rw-r--r--org.eclipse.riena.tests/plugin.xml33
-rw-r--r--org.eclipse.riena.tests/schema/core.test.extpoint.exsd119
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/AllTests.java38
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/config/BusinessClass.java32
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/config/ConfigTest.java88
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/exception/ExceptionHandlerManagerTest.java95
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/exception/TestExceptionHandler.java71
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/extension/util/ExtensionUtilTest.java25
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/extension/util/ITest.java21
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/ServiceInjectorTest.java27
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/exceptionmanager/AllTests.java30
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/exceptionmanager/TopologicalSortTest.java108
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/internal/tests/Activator.java78
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/sample/TestCustomersPermissions.java40
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/AllManualTests.java40
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/AllTests.java34
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/AuthorizationTest.java85
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/BusinessTestCase.java32
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/FilePermissionStoreTest.java58
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/TestcasePermission.java75
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/policy-def-test.xml30
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/common/Callback2CredentialConverterTest.java147
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/MyCallbackHandler.java75
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authentication/AuthenticationClientITest.java153
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authentication/AuthenticationLoginModuleITest.java68
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authorization/AuthorizationServiceITest.java115
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/module/ClientRemoteLoginModule.java121
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/module/LocalLoginModule.java126
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/session/SessionServiceITest.java155
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/tests/AllTests.java29
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/tests/RienaTestCase.java68
93 files changed, 5628 insertions, 0 deletions
diff --git a/org.eclipse.riena.security.common/.classpath b/org.eclipse.riena.security.common/.classpath
new file mode 100644
index 0000000..751c8f2
--- /dev/null
+++ b/org.eclipse.riena.security.common/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.riena.security.common/.project b/org.eclipse.riena.security.common/.project
new file mode 100644
index 0000000..85af67f
--- /dev/null
+++ b/org.eclipse.riena.security.common/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.riena.security.common</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.riena.security.common/META-INF/MANIFEST.MF b/org.eclipse.riena.security.common/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e5a5670
--- /dev/null
+++ b/org.eclipse.riena.security.common/META-INF/MANIFEST.MF
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Security Common Plug-in
+Bundle-SymbolicName: org.eclipse.riena.security.common
+Bundle-Version: 1.0.0
+Bundle-Activator: org.eclipse.riena.internal.security.common.Activator
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.riena.communication.core,
+ org.eclipse.riena.core,
+ org.eclipse.equinox.log
+Eclipse-LazyStart: true
+Export-Package: org.eclipse.riena.security.common,
+ org.eclipse.riena.security.common.authentication,
+ org.eclipse.riena.security.common.authentication.credentials,
+ org.eclipse.riena.security.common.authorization,
+ org.eclipse.riena.security.common.policies,
+ org.eclipse.riena.security.common.session
+Import-Package: org.osgi.service.log;version="1.3.0"
+Eclipse-RegisterBuddy: org.eclipse.riena.communication.core
+Eclipse-BuddyPolicy: registered
diff --git a/org.eclipse.riena.security.common/about.html b/org.eclipse.riena.security.common/about.html
new file mode 100644
index 0000000..fc81119
--- /dev/null
+++ b/org.eclipse.riena.security.common/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head><body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+<div style="position: absolute; width: 28px; height: 28px; z-index: 1000; display: none;"></div><img style="position: absolute; width: 35px; height: 29px; z-index: 1000; display: none;" src="about-Dateien/launch.png"></body></html> \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/build.properties b/org.eclipse.riena.security.common/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/org.eclipse.riena.security.common/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/Activator.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/Activator.java
new file mode 100644
index 0000000..215eb9b
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/Activator.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.security.common;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.equinox.log.Logger;
+import org.eclipse.riena.communication.core.hooks.ICallHook;
+import org.eclipse.riena.core.logging.LogUtil;
+import org.eclipse.riena.security.common.ISubjectHolderService;
+import org.eclipse.riena.security.common.authorization.IPermissionCache;
+import org.eclipse.riena.security.common.authorization.RienaPolicy;
+import org.eclipse.riena.security.common.authorization.internal.PermissionCache;
+import org.eclipse.riena.security.common.session.ISessionHolderService;
+import org.eclipse.riena.security.common.session.internal.SimpleSessionHolderService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.riena.security.common";
+
+ // The shared instance
+ private static Activator plugin;
+ private static BundleContext CONTEXT;
+ private LogUtil logUtil;
+
+ private ServiceRegistration sessionHolderService;
+ private ServiceRegistration securityCallHook;
+ private ServiceRegistration principalHolderService;
+ private ServiceRegistration permissionCache;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ CONTEXT = context;
+ sessionHolderService = CONTEXT.registerService(ISessionHolderService.ID, new SimpleSessionHolderService(), null);
+ securityCallHook = CONTEXT.registerService(ICallHook.ID, new SecurityCallHook(), null);
+ principalHolderService = CONTEXT.registerService(ISubjectHolderService.ID, new SubjectHolderService(), null);
+ permissionCache = CONTEXT.registerService(IPermissionCache.ID,new PermissionCache(),null);
+ RienaPolicy.init();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ sessionHolderService.unregister();
+ securityCallHook.unregister();
+ principalHolderService.unregister();
+ plugin = null;
+ CONTEXT = null;
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ public static BundleContext getContext() {
+ return CONTEXT;
+ }
+
+ public Logger getLogger(String name) {
+ if (logUtil == null) {
+ logUtil = new LogUtil(CONTEXT);
+ }
+ return logUtil.getLogger(name);
+ }
+
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SecurityCallHook.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SecurityCallHook.java
new file mode 100644
index 0000000..4da2a69
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SecurityCallHook.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.security.common;
+
+import java.util.Map;
+
+import org.eclipse.riena.communication.core.hooks.CallContext;
+import org.eclipse.riena.communication.core.hooks.ICallHook;
+import org.eclipse.riena.core.service.ServiceInjector;
+import org.eclipse.riena.security.common.session.ISessionHolder;
+import org.eclipse.riena.security.common.session.ISessionHolderService;
+import org.eclipse.riena.security.common.session.Session;
+
+/**
+ * This Call Hook deals with security issues of a webservice calls, it sets the cookie of the session and principal
+ * location before the call and checks for set-cookies after the call returns.
+ *
+ */
+public class SecurityCallHook implements ICallHook {
+
+ private static final String SSOID = "x-compeople-ssoid";
+ private ISessionHolderService shService;
+
+ public SecurityCallHook() {
+ super();
+ new ServiceInjector(Activator.getContext(), ISessionHolderService.ID, this, "bindSHS", "unbindSHS").start();
+ }
+
+ public void bindSHS(ISessionHolderService shService) {
+ this.shService = shService;
+ }
+
+ public void unbindSHS(ISessionHolderService shService) {
+ if (this.shService == shService) {
+ this.shService = null;
+ }
+ }
+
+ /**
+ * @see de.compeople.spirit.communication.base.hook.ICallHook#beforeCall(de.compeople.spirit.communication.base.hook.ICallContext)
+ */
+ public void beforeCall(CallContext callback) {
+ ISessionHolder sessionHolder = shService.fetchSessionHolder();
+ Session session = sessionHolder.getSession();
+
+ if (session != null) {
+ callback.setCookie(SSOID, session.getSessionId());
+ }
+ }
+
+ /**
+ * @see de.compeople.spirit.communication.base.hook.ICallHook#afterCall(de.compeople.spirit.communication.base.hook.ICallContext)
+ */
+ public void afterCall(CallContext callback) {
+ ISessionHolder sessionHolder = shService.fetchSessionHolder();
+ Map<String, String> map = callback.getSetCookies();
+ if (map == null) {
+ return;
+ }
+ String temp = (String) map.get(SSOID);
+ if (temp != null) {
+ sessionHolder.setSession(new Session(temp));
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SimpleSubjectHolder.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SimpleSubjectHolder.java
new file mode 100644
index 0000000..f74fc40
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SimpleSubjectHolder.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.security.common;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.security.auth.Subject;
+
+import org.eclipse.riena.security.common.ISubjectChangeListener;
+import org.eclipse.riena.security.common.ISubjectHolder;
+import org.eclipse.riena.security.common.SubjectChangeEvent;
+
+
+/**
+ * The <code>SimpleSubjectHolder</code> is a very simple implementation of the <code>ISubjectHolder</code>
+ * interface which should be sufficient for at least the client side.
+ *
+ */
+public class SimpleSubjectHolder implements ISubjectHolder {
+
+ private Subject subject;
+ private List<ISubjectChangeListener> principalChangeListeners;
+
+ /**
+ * Creates a SimpleSubjectHolder
+ */
+ public SimpleSubjectHolder() {
+ principalChangeListeners = new ArrayList<ISubjectChangeListener>();
+ }
+
+ /**
+ * @see de.compeople.spirit.security.base.ISubjectHolder#getSubject()
+ */
+ public Subject getSubject() {
+ return subject;
+ }
+
+ /**
+ * @see de.compeople.spirit.security.base.ISubjectHolder#setSubject(Subject)
+ */
+ public void setSubject(Subject subject) {
+ Subject old = this.subject;
+ this.subject = subject;
+ notifySubjectChange(this.subject, old);
+ }
+
+ private void notifySubjectChange(Subject newSubject, Subject oldSubject) {
+ // check avoids SubjectChangeEvent object if there is no listener
+ if (principalChangeListeners.size() > 0) {
+ SubjectChangeEvent event = new SubjectChangeEvent(newSubject, oldSubject);
+ for (ISubjectChangeListener listener : principalChangeListeners) {
+ listener.changed(event);
+ }
+ }
+ }
+
+ public void addSubjectChangeListener(ISubjectChangeListener listener) {
+ if (listener != null) {
+ principalChangeListeners.add(listener);
+ }
+ }
+
+ public void removeSubjectChangeListener(ISubjectChangeListener listener) {
+ principalChangeListeners.remove(listener);
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SubjectHolderService.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SubjectHolderService.java
new file mode 100644
index 0000000..d3619d0
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/internal/security/common/SubjectHolderService.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.security.common;
+
+import java.util.HashMap;
+
+import org.eclipse.riena.core.util.ContainerModel;
+import org.eclipse.riena.security.common.ISubjectHolder;
+import org.eclipse.riena.security.common.ISubjectHolderService;
+
+public class SubjectHolderService implements ISubjectHolderService {
+
+ private HashMap<Thread, ISubjectHolder> subjectHolderMap;
+ private ISubjectHolder subjectHolder;
+
+ public SubjectHolderService() {
+ super();
+ if (ContainerModel.isClient()) {
+ subjectHolder = new SimpleSubjectHolder();
+ } else {
+ subjectHolderMap = new HashMap<Thread, ISubjectHolder>();
+ }
+ }
+
+ public ISubjectHolder fetchSubjectHolder() {
+ if (ContainerModel.isClient()) {
+ return subjectHolder;
+ } else {
+ ISubjectHolder holder = subjectHolderMap.get(Thread.currentThread());
+ if (holder == null) {
+ holder = new SimpleSubjectHolder();
+ subjectHolderMap.put(Thread.currentThread(), holder);
+ }
+ return holder;
+ }
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectChangeListener.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectChangeListener.java
new file mode 100644
index 0000000..7aebe12
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectChangeListener.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common;
+
+/**
+ * The PrincipalChangeListener is informed when the Principal changed
+ *
+ */
+public interface ISubjectChangeListener {
+
+ /**
+ * Signals the Principal is changed
+ *
+ * @param event
+ */
+ void changed(SubjectChangeEvent event);
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectHolder.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectHolder.java
new file mode 100644
index 0000000..16c535a
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectHolder.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common;
+
+
+import javax.security.auth.Subject;
+
+/**
+ * A <code>ISubjectHolder</code> implementation retrieves the current principal, i.e. on the client the currently
+ * logged on user and on the server the user bound to the current session.
+ *
+ */
+public interface ISubjectHolder {
+
+ /**
+ * Get the current principal
+ *
+ * @return current principal
+ */
+ Subject getSubject();
+
+ /**
+ * Set the current principal
+ *
+ * @param subject
+ * current subject
+ */
+ void setSubject(Subject subject);
+
+ /**
+ * Adds the given principal change listener
+ *
+ * @param listener
+ */
+ void addSubjectChangeListener(ISubjectChangeListener listener);
+
+ /**
+ * Removes the given principal change listener
+ *
+ * @param listener
+ */
+ void removeSubjectChangeListener(ISubjectChangeListener listener);
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectHolderService.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectHolderService.java
new file mode 100644
index 0000000..8046e04
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/ISubjectHolderService.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common;
+
+public interface ISubjectHolderService {
+
+ /**
+ * Service ID
+ */
+ String ID = ISubjectHolderService.class.getName();
+
+ ISubjectHolder fetchSubjectHolder();
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/NotAuthorizedFailure.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/NotAuthorizedFailure.java
new file mode 100644
index 0000000..3b0067b
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/NotAuthorizedFailure.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common;
+
+import org.eclipse.riena.core.exception.Failure;
+
+public class NotAuthorizedFailure extends Failure {
+
+ /**
+ * @param msg
+ * @param args
+ * @param cause
+ */
+ public NotAuthorizedFailure(String msg, Object[] args, Throwable cause) {
+ super(msg, args, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param msg
+ */
+ public NotAuthorizedFailure(String msg) {
+ super(msg);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param msg
+ * @param cause
+ */
+ public NotAuthorizedFailure(String msg, Throwable cause) {
+ super(msg, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param msg
+ * @param arg1
+ * @param cause
+ */
+ public NotAuthorizedFailure(String msg, Object arg1, Throwable cause) {
+ super(msg, arg1, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param msg
+ * @param arg1
+ * @param arg2
+ * @param cause
+ */
+ public NotAuthorizedFailure(String msg, Object arg1, Object arg2, Throwable cause) {
+ super(msg, arg1, arg2, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/SecurityFailure.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/SecurityFailure.java
new file mode 100644
index 0000000..d48284c
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/SecurityFailure.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common;
+
+import org.eclipse.riena.core.exception.Failure;
+
+/**
+ * The mother of all security related failures
+ *
+ */
+public class SecurityFailure extends Failure {
+
+ /**
+ * Creates a new instance of <code>SecurityFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param args
+ * message parameters
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public SecurityFailure(String msg, Object[] args, Throwable cause) {
+ super(msg, args, cause);
+ }
+
+ /**
+ * Creates a new instance of <code>SecurityFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ */
+ public SecurityFailure(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Creates a new instance of <code>SecurityFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public SecurityFailure(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+ /**
+ * Creates a new instance of <code>SecurityFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param arg1
+ * message parameter 1
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public SecurityFailure(String msg, Object arg1, Throwable cause) {
+ super(msg, arg1, cause);
+ }
+
+ /**
+ * Creates a new instance of <code>SecurityFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param arg1
+ * message parameter 1
+ * @param arg2
+ * message parameter 2
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public SecurityFailure(String msg, Object arg1, Object arg2, Throwable cause) {
+ super(msg, arg1, arg2, cause);
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/SubjectChangeEvent.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/SubjectChangeEvent.java
new file mode 100644
index 0000000..4b6fab6
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/SubjectChangeEvent.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common;
+
+
+import javax.security.auth.Subject;
+
+/**
+ * SubjectChangeEvent notify that the principal is changed
+ *
+ */
+public class SubjectChangeEvent {
+ private Subject oldSubject;
+ private Subject newSubject;
+
+ /**
+ * Creates an SubjectChangeEvent with the new and old Principal
+ *
+ * @param newSubject
+ * @param oldSubject
+ */
+ public SubjectChangeEvent(Subject newSubject, Subject oldSubject) {
+ super();
+ this.newSubject = newSubject;
+ this.oldSubject = oldSubject;
+ }
+
+ /**
+ * @return Returns the newSubject.
+ */
+ public Subject getNewPrincipal() {
+ return newSubject;
+ }
+
+ /**
+ * @return Returns the oldSubject.
+ */
+ public Subject getOldPrincipal() {
+ return oldSubject;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationException.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationException.java
new file mode 100644
index 0000000..16487a9
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationException.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.riena.security.common.authentication;
+
+/**
+ * Checked Exception which indicates an non-fatal error situation caused by the authentication module.
+ *
+ */
+public class AuthenticationException extends Exception {
+
+ /**
+ * constructor.
+ */
+ public AuthenticationException() {
+ super();
+ }
+
+ /**
+ * constructor.
+ *
+ * @param message
+ * the detail message
+ */
+ public AuthenticationException(String message) {
+ super(message);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationFailure.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationFailure.java
new file mode 100644
index 0000000..ed746c6
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationFailure.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication;
+
+import org.eclipse.riena.security.common.SecurityFailure;
+
+/**
+ * Failure caused by any fatal problem of the authentication component.
+ *
+ * @see de.compeople.spirit.core.base.exception.Failure
+ */
+public class AuthenticationFailure extends SecurityFailure {
+
+ /**
+ * Creates a new instance of <code>AuthenticationFailure</code>
+ *
+ * @param message
+ * The reason for this exception
+ */
+ public AuthenticationFailure(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new instance of <code>AuthenticationFailure</code>
+ *
+ * @param message
+ * The reason for this failure
+ * @param e
+ * The failure/exception which caused this failure
+ */
+ public AuthenticationFailure(String message, Throwable e) {
+ super(message, e);
+ }
+
+ /**
+ * Creates a new instance of <code>AuthenticationFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param arg1
+ * message parameter 1
+ * @param arg2
+ * message parameter 2
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public AuthenticationFailure(String msg, Object arg1, Object arg2, Throwable cause) {
+ super(msg, arg1, arg2, cause);
+ }
+
+ /**
+ * Creates a new instance of <code>AuthenticationFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param arg1
+ * message parameter 1
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public AuthenticationFailure(String msg, Object arg1, Throwable cause) {
+ super(msg, arg1, cause);
+ }
+
+ /**
+ * Creates a new instance of <code>AuthenticationFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param args
+ * message parameters
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public AuthenticationFailure(String msg, Object[] args, Throwable cause) {
+ super(msg, args, cause);
+ }
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationTicket.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationTicket.java
new file mode 100644
index 0000000..c92f958
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/AuthenticationTicket.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.riena.security.common.session.Session;
+
+/**
+ * An object of this class will be returned by the authentication process. It
+ * contains the references to the authentication module and the session service.
+ *
+ * @see de.compeople.spirit.security.base.authentication.ISecurityTicket
+ */
+public class AuthenticationTicket implements Serializable {
+
+ private Session session;
+ private Set<Principal> principals;
+
+ /**
+ * constructor.
+ */
+ public AuthenticationTicket() {
+ super();
+ }
+
+ /**
+ * constructor.
+ *
+ * @param session
+ * session
+ * @param authenticationContext
+ * authentication context
+ * @pre session != null
+ * @pre authenticationContext != nul
+ */
+ public AuthenticationTicket(Session session) {
+ super();
+ assert session != null : "Missing session";
+ this.session = session;
+ this.principals = new HashSet<Principal>();
+ }
+
+ /**
+ * get the session
+ *
+ * @return session
+ */
+ public Session getSession() {
+ return session;
+ }
+
+ /**
+ * get the authentication context
+ *
+ * @return authentication context object reference
+ */
+ public Set<Principal> getPrincipals() {
+ if (principals == null) {
+ principals = new HashSet<Principal>();
+ }
+ return principals;
+ }
+
+ /**
+ * @param session
+ * The session to set.
+ */
+ public void setSession(Session session) {
+ this.session = session;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return "AuthenticationTicket(session=" + getSession() + ",principals=" + getPrincipals() + ")";
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/Callback2CredentialConverter.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/Callback2CredentialConverter.java
new file mode 100644
index 0000000..c017eff
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/Callback2CredentialConverter.java
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.ChoiceCallback;
+import javax.security.auth.callback.ConfirmationCallback;
+import javax.security.auth.callback.LanguageCallback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.TextInputCallback;
+import javax.security.auth.callback.TextOutputCallback;
+
+import org.eclipse.riena.security.common.authentication.credentials.AbstractCredential;
+import org.eclipse.riena.security.common.authentication.credentials.ChoiceCredential;
+import org.eclipse.riena.security.common.authentication.credentials.ConfirmationCredential;
+import org.eclipse.riena.security.common.authentication.credentials.CustomCredential;
+import org.eclipse.riena.security.common.authentication.credentials.LanguageCredential;
+import org.eclipse.riena.security.common.authentication.credentials.NameCredential;
+import org.eclipse.riena.security.common.authentication.credentials.PasswordCredential;
+import org.eclipse.riena.security.common.authentication.credentials.TextInputCredential;
+import org.eclipse.riena.security.common.authentication.credentials.TextOutputCredential;
+
+/**
+ * this class converts between JAAS callbacks and credential object so that they
+ * can be easily transported to a remote service
+ */
+public class Callback2CredentialConverter {
+
+ /**
+ * Convert Callback objects to AbstractCredential objects
+ *
+ * @param callbacks
+ * @return
+ */
+ public static AbstractCredential[] callbacks2Credentials(Callback[] callbacks) {
+ AbstractCredential[] creds = new AbstractCredential[callbacks.length];
+ int i = 0;
+ for (Callback cb : callbacks) {
+ if (cb instanceof NameCallback) {
+ NameCallback ncb = (NameCallback) cb;
+ NameCredential nc = new NameCredential(ncb.getPrompt(), ncb.getDefaultName());
+ nc.setName(ncb.getName());
+ creds[i++] = nc;
+ } else {
+ if (cb instanceof PasswordCallback) {
+ PasswordCallback pcb = (PasswordCallback) cb;
+ PasswordCredential pc = new PasswordCredential(pcb.getPrompt(), pcb.isEchoOn());
+ pc.setPassword(pcb.getPassword());
+ creds[i++] = pc;
+ } else {
+ if (cb instanceof ConfirmationCallback) {
+ ConfirmationCallback ccb = (ConfirmationCallback) cb;
+ ConfirmationCredential ccc = new ConfirmationCredential(ccb.getMessageType(), ccb.getOptionType(), ccb.getDefaultOption());
+ ccc.setSelectedIndex(ccb.getSelectedIndex());
+ creds[i++] = ccc;
+ } else {
+ if (cb instanceof TextInputCallback) {
+ TextInputCallback ticb = (TextInputCallback) cb;
+ TextInputCredential tic = new TextInputCredential(ticb.getPrompt(), ticb.getDefaultText());
+ tic.setText(ticb.getText());
+ creds[i++] = tic;
+ } else {
+ if (cb instanceof TextOutputCallback) {
+ TextOutputCallback tocb = (TextOutputCallback) cb;
+ TextOutputCredential toc = new TextOutputCredential(tocb.getMessageType(), tocb.getMessage());
+ creds[i++] = toc;
+
+ } else {
+ if (cb instanceof LanguageCallback) {
+ LanguageCallback lcb = (LanguageCallback) cb;
+ LanguageCredential lc = new LanguageCredential(lcb.getLocale());
+ creds[i++] = lc;
+ } else {
+ if (cb instanceof ChoiceCallback) {
+ ChoiceCallback ccb = (ChoiceCallback) cb;
+ ChoiceCredential cc = new ChoiceCredential(ccb.getPrompt(), ccb.getChoices(), ccb.getDefaultChoice(), ccb
+ .allowMultipleSelections());
+ cc.setSelections(ccb.getSelectedIndexes());
+ creds[i++] = cc;
+ } else {
+ CustomCredential cc = new CustomCredential(cb);
+ creds[i++] = cc;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return creds;
+ }
+
+ public static Callback[] credentials2Callbacks(AbstractCredential[] credentials) {
+ Callback[] callbacks = new Callback[credentials.length];
+ int i = 0;
+ for (AbstractCredential cred : credentials) {
+ if (cred instanceof NameCredential) {
+ NameCredential nc = (NameCredential) cred;
+ NameCallback ncb;
+ if (nc.getDefaultName() == null) {
+ ncb = new NameCallback(nc.getPrompt());
+ } else {
+ ncb = new NameCallback(nc.getPrompt(), nc.getDefaultName());
+ }
+ ncb.setName(nc.getName());
+ callbacks[i++] = ncb;
+ } else {
+ if (cred instanceof PasswordCredential) {
+ PasswordCredential pc = (PasswordCredential) cred;
+ PasswordCallback pcb = new PasswordCallback(pc.getPrompt(), pc.isEchoOn());
+ pcb.setPassword(pc.getPassword());
+ callbacks[i++] = pcb;
+ } else {
+ if (cred instanceof ConfirmationCredential) {
+ ConfirmationCredential cc = (ConfirmationCredential) cred;
+ ConfirmationCallback ccb = new ConfirmationCallback(cc.getMessageType(), cc.getOptionType(), cc.getDefaultOption());
+ ccb.setSelectedIndex(cc.getSelectedIndex());
+ callbacks[i++] = ccb;
+ } else {
+ if (cred instanceof TextInputCredential) {
+ TextInputCredential tic = (TextInputCredential) cred;
+ TextInputCallback ticb = new TextInputCallback(tic.getPrompt(), tic.getDefaultText());
+ ticb.setText(tic.getText());
+ callbacks[i++] = ticb;
+ } else {
+ if (cred instanceof TextOutputCredential) {
+ TextOutputCredential toc = (TextOutputCredential) cred;
+ TextOutputCallback tocb = new TextOutputCallback(toc.getMessageType(), toc.getMessage());
+ callbacks[i++] = tocb;
+ } else {
+ if (cred instanceof LanguageCredential) {
+ LanguageCredential lc = (LanguageCredential) cred;
+ LanguageCallback lcb = new LanguageCallback();
+ lcb.setLocale(lc.getLocale());
+ callbacks[i++] = lcb;
+ } else {
+ if (cred instanceof ChoiceCredential) {
+ ChoiceCredential cc = (ChoiceCredential) cred;
+ ChoiceCallback ccb = new ChoiceCallback(cc.getPrompt(), cc.getChoices(), cc.getDefaultChoice(), cc
+ .isMultipleSelectionsAllowed());
+ callbacks[i++] = ccb;
+ } else {
+ if (cred instanceof CustomCredential) {
+ callbacks[i++] = ((CustomCredential) cred).getCallback();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return callbacks;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/ClientLogin.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/ClientLogin.java
new file mode 100644
index 0000000..9141c32
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/ClientLogin.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication;
+
+import java.security.Principal;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.login.LoginException;
+
+import org.eclipse.riena.core.service.ServiceInjector;
+import org.eclipse.riena.internal.security.common.Activator;
+import org.eclipse.riena.security.common.ISubjectHolderService;
+import org.eclipse.riena.security.common.authentication.credentials.AbstractCredential;
+
+/**
+ *
+ */
+public class ClientLogin {
+
+ private IAuthenticationService authenticationService;
+ private ISubjectHolderService subjectHolderService;
+ private String loginContext;
+ private AuthenticationTicket ticket;
+ private Subject subject;
+
+ public ClientLogin(String loginContext, Subject subject) {
+ super();
+ this.loginContext = loginContext;
+ this.subject = subject;
+ new ServiceInjector(Activator.getContext(), IAuthenticationService.ID, this, "bindAuthenticationService", "unbindAuthenticationService").start();
+ new ServiceInjector(Activator.getContext(), ISubjectHolderService.ID, this, "bindSubjectHolderService", "unbindSubjectHolderService").start();
+ }
+
+ public void bindAuthenticationService(IAuthenticationService authenticationService) {
+ this.authenticationService = authenticationService;
+ }
+
+ public void unbindAuthenticationService(IAuthenticationService subHolderService) {
+ if (this.authenticationService == authenticationService) {
+ authenticationService = null;
+ }
+ }
+
+ public void bindSubjectHolderService(ISubjectHolderService subjectHolderService) {
+ this.subjectHolderService = subjectHolderService;
+ }
+
+ public void unbindSubjectHolderService(ISubjectHolderService subjectHolderService) {
+ if (this.subjectHolderService == subjectHolderService) {
+ this.subjectHolderService = null;
+ }
+ }
+
+ public boolean login(Callback[] callbacks) throws LoginException {
+ try {
+ AbstractCredential[] creds = Callback2CredentialConverter.callbacks2Credentials(callbacks);
+ ticket = authenticationService.login(loginContext, creds);
+ return true;
+ } catch (AuthenticationFailure failure) {
+ throw new LoginException(failure.getMessage());
+ }
+ }
+
+ public boolean commit() {
+ Set<Principal> pSet = subject.getPrincipals();
+ for (Principal p : ticket.getPrincipals()) {
+ pSet.add(p);
+ }
+ subjectHolderService.fetchSubjectHolder().setSubject(subject);
+ return true;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/IAuthenticationService.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/IAuthenticationService.java
new file mode 100644
index 0000000..571fae6
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/IAuthenticationService.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication;
+
+import org.eclipse.riena.security.common.authentication.credentials.AbstractCredential;
+import org.eclipse.riena.security.common.session.Session;
+
+/**
+ * The authentication interface.
+ *
+ */
+public interface IAuthenticationService {
+
+ String ID = IAuthenticationService.class.getName();
+ String WS_ID = "/AuthenticationService";
+
+ /**
+ * login operation.
+ *
+ * @param principalID
+ * principal ID
+ * @param credentials
+ * credential container
+ * @return a security ticket
+ * @throws AuthenticationException
+ * thrown in cases of application errors
+ * @throws AuthenticationFailure
+ * thrown in cases of fatal error occurrences
+ * @pre principalID != null
+ * @pre credentials != null
+ */
+ // ISecurityTicket login(PrincipalID principalID, Credentials credentials)
+ // throws AuthenticationException, AuthenticationFailure;
+ /**
+ * Login as a proxy on behalf of someone else. The proxy login requires that
+ * a user has already been logged in, to become a proxy for another user.
+ *
+ * @param proxyTicket
+ * the security ticket returned from a previous login()
+ * @param principalID
+ * principal ID of the represented user
+ * @param principalCredentials
+ * credential container of the represented user
+ * @return a security ticket
+ * @throws AuthenticationException
+ * thrown in cases of application errors
+ * @throws AuthenticationFailure
+ * thrown in cases of fatal error occurrences
+ * @pre proxyTicket != null
+ * @pre principalID != null
+ * @pre principalCredentials != null
+ */
+ // ISecurityTicket proxyLogin(ISecurityTicket proxyTicket, PrincipalID
+ // principalID, Credentials principalCredentials) throws
+ // AuthenticationException,
+ // AuthenticationFailure;
+ /**
+ * change the value credential(s).
+ *
+ * @param ticket
+ * the principal object reference
+ * @param oldCredentials
+ * the old credentials container
+ * @param newCredentials
+ * the new credentials container
+ * @throws AuthenticationFailure
+ * thrown in cases of fatal error occurrences
+ * @pre ticket != null
+ * @pre ticket.getSession() != null
+ * @pre oldCredentials != null
+ * @pre newCredentials != null
+ */
+ // void changeCredentials(ISecurityTicket ticket, Credentials
+ // oldCredentials, Credentials newCredentials) throws AuthenticationFailure;
+ /**
+ * logoff operation.
+ *
+ * @param loginContext
+ * TODO
+ * @param ticket
+ * a security ticket
+ * @throws AuthenticationFailure
+ * thrown in cases of fatal error occurrences
+ * @pre ticket != null
+ * @pre ticket.getSession() != null
+ */
+ // void logoff(ISecurityTicket ticket) throws AuthenticationFailure;
+ AuthenticationTicket login(String loginContext, AbstractCredential[] credentials);
+
+ void logout(Session session);
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/SimplePrincipal.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/SimplePrincipal.java
new file mode 100644
index 0000000..237f999
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/SimplePrincipal.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+/**
+ * The <code>SimplePrincipal</code> is a <code>java.security.Principal</code>.
+ *
+ */
+public class SimplePrincipal implements Principal, Serializable {
+
+ private String name;
+
+ /**
+ * constructor.
+ */
+ public SimplePrincipal() {
+ super();
+ }
+
+ /**
+ * Create a <code>SimplePrincipal</code> with a given <code>name</code>.
+ *
+ * @param name
+ * the name of the principal
+ * @pre name != null && name.length() > 0
+ */
+ public SimplePrincipal(String name) {
+ super();
+ // PreCondition.assertTrue( "the Name must not be null or empty", name != null && name.length() > 0 );
+
+ setName(name);
+ }
+
+ /**
+ * Create a <code>SimplePrincipal</code> with a given name. The name is a composite of <code>proxyName</code>
+ * and <code>representedName</code>.
+ *
+ * @param proxyName
+ * name of the proxy
+ * @param representedName
+ */
+ public SimplePrincipal(String proxyName, String representedName) {
+ this(proxyName + "," + representedName);
+ }
+
+ /**
+ * @see java.security.Principal#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of this principal
+ *
+ * @param name
+ * The name to set.
+ * @pre name != null && name.length() > 0
+ * @pre getName() == null;
+ */
+ public void setName(String name) {
+ // PreCondition.assertTrue( "the Name must not be null or empty!", name != null && name.length() > 0 );
+ // PreCondition.assertTrue( "Name can only by set once!", this.name == null );
+ this.name = name;
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ }
+ if (!(object instanceof SimplePrincipal)) {
+ return false;
+ }
+ SimplePrincipal that = (SimplePrincipal) object;
+
+ if (this.name == null) {
+ return that.name == null;
+ }
+
+ return this.name.equals(that.name);
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ if (name == null) {
+ return getClass().hashCode();
+ } else {
+ return getClass().hashCode() & name.hashCode();
+ }
+ }
+
+ /**
+ * overwrite super.toString()
+ *
+ * @return string representation of object
+ */
+ public String toString() {
+ return "(" + this.getClass().getName() + ":" + name + ")";
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/AbstractCredential.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/AbstractCredential.java
new file mode 100644
index 0000000..2e71bc8
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/AbstractCredential.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication.credentials;
+
+public abstract class AbstractCredential {
+
+ private String prompt;
+
+ public AbstractCredential(String prompt) {
+ super();
+ this.prompt = prompt;
+ }
+
+ public String getPrompt() {
+ return prompt;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/ChoiceCredential.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/ChoiceCredential.java
new file mode 100644
index 0000000..5a099a9
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/ChoiceCredential.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication.credentials;
+
+/**
+ *
+ */
+public class ChoiceCredential extends AbstractCredential {
+
+ private String[] choices;
+ private int defaultChoice;
+ private boolean multipleSelectionsAllowed;
+ private int[] selections;
+
+ /**
+ * @param prompt
+ */
+ public ChoiceCredential(String prompt, String[] choices, int defaultChoice, boolean multipleSelectionsAllowed) {
+ super(prompt);
+ this.choices = choices;
+ this.defaultChoice = defaultChoice;
+ this.multipleSelectionsAllowed = multipleSelectionsAllowed;
+ }
+
+ public String[] getChoices() {
+ return choices;
+ }
+
+ public int getDefaultChoice() {
+ return defaultChoice;
+ }
+
+ public boolean isMultipleSelectionsAllowed() {
+ return multipleSelectionsAllowed;
+ }
+
+ public int[] getSelections() {
+ return selections;
+ }
+
+ public void setSelections(int[] selections) {
+ this.selections = selections;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/ConfirmationCredential.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/ConfirmationCredential.java
new file mode 100644
index 0000000..58bb0da
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/ConfirmationCredential.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication.credentials;
+
+/**
+ *
+ */
+public class ConfirmationCredential extends AbstractCredential {
+
+ private int messageType;
+ private int optionType;
+ private int defaultOption;
+ private int selectedIndex;
+
+ /**
+ * @param prompt
+ */
+ public ConfirmationCredential(int messageType, int optionType, int defaultOption) {
+ super(null);
+ this.messageType = messageType;
+ this.optionType = optionType;
+ this.defaultOption = defaultOption;
+ }
+
+ public int getMessageType() {
+ return messageType;
+ }
+
+ public int getOptionType() {
+ return optionType;
+ }
+
+ public int getDefaultOption() {
+ return defaultOption;
+ }
+
+ public int getSelectedIndex() {
+ return selectedIndex;
+ }
+
+ public void setSelectedIndex(int selectedIndex) {
+ this.selectedIndex = selectedIndex;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/CustomCredential.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/CustomCredential.java
new file mode 100644
index 0000000..84bcc2a
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/CustomCredential.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication.credentials;
+
+import javax.security.auth.callback.Callback;
+
+/**
+ * wrapper for all custom written callbacks in security to transport them to the
+ * remote AuthenticationService
+ */
+public class CustomCredential extends AbstractCredential {
+
+ private Callback callback;
+
+ public CustomCredential(Callback callback) {
+ super(null);
+ this.callback = callback;
+ }
+
+ public Callback getCallback() {
+ return callback;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/LanguageCredential.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/LanguageCredential.java
new file mode 100644
index 0000000..b9fb4e1
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/LanguageCredential.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication.credentials;
+
+import java.util.Locale;
+
+/**
+ *
+ */
+public class LanguageCredential extends AbstractCredential {
+
+ private Locale locale;
+
+ /**
+ * @param prompt
+ */
+ public LanguageCredential(Locale locale) {
+ super(null);
+ this.locale = locale;
+ }
+
+ public Locale getLocale() {
+ return locale;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/NameCredential.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/NameCredential.java
new file mode 100644
index 0000000..57e7bf7
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/NameCredential.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication.credentials;
+
+public class NameCredential extends AbstractCredential {
+
+ String defaultName;
+ String name;
+
+ public NameCredential(String prompt) {
+ super(prompt);
+ }
+
+ public NameCredential(String prompt, String defaultName) {
+ this(prompt);
+ this.defaultName = defaultName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDefaultName() {
+ return defaultName;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/PasswordCredential.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/PasswordCredential.java
new file mode 100644
index 0000000..e09690c
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/PasswordCredential.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication.credentials;
+
+/**
+ * @author campo
+ *
+ */
+public class PasswordCredential extends AbstractCredential {
+
+ private char[] password;
+ private boolean echoOn;
+
+ /**
+ * @param prompt
+ */
+ public PasswordCredential(String prompt, boolean echoOn) {
+ super(prompt);
+ this.echoOn = echoOn;
+ }
+
+ public char[] getPassword() {
+ return password;
+ }
+
+ public void setPassword(char[] password) {
+ this.password = password;
+ }
+
+ public boolean isEchoOn() {
+ return echoOn;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/TextInputCredential.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/TextInputCredential.java
new file mode 100644
index 0000000..f3625db
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/TextInputCredential.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication.credentials;
+
+/**
+ *
+ */
+public class TextInputCredential extends AbstractCredential {
+
+ private String defaultText;
+ private String inputText;
+
+ /**
+ * @param prompt
+ */
+ public TextInputCredential(String prompt, String defaultText) {
+ super(prompt);
+ this.defaultText = defaultText;
+ }
+
+ public String getText() {
+ return inputText;
+ }
+
+ public void setText(String inputText) {
+ this.inputText = inputText;
+ }
+
+ public String getDefaultText() {
+ return defaultText;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/TextOutputCredential.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/TextOutputCredential.java
new file mode 100644
index 0000000..80f9f34
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/credentials/TextOutputCredential.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authentication.credentials;
+
+/**
+ *
+ */
+public class TextOutputCredential extends AbstractCredential {
+
+ private int messageType;
+ private String message;
+
+ public TextOutputCredential(int messageType, String message) {
+ super(null);
+ this.messageType = messageType;
+ this.message = message;
+ }
+
+ public int getMessageType() {
+ return messageType;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/IAuthorizationService.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/IAuthorizationService.java
new file mode 100644
index 0000000..95a2ca9
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/IAuthorizationService.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authorization;
+
+import java.security.Permissions;
+import java.security.Principal;
+
+public interface IAuthorizationService {
+
+ public String ID = IAuthorizationService.class.getName();
+ String WS_ID = "/AuthorizationService";
+
+ public Permissions[] getPermissions(Principal[] principals);
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/IPermissionCache.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/IPermissionCache.java
new file mode 100644
index 0000000..8176290
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/IPermissionCache.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authorization;
+
+import java.security.Permissions;
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+public interface IPermissionCache {
+
+ public String ID = IPermissionCache.class.getName();
+
+ public Permissions getPermissions(Subject subject);
+
+ public Permissions getPermissions(Principal[] principals);
+
+ public void purgePermissions(Principal principal);
+
+ public void purgePermissions(Subject subject);
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/PermissionClassFactory.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/PermissionClassFactory.java
new file mode 100644
index 0000000..36aa7d7
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/PermissionClassFactory.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authorization;
+
+/**
+ *
+ */
+public class PermissionClassFactory {
+
+ public static Class retrieveClass(String permissionClass) throws ClassNotFoundException {
+ return Class.forName(permissionClass);
+ }
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/PolicyProvider.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/PolicyProvider.java
new file mode 100644
index 0000000..70c5ccf
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/PolicyProvider.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authorization;
+
+import java.io.FilePermission;
+import java.security.PermissionCollection;
+import java.security.Permissions;
+
+import javax.security.auth.Subject;
+
+public class PolicyProvider {
+
+ public PolicyProvider() {
+ super();
+ }
+
+ public PermissionCollection getPermissions(Subject subject) {
+ System.out.println("PolicyProvider: getPermissions");
+ Permissions permissions = new Permissions();
+ permissions.add(new FilePermission("foo.txt", "read"));
+ return permissions;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/RienaPolicy.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/RienaPolicy.java
new file mode 100644
index 0000000..21a6876
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/RienaPolicy.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authorization;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Permissions;
+import java.security.Policy;
+import java.security.Principal;
+import java.security.ProtectionDomain;
+
+import org.eclipse.riena.core.service.ServiceInjector;
+import org.eclipse.riena.internal.security.common.Activator;
+
+import sun.security.provider.PolicyFile;
+
+/**
+ *
+ */
+public class RienaPolicy extends Policy {
+
+ private static Policy defaultPolicy;
+ private IPermissionCache permCache;
+
+ public RienaPolicy() {
+ super();
+ new ServiceInjector(Activator.getContext(), IPermissionCache.ID, this, "bindPermCache", "unbindPermCache").start();
+ }
+
+ public void bindPermCache(IPermissionCache permCache) {
+ this.permCache = permCache;
+ }
+
+ public void unbindPermCache(IPermissionCache permCache) {
+ if (permCache == this.permCache) {
+ this.permCache = null;
+ }
+ }
+
+ /**
+ *
+ */
+ public static void init() {
+ RienaPolicy rp = new RienaPolicy();
+ Policy.setPolicy(rp);
+ defaultPolicy = new PolicyFile();
+ if (true)
+ return;
+ try {
+ Class<?> clz = RienaPolicy.class.getClassLoader().getSystemClassLoader().loadClass("org.eclipse.riena.security.common.policyproxy.PolicyProxy");
+ Method method = clz.getMethod("setRealPolicy", Policy.class);
+ method.invoke(clz, rp);
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ // PolicyProxy.setRealPolicy(rp);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.security.Policy#getPermissions(java.security.CodeSource)
+ */
+ @Override
+ public PermissionCollection getPermissions(CodeSource codesource) {
+ System.out.println("rienapolicy: codesource: getPermissions codesource=" + codesource.getLocation());
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.security.Policy#refresh()
+ */
+ @Override
+ public void refresh() {
+ System.out.println("rienapolicy: refresh");
+ }
+
+ @Override
+ public PermissionCollection getPermissions(ProtectionDomain domain) {
+ System.out.println("rienapolicy: domain: getPermissions domain=" + domain.getCodeSource().getLocation());
+ return super.getPermissions(domain);
+ }
+
+ @Override
+ public boolean implies(ProtectionDomain domain, Permission permission) {
+ System.out.print("(Y)");
+ if (/* permission instanceof AuthPermission && */domain.getCodeSource().getLocation().toString().contains("/org.eclipse.riena.security.common/")) {
+ return true;
+ }
+
+ // this branch is entered if there is no principal set
+ if (domain.getPrincipals() == null || domain.getPrincipals().length == 0) {
+ boolean result = defaultPolicy.implies(domain, permission);
+ if (!result) {
+ System.err.println("no right to do " + permission + " for " + domain.getCodeSource().getLocation() + " no principal");
+ }
+ return result;
+ }
+
+ // this branch is entered if there is at least one principal
+ System.out.print("rienapolicy: implies ");
+ for (Principal p : domain.getPrincipals()) {
+ System.out.print(p);
+ }
+ System.out.println(" " + permission);
+ boolean result;
+ if (permCache == null) {
+ result = defaultPolicy.implies(domain, permission);
+ } else {
+ Permissions perms = permCache.getPermissions(domain.getPrincipals());
+ if (perms != null) {
+ result = perms.implies(permission);
+ } else {
+ result = false;
+ }
+ }
+ if (!result) {
+ System.err.println("no right to do " + permission + " for " + domain.getCodeSource().getLocation() + " with principal");
+ }
+ return result;
+ }
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/internal/PermissionCache.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/internal/PermissionCache.java
new file mode 100644
index 0000000..1e206f1
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authorization/internal/PermissionCache.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.authorization.internal;
+
+import java.security.Permission;
+import java.security.Permissions;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+
+import org.eclipse.equinox.log.Logger;
+import org.eclipse.riena.core.cache.GenericObjectCache;
+import org.eclipse.riena.core.service.ServiceInjector;
+import org.eclipse.riena.core.util.ContainerModel;
+import org.eclipse.riena.internal.security.common.Activator;
+import org.eclipse.riena.security.common.authorization.IAuthorizationService;
+import org.eclipse.riena.security.common.authorization.IPermissionCache;
+import org.osgi.service.log.LogService;
+
+public class PermissionCache implements IPermissionCache {
+
+ private GenericObjectCache permCache = new GenericObjectCache();
+ private Logger LOGGER = Activator.getDefault().getLogger(PermissionCache.class.getName());
+
+ public IAuthorizationService authService;
+
+ public PermissionCache() {
+ super();
+ permCache.setName("PermissionCache");
+ permCache.setHashMap(new HashMap<Subject, Permissions>());
+ if (ContainerModel.isClient()) {
+ permCache.setMinimumSize(1);
+ permCache.setTimeout(999999000); // client permissions nearly
+ // never timeout
+ } else {
+ permCache.setMinimumSize(100);
+ permCache.setTimeout(360000);
+ }
+ new ServiceInjector(Activator.getContext(), IAuthorizationService.ID, this, "bindAuthService", "unbindAuthService").start();
+ }
+
+ public void bindAuthService(IAuthorizationService authService) {
+ this.authService = authService;
+ }
+
+ public void unbindAuthService(IAuthorizationService authService) {
+ if (authService == this.authService) {
+ this.authService = null;
+ }
+ }
+
+ public Permissions getPermissions(Subject subject) {
+ Set<Principal> principals = subject.getPrincipals();
+ Principal[] principalArray = principals.toArray(new Principal[principals.size()]);
+ return getPermissions(principalArray);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.security.common.authorization.IPermissionCache#getPermissions(javax.security.auth.Subject)
+ */
+ public Permissions getPermissions(Principal[] principals) {
+ Permissions allPerms = new Permissions();
+ ArrayList<Principal> missingPrincipals = new ArrayList<Principal>();
+
+ for (Principal principal : principals) {
+ Permissions perms = (Permissions) permCache.get(principal.getName());
+ if (perms == null) {
+ missingPrincipals.add(principal);
+ } else {
+ addPerms(allPerms, perms);
+ }
+ }
+ if (missingPrincipals.size() > 0) {
+ if (authService == null) {
+ LOGGER.log(LogService.LOG_ERROR, "no authorization service to retrieve permissions");
+ return null;
+ }
+ Principal[] mpArray = missingPrincipals.toArray(new Principal[missingPrincipals.size()]);
+ Permissions[] permsArray = authService.getPermissions(mpArray);
+ for (int i = 0; i < missingPrincipals.size(); i++) {
+ permCache.put(missingPrincipals.get(i).getName(), permsArray[i]);
+ addPerms(allPerms, permsArray[i]);
+ }
+ }
+ // = authService.getPermissions(subject.getPrincipals().toArray(new
+ // Principal[subject.getPrincipals().size()]));
+ return allPerms;
+ }
+
+ private Permissions addPerms(Permissions allPerms, Permissions perms) {
+ Enumeration<Permission> enumPerms = perms.elements();
+ while (enumPerms.hasMoreElements()) {
+ Permission perm = enumPerms.nextElement();
+ allPerms.add(perm);
+ }
+
+ return allPerms;
+ }
+
+ public void purgePermissions(Subject subject) {
+ }
+
+ public void purgePermissions(Principal principal) {
+ }
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/policies/TestPermission.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/policies/TestPermission.java
new file mode 100644
index 0000000..783c475
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/policies/TestPermission.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.policies;
+
+import java.security.Permission;
+
+public class TestPermission extends Permission {
+
+ public TestPermission(String name) {
+ super(name);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof TestPermission) {
+ if (((TestPermission) obj).getName() == this.getName()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String getActions() {
+ return null;
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+
+ @Override
+ public boolean implies(Permission permission) {
+ if (this.equals(permission)) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/ISessionHolder.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/ISessionHolder.java
new file mode 100644
index 0000000..8e3532a
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/ISessionHolder.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.session;
+
+/**
+ * Stores the session and the principal location in the Webservice (axis) context
+ *
+ */
+public interface ISessionHolder {
+
+ /**
+ * Returns the current session
+ *
+ * @return current session
+ */
+ Session getSession();
+
+ /**
+ * Sets the current session
+ *
+ * @param session
+ * current session.
+ */
+ void setSession(Session session);
+
+ /**
+ * Set JSessionId
+ *
+ * @param value
+ */
+ void setJSessionCookieValue(String value);
+
+ /**
+ * Return JSessionId
+ *
+ * @return
+ */
+ String getJSessionCookieValue();
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/ISessionHolderService.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/ISessionHolderService.java
new file mode 100644
index 0000000..64edb98
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/ISessionHolderService.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.session;
+
+public interface ISessionHolderService {
+
+ /**
+ * Service ID
+ */
+ String ID = ISessionHolderService.class.getName();
+
+ ISessionHolder fetchSessionHolder();
+
+}
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/Session.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/Session.java
new file mode 100644
index 0000000..2d734ef
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/Session.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.session;
+
+import java.io.Serializable;
+
+/**
+ * stores the session id
+ *
+ */
+public final class Session implements Serializable {
+
+ private String sessionId;
+
+ /**
+ * Creates a new instance of <code>Session</code>
+ */
+ public Session() {
+ super();
+ }
+
+ /**
+ * Creates a new instance of <code>Session</code> with the given session ID
+ *
+ * @param sessionId
+ * session ID
+ */
+ public Session(String sessionId) {
+ super();
+ setSessionId(sessionId);
+ }
+
+ /**
+ * @see org.eclipse.riena.security.common.session.ISession#getSessionId()
+ */
+ public String getSessionId() {
+ return sessionId;
+ }
+
+ /**
+ * Sets the ID of the session
+ *
+ * @param sessionId -
+ * ID of the session
+ */
+ public void setSessionId(String sessionId) {
+ this.sessionId = sessionId;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/internal/SimpleSessionHolder.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/internal/SimpleSessionHolder.java
new file mode 100644
index 0000000..3e1f732
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/internal/SimpleSessionHolder.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.session.internal;
+
+import org.eclipse.riena.security.common.session.ISessionHolder;
+import org.eclipse.riena.security.common.session.Session;
+
+/**
+ * <code>SimpleSessionHolder</code>. This implementation stores the session and the principal location.
+ *
+ */
+public class SimpleSessionHolder implements ISessionHolder {
+
+ private Session session;
+ private String jSessionCookieValue = null;
+
+ /**
+ * @see org.eclipse.riena.security.common.session.ISessionHolder#getSession()
+ */
+ public Session getSession() {
+ return session;
+ }
+
+ /**
+ * @see org.eclipse.riena.security.common.session.ISessionHolder#setSession(org.eclipse.riena.security.common.session.ISession)
+ */
+ public void setSession(Session session) {
+ this.session = session;
+ }
+
+ /**
+ * @see org.eclipse.riena.security.common.session.ISessionHolder#setJSessionCookieValue(java.lang.String)
+ */
+ public void setJSessionCookieValue(String value) {
+ this.jSessionCookieValue = value;
+ }
+
+ /**
+ * @see org.eclipse.riena.security.common.session.ISessionHolder#getJSessionCookieValue()
+ */
+ public String getJSessionCookieValue() {
+ return jSessionCookieValue;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/internal/SimpleSessionHolderService.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/internal/SimpleSessionHolderService.java
new file mode 100644
index 0000000..eaa7e53
--- /dev/null
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/session/internal/SimpleSessionHolderService.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common.session.internal;
+
+import java.util.HashMap;
+
+import org.eclipse.riena.core.util.ContainerModel;
+import org.eclipse.riena.security.common.session.ISessionHolder;
+import org.eclipse.riena.security.common.session.ISessionHolderService;
+
+public class SimpleSessionHolderService implements ISessionHolderService {
+
+ private HashMap<Thread, ISessionHolder> sessionHolderMap;
+ private ISessionHolder sessionHolder;
+
+ public SimpleSessionHolderService() {
+ super();
+ if (ContainerModel.isClient()) {
+ sessionHolder = new SimpleSessionHolder();
+ } else {
+ sessionHolderMap = new HashMap<Thread, ISessionHolder>();
+ }
+ }
+
+ public ISessionHolder fetchSessionHolder() {
+ if (ContainerModel.isClient()) {
+ return sessionHolder;
+ } else {
+ ISessionHolder holder = sessionHolderMap.get(Thread.currentThread());
+ if (holder == null) {
+ holder = new SimpleSessionHolder();
+ sessionHolderMap.put(Thread.currentThread(), holder);
+ }
+ return holder;
+ }
+ }
+
+}
diff --git a/org.eclipse.riena.security.server/.classpath b/org.eclipse.riena.security.server/.classpath
new file mode 100644
index 0000000..751c8f2
--- /dev/null
+++ b/org.eclipse.riena.security.server/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.riena.security.server/.project b/org.eclipse.riena.security.server/.project
new file mode 100644
index 0000000..7492608
--- /dev/null
+++ b/org.eclipse.riena.security.server/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.riena.security.server</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.riena.security.server/META-INF/MANIFEST.MF b/org.eclipse.riena.security.server/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..0346e2f
--- /dev/null
+++ b/org.eclipse.riena.security.server/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Security Server Plug-in
+Bundle-SymbolicName: org.eclipse.riena.security.server
+Bundle-Version: 1.0.0
+Bundle-Activator: org.eclipse.riena.internal.security.server.Activator
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.riena.security.common,
+ org.eclipse.equinox.log,
+ org.eclipse.riena.communication.core,
+ org.eclipse.riena.core
+Eclipse-LazyStart: true
+Import-Package: javax.servlet.http;version="2.4.0",
+ org.osgi.service.log;version="1.3.0"
+Export-Package: org.eclipse.riena.security.server.session
diff --git a/org.eclipse.riena.security.server/about.html b/org.eclipse.riena.security.server/about.html
new file mode 100644
index 0000000..fc81119
--- /dev/null
+++ b/org.eclipse.riena.security.server/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head><body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+<div style="position: absolute; width: 28px; height: 28px; z-index: 1000; display: none;"></div><img style="position: absolute; width: 35px; height: 29px; z-index: 1000; display: none;" src="about-Dateien/launch.png"></body></html> \ No newline at end of file
diff --git a/org.eclipse.riena.security.server/build.properties b/org.eclipse.riena.security.server/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/org.eclipse.riena.security.server/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.riena.security.server/src/org/eclipse/riena/internal/security/server/Activator.java b/org.eclipse.riena.security.server/src/org/eclipse/riena/internal/security/server/Activator.java
new file mode 100644
index 0000000..3a115bd
--- /dev/null
+++ b/org.eclipse.riena.security.server/src/org/eclipse/riena/internal/security/server/Activator.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.security.server;
+
+import java.util.Hashtable;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.equinox.log.Logger;
+import org.eclipse.riena.communication.core.hooks.IServiceHook;
+import org.eclipse.riena.core.cache.GenericObjectCache;
+import org.eclipse.riena.core.cache.IGenericObjectCache;
+import org.eclipse.riena.core.logging.LogUtil;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "de.compeople.scp.security.server";
+
+ // The shared instance
+ private static Activator plugin;
+ private static BundleContext CONTEXT;
+ private LogUtil logUtil;
+ private ServiceRegistration principalCacheRegistration;
+ private ServiceRegistration securityServiceHook;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ CONTEXT = context;
+ GenericObjectCache principalCache = new GenericObjectCache();
+ principalCache.setName("principalCache");
+ Hashtable<String, String> props = new Hashtable<String, String>();
+ props.put("cache.type", "PrincipalCache");
+ principalCacheRegistration = CONTEXT.registerService(IGenericObjectCache.ID, principalCache, props);
+ securityServiceHook = CONTEXT.registerService(IServiceHook.ID, new SecurityServiceHook(), null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ principalCacheRegistration.unregister();
+ securityServiceHook.unregister();
+ plugin = null;
+ CONTEXT = null;
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ public static BundleContext getContext() {
+ return CONTEXT;
+ }
+
+ public Logger getLogger(String name) {
+ if (logUtil == null) {
+ logUtil = new LogUtil(CONTEXT);
+ }
+ return logUtil.getLogger(name);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.server/src/org/eclipse/riena/internal/security/server/SecurityServiceHook.java b/org.eclipse.riena.security.server/src/org/eclipse/riena/internal/security/server/SecurityServiceHook.java
new file mode 100644
index 0000000..354fce6
--- /dev/null
+++ b/org.eclipse.riena.security.server/src/org/eclipse/riena/internal/security/server/SecurityServiceHook.java
@@ -0,0 +1,276 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.security.server;
+
+import java.security.Principal;
+import java.util.HashMap;
+
+import javax.security.auth.Subject;
+import javax.servlet.http.Cookie;
+
+import org.eclipse.equinox.log.Logger;
+import org.eclipse.riena.communication.core.hooks.IServiceHook;
+import org.eclipse.riena.communication.core.hooks.ServiceContext;
+import org.eclipse.riena.core.cache.IGenericObjectCache;
+import org.eclipse.riena.core.service.ServiceInjector;
+import org.eclipse.riena.security.common.ISubjectHolder;
+import org.eclipse.riena.security.common.ISubjectHolderService;
+import org.eclipse.riena.security.common.NotAuthorizedFailure;
+import org.eclipse.riena.security.common.session.ISessionHolder;
+import org.eclipse.riena.security.common.session.ISessionHolderService;
+import org.eclipse.riena.security.common.session.Session;
+import org.eclipse.riena.security.server.session.ISessionService;
+import org.osgi.service.log.LogService;
+
+/**
+ * This Service Hook deals with security issues of a webservice invocation. It
+ * reads the cookies and set SessionHolder, PrincipalLocationHolder and
+ * PrincipalHolder. It also sets "Set-Cookie" on return, when the session has
+ * changed.
+ *
+ */
+public class SecurityServiceHook implements IServiceHook {
+
+ /** <code>SESSIONID</code> */
+ public static final String SESSIONID = "ssoid";
+ /** <code>SSOID</code> used as Cookie name for the ssoid */
+ public final static String SSOID = "x-compeople-ssoid";
+ /**
+ * <code>PRINCIPAL</code> the name of the id, under which the principal is
+ * stored in the current messagecontext *
+ */
+ public static final String PRINCIPAL = "principal";
+ /** <code>SET_SESSION</code> */
+ public static final String SET_SESSION = "set-ssoid";
+
+ // private static final String UNSECURE_WEBSERVICES_ID =
+ // "spirit.security.server.UnsecureWebservices";
+
+ private IGenericObjectCache principalCache;
+ private ISessionService sessionService;
+ private ISubjectHolderService subjectHolderService;
+ private ISessionHolderService sessionHolderService;
+
+ private HashMap<String, Boolean> freeHivemindWebservices = new HashMap<String, Boolean>();
+ private boolean requiresSSOIDbyDefault = false;
+
+ private static final Logger LOGGER = Activator.getDefault().getLogger(SecurityServiceHook.class.getName());
+
+ /**
+ *
+ */
+ public SecurityServiceHook() {
+ super();
+ new ServiceInjector(Activator.getContext(), IGenericObjectCache.ID, "(cache.type=PrincipalCache)", this, "bindPrincipalCache", "unbindPrincipalCache")
+ .start();
+ new ServiceInjector(Activator.getContext(), ISessionService.ID, this, "bindSessionService", "unbindSessionService").start();
+ new ServiceInjector(Activator.getContext(), ISubjectHolderService.ID, this, "bindSubjectHolderService", "unbindSubjectHolderService").start();
+ new ServiceInjector(Activator.getContext(), ISessionHolderService.ID, this, "bindSessionHolderService", "unbindSessionHolderService").start();
+
+ // List<UnsecureWebservice> tempList =
+ // RegistryAccessor.fetchRegistry().getConfiguration(UNSECURE_WEBSERVICES_ID);
+ String appName = "???appname??????";// RuntimeInfo.getApplicationName();
+ if (appName == null) {
+ appName = "<unknown>";
+ }
+ // if (tempList.size() == 0) {
+ // LOGGER.log(LogService.LOG_INFO, appName + ": no unsecureWebservices
+ // defined");
+ // }
+ // for (int i = 0; i < tempList.size(); i++) {
+ // UnsecureWebservice freeWS = tempList.get(i);
+ // freeHivemindWebservices.put(freeWS.getServiceId(), Boolean.TRUE);
+ // if (freeWS.getServiceId().equals("*")) {
+ // requiresSSOIDbyDefault = false;
+ // }
+ // if (freeWS.getServiceId().equals("*")) {
+ // LOGGER.log(LogService.LOG_INFO, appName
+ // + ": defining ALL WEBSERVICES in this Webapp as unsecure (SSOID is
+ // not required). definition * for
+ // UnsecureServices found.");
+ // } else {
+ // LOGGER.log(LogService.LOG_INFO, appName + ": defining a Webservice "
+ // + freeWS.getServiceId() + " as unsecure
+ // (SSOID not required).");
+ // }
+ // }
+
+ // String preferenceValue =
+ // PreferencesAccessor.fetchPreferences().getSystemPreference("spirit.security.server.UnsecureWebservices").getString("All");
+ // if (preferenceValue.equalsIgnoreCase("true")) {
+ // requiresSSOIDbyDefault = false;
+ // LOGGER.log(LogService.LOG_INFO, "ALL WEBSERVICES are defined as
+ // unsecure in webapp:" + appName
+ // + " using SystemPreference
+ // spirit.security.server.UnsecureWebservices.");
+ // }
+
+ if (!requiresSSOIDbyDefault) {
+ LOGGER.log(LogService.LOG_INFO, appName + ": defining ALL WEBSERVICES in this Webapp as unsecure (SSOID is not required).");
+ }
+ }
+
+ public void bindPrincipalCache(IGenericObjectCache principalCache) {
+ this.principalCache = principalCache;
+ }
+
+ public void unbindPrincipalCache(IGenericObjectCache principalCache) {
+ if (this.principalCache == principalCache) {
+ this.principalCache = null;
+ }
+ }
+
+ public void bindSessionService(ISessionService sessionService) {
+ this.sessionService = sessionService;
+ }
+
+ public void unbindSessionService(ISessionService sessionService) {
+ if (this.sessionService == sessionService) {
+ this.sessionService = null;
+ }
+ }
+
+ public void bindSubjectHolderService(ISubjectHolderService subjectHolderService) {
+ this.subjectHolderService = subjectHolderService;
+ }
+
+ public void unbindSubjectHolderService(ISubjectHolderService subjectHolderService) {
+ if (this.subjectHolderService == subjectHolderService) {
+ this.subjectHolderService = null;
+ }
+ }
+
+ public void bindSessionHolderService(ISessionHolderService ISessionHolderService) {
+ this.sessionHolderService = ISessionHolderService;
+ }
+
+ public void unbindSessionHolderService(ISessionHolderService ISessionHolderService) {
+ if (this.sessionHolderService == ISessionHolderService) {
+ this.sessionHolderService = null;
+ }
+ }
+
+ /**
+ * @see de.compeople.spirit.communication.server.hook.IServiceHook#beforeService(de.compeople.spirit.communication.server.hook.IServiceContext)
+ */
+ public void beforeService(ServiceContext callback) {
+ boolean requiresSSOID = requiresSSOIDbyDefault;
+ // if (freeHivemindWebservices.get(callback.getComponentId()) != null) {
+ // requiresSSOID = false;
+ // } else {
+ // if (callback.isUnsecure()) {
+ // requiresSSOID = false;
+ // }
+ // }
+ ISessionHolder sessionHolder = null;
+ ISubjectHolder subjectHolder = null;
+
+ // first extract the cookies
+ Cookie[] cookies = callback.getCookies();
+ String ssoid = null;
+ if (cookies != null) {
+ for (int i = 0; i < cookies.length; i++) {
+ if (cookies[i].getName().equals(SSOID)) {
+ ssoid = cookies[i].getValue();
+ }
+ }
+ }
+
+ if (ssoid != null && ssoid.length() == 0) {
+ ssoid = null;
+ }
+
+ LOGGER.log(LogService.LOG_DEBUG, "before Service ssoid = " + ssoid);
+
+ if (ssoid == null && requiresSSOID) {
+ LOGGER.log(LogService.LOG_ERROR, "error in call to webservice {" + callback.getInterfaceName()
+ + "} since it is not in the list of webservices that do not require a session but SSOID=null !!!");
+ if (System.getProperty("spirit.secure.webservices") == null || System.getProperty("spirit.secure.webservices").equals("true")) {
+ throw new NotAuthorizedFailure("call to webservice " + callback.getInterfaceName() + " failed, no valid session was given but is required.");
+ }
+ }
+
+ // check the ssoid in the session service potentially with a webservice
+ // call
+ // note: ssoid and plid are not set
+ if (ssoid != null) {
+ Principal[] principals = (Principal[]) principalCache.get(ssoid, SecurityServiceHook.class);
+ if (principals == null) {
+ principals = sessionService.findPrincipals(new Session(ssoid));
+ LOGGER.log(LogService.LOG_DEBUG, "sessionService found principal = " + principals);
+ if (principals == null && requiresSSOID) {
+ LOGGER.log(LogService.LOG_ERROR, "ssoid {" + ssoid + "} found in request but SessionService could not find a Principal.");
+ throw new NotAuthorizedFailure("call to webservice with invalid ssoid");
+ }
+ if (principals != null) {
+ principalCache.put(ssoid, principals);
+ }
+ } else {
+ LOGGER.log(LogService.LOG_DEBUG, "found principal in cache = " + principals);
+ }
+ if (principals != null) {
+ Subject subject = new Subject();
+ for (Principal p : principals) {
+ subject.getPrincipals().add(p);
+ }
+ subjectHolderService.fetchSubjectHolder().setSubject(subject);
+ callback.setProperty("riena.subject", subject);
+ }
+ }
+
+ // set ssoid and plid in the sessionholder and the ssoid as attribute
+ if (ssoid != null) {
+ Session beforeSession = new Session(ssoid);
+ sessionHolderService.fetchSessionHolder().setSession(beforeSession);
+ callback.setProperty("de.compeople.ssoid", beforeSession);
+ }
+
+ }
+
+ /**
+ * @see de.compeople.spirit.communication.server.hook.IServiceHook#afterService(de.compeople.spirit.communication.server.hook.IServiceContext)
+ */
+ public void afterService(ServiceContext context) {
+ Session afterSession = sessionHolderService.fetchSessionHolder().getSession();
+ Session beforeSession = (Session) context.getProperty("de.compeople.ssoid");
+ String ssoid = null;
+ if (afterSession != null) {
+ ssoid = afterSession.getSessionId();
+ }
+ if (beforeSession != null) {
+ LOGGER.log(LogService.LOG_DEBUG, "afterService after_ssoid=" + ssoid + " before_ssoid=" + beforeSession.getSessionId());
+ }
+ LOGGER.log(LogService.LOG_DEBUG, "afterService compare session instance before=" + beforeSession + " after=" + afterSession);
+ if (beforeSession != afterSession || (beforeSession != null && afterSession != null && !(beforeSession.getSessionId().equals(ssoid)))) {
+ if (ssoid == null || ssoid.equals("0")) {
+ // delete cookie
+ Cookie cookie = new Cookie(SSOID, "");
+ cookie.setPath("/");
+ context.addCookie(cookie);
+ LOGGER.log(LogService.LOG_DEBUG, "setting cookie to '0'");
+ } else {
+ Cookie cookie = new Cookie(SSOID, ssoid);
+ cookie.setPath("/");
+ context.addCookie(cookie);
+ if (beforeSession != null && !(beforeSession.getSessionId().equals("0"))) {
+ LOGGER.log(LogService.LOG_WARNING, "CHANGING cookie setting from '" + beforeSession.getSessionId() + "' to '" + ssoid + "'");
+ } else {
+ LOGGER.log(LogService.LOG_DEBUG, "setting cookie to '" + ssoid + "'");
+ }
+ }
+ } else {
+ LOGGER.log(LogService.LOG_DEBUG, "doing nothing in afterService");
+ }
+
+ sessionHolderService.fetchSessionHolder().setSession(null);
+ subjectHolderService.fetchSubjectHolder().setSubject(null);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.server/src/org/eclipse/riena/security/server/session/ISessionService.java b/org.eclipse.riena.security.server/src/org/eclipse/riena/security/server/session/ISessionService.java
new file mode 100644
index 0000000..19f21e2
--- /dev/null
+++ b/org.eclipse.riena.security.server/src/org/eclipse/riena/security/server/session/ISessionService.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.server.session;
+
+import java.security.Principal;
+
+import org.eclipse.riena.security.common.session.Session;
+
+/**
+ * The ISessionService interfaces describes the methods for maintaining global
+ * sessions for user. Sessions are identified by id and associated with a user
+ * (Principal). Sessions may exists in different zones (secure and high securly
+ * zone) and are linked through some "magic" that lies in the implementation of
+ * the service.
+ *
+ */
+public interface ISessionService {
+
+ String ID = ISessionService.class.getName();
+ String WS_ID = "/SessionService";
+
+ /**
+ * Generates a new sessionid for a user with given credentials
+ *
+ * @param principals
+ * principal for which a session is generated
+ * @param credential
+ * credential of the principal
+ * @return ISession the generated session object
+ */
+ Session generateSession(Principal[] principals);
+
+ /**
+ * Checks and registers the given security ticket for the session controller
+ *
+ * @param ticket
+ * security ticket which should be checked and registerd for this
+ * session controller
+ * @return true if registration was successful
+ */
+ // boolean registerSession(ISecurityTicket ticket);
+ /**
+ * Finds a userid for a specific session
+ *
+ * @param session
+ * session for which to search
+ * @return Principal principal (null if session does not exist)
+ */
+ Principal[] findPrincipals(Session session);
+
+ /**
+ * Checks whether a session exists and can be used in the zone associated
+ * with this service
+ *
+ * @param session
+ * session to check
+ * @return true if session is valid for this zone
+ */
+ boolean isValidSession(Session session);
+
+ /**
+ * Checks whether this session exists. If true this session can be forward
+ * to the next deeper level. This method can return true even if
+ * "isValidSession" is false.
+ *
+ * @param session
+ * session to check
+ * @return true if this session exists, can be invalid but maybe its valid
+ * in a "deeper" zone.
+ */
+ boolean hasSession(Session session);
+
+ /**
+ * Invalidates the session in the component
+ *
+ * @param session
+ * session to invalidate
+ */
+ void invalidateSession(Session session);
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.security.server/src/org/eclipse/riena/security/server/session/SessionFailure.java b/org.eclipse.riena.security.server/src/org/eclipse/riena/security/server/session/SessionFailure.java
new file mode 100644
index 0000000..3f1dc60
--- /dev/null
+++ b/org.eclipse.riena.security.server/src/org/eclipse/riena/security/server/session/SessionFailure.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.server.session;
+
+import org.eclipse.riena.security.common.SecurityFailure;
+
+/**
+ * Failure in the SessionComponent
+ *
+ */
+public class SessionFailure extends SecurityFailure {
+
+ /**
+ * Creates a new instance of <code>SessionFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param args
+ * message parameters
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public SessionFailure(String msg, Object[] args, Throwable cause) {
+ super(msg, args, cause);
+ }
+
+ /**
+ * Creates a new instance of <code>SessionFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ */
+ public SessionFailure(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Creates a new instance of <code>SessionFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public SessionFailure(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+ /**
+ * Creates a new instance of <code>SessionFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param arg1
+ * message parameter 1
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public SessionFailure(String msg, Object arg1, Throwable cause) {
+ super(msg, arg1, cause);
+ }
+
+ /**
+ * Creates a new instance of <code>SecurityFailure</code>
+ *
+ * @param msg
+ * message text or message code
+ * @param arg1
+ * message parameter 1
+ * @param arg2
+ * message parameter 2
+ * @param cause
+ * exception which has caused this Failure
+ */
+ public SessionFailure(String msg, Object arg1, Object arg2, Throwable cause) {
+ super(msg, arg1, arg2, cause);
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.tests/.classpath b/org.eclipse.riena.tests/.classpath
new file mode 100644
index 0000000..751c8f2
--- /dev/null
+++ b/org.eclipse.riena.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.riena.tests/.project b/org.eclipse.riena.tests/.project
new file mode 100644
index 0000000..f68afa3
--- /dev/null
+++ b/org.eclipse.riena.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.riena.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.riena.tests/META-INF/MANIFEST.MF b/org.eclipse.riena.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..1e96811
--- /dev/null
+++ b/org.eclipse.riena.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Tests Plug-in
+Bundle-SymbolicName: org.eclipse.riena.tests;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.eclipse.riena.internal.tests.Activator
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.riena.security.authorizationservice,
+ org.junit,
+ org.eclipse.riena.security.common,
+ org.eclipse.equinox.cm,
+ org.eclipse.riena.core,
+ org.eclipse.equinox.log,
+ org.eclipse.riena.sample.app.common,
+ org.eclipse.riena.communication.core,
+ org.eclipse.riena.security.server,
+ org.eclipse.riena.exceptionmanager
+Eclipse-LazyStart: true
+Eclipse-RegisterBuddy: org.eclipse.riena.security.common
+Export-Package: org.eclipse.riena.security.authorizationservice,
+ org.eclipse.riena.security.services.itest.module,
+ org.eclipse.riena.tests
+Import-Package: org.osgi.service.log;version="1.3.0"
diff --git a/org.eclipse.riena.tests/OSGI-INF/permissions.perm b/org.eclipse.riena.tests/OSGI-INF/permissions.perm
new file mode 100644
index 0000000..8657fc0
--- /dev/null
+++ b/org.eclipse.riena.tests/OSGI-INF/permissions.perm
@@ -0,0 +1,16 @@
+# specify all necessary permissions for this bundle to work
+# so that security can be active, we can still check permissions
+# based on principal and allow additional permissions if required
+
+(java.io.FilePermission "<<ALL FILES>>" "read,write")
+(org.osgi.framework.AdminPermission)
+(org.osgi.framework.PackagePermission "*" "export,import")
+(org.osgi.framework.BundlePermission "*" "provide,require")
+#(java.util.PropertyPermission "*" "read,write")
+(org.osgi.framework.ServicePermission "*" "register,get")
+(java.lang.RuntimePermission "*")
+(java.security.SecurityPermission "*")
+(javax.security.auth.AuthPermission "*")
+(java.net.SocketPermission "*" "accept,listen,connect,resolve")
+(java.lang.reflect.ReflectPermission "*")
+#suppressAccessChecks
diff --git a/org.eclipse.riena.tests/about.html b/org.eclipse.riena.tests/about.html
new file mode 100644
index 0000000..fc81119
--- /dev/null
+++ b/org.eclipse.riena.tests/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head><body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+<div style="position: absolute; width: 28px; height: 28px; z-index: 1000; display: none;"></div><img style="position: absolute; width: 35px; height: 29px; z-index: 1000; display: none;" src="about-Dateien/launch.png"></body></html> \ No newline at end of file
diff --git a/org.eclipse.riena.tests/build.properties b/org.eclipse.riena.tests/build.properties
new file mode 100644
index 0000000..e9863e2
--- /dev/null
+++ b/org.eclipse.riena.tests/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/org.eclipse.riena.tests/config/projekte.security b/org.eclipse.riena.tests/config/projekte.security
new file mode 100644
index 0000000..bf6e96c
--- /dev/null
+++ b/org.eclipse.riena.tests/config/projekte.security
@@ -0,0 +1,268 @@
+#
+# This is the "master security properties file".
+#
+# In this file, various security properties are set for use by
+# java.security classes. This is where users can statically register
+# Cryptography Package Providers ("providers" for short). The term
+# "provider" refers to a package or set of packages that supply a
+# concrete implementation of a subset of the cryptography aspects of
+# the Java Security API. A provider may, for example, implement one or
+# more digital signature algorithms or message digest algorithms.
+#
+# Each provider must implement a subclass of the Provider class.
+# To register a provider in this master security properties file,
+# specify the Provider subclass name and priority in the format
+#
+# security.provider.<n>=<className>
+#
+# This declares a provider, and specifies its preference
+# order n. The preference order is the order in which providers are
+# searched for requested algorithms (when no specific provider is
+# requested). The order is 1-based; 1 is the most preferred, followed
+# by 2, and so on.
+#
+# <className> must specify the subclass of the Provider class whose
+# constructor sets the values of various properties that are required
+# for the Java Security API to look up the algorithms or other
+# facilities implemented by the provider.
+#
+# There must be at least one provider specification in java.security.
+# There is a default provider that comes standard with the JDK. It
+# is called the "SUN" provider, and its Provider subclass
+# named Sun appears in the sun.security.provider package. Thus, the
+# "SUN" provider is registered via the following:
+#
+# security.provider.1=sun.security.provider.Sun
+#
+# (The number 1 is used for the default provider.)
+#
+# Note: Statically registered Provider subclasses are instantiated
+# when the system is initialized. Providers can be dynamically
+# registered instead by calls to either the addProvider or
+# insertProviderAt method in the Security class.
+
+#
+# List of providers and their preference orders (see above):
+#
+security.provider.1=sun.security.provider.Sun
+security.provider.2=sun.security.rsa.SunRsaSign
+security.provider.3=com.sun.net.ssl.internal.ssl.Provider
+security.provider.4=com.sun.crypto.provider.SunJCE
+security.provider.5=sun.security.jgss.SunProvider
+security.provider.6=com.sun.security.sasl.Provider
+
+#
+# Select the source of seed data for SecureRandom. By default an
+# attempt is made to use the entropy gathering device specified by
+# the securerandom.source property. If an exception occurs when
+# accessing the URL then the traditional system/thread activity
+# algorithm is used.
+#
+# On Solaris and Linux systems, if file:/dev/urandom is specified and it
+# exists, a special SecureRandom implementation is activated by default.
+# This "NativePRNG" reads random bytes directly from /dev/urandom.
+#
+# On Windows systems, the URLs file:/dev/random and file:/dev/urandom
+# enables use of the Microsoft CryptoAPI seed functionality.
+#
+securerandom.source=file:/dev/urandom
+#
+# The entropy gathering device is described as a URL and can also
+# be specified with the system property "java.security.egd". For example,
+# -Djava.security.egd=file:/dev/urandom
+# Specifying this system property will override the securerandom.source
+# setting.
+
+#
+# Class to instantiate as the javax.security.auth.login.Configuration
+# provider.
+#
+login.configuration.provider=com.sun.security.auth.login.ConfigFile
+
+#
+# Default login configuration file
+#
+#login.config.url.1=file:${user.home}/.java.login.config
+
+#
+# Class to instantiate as the system Policy. This is the name of the class
+# that will be used as the Policy object.
+#
+policy.provider=org.eclipse.riena.security.common.bootpolicy.BootPolicy
+
+# The default is to have a single system-wide policy file,
+# and a policy file in the user's home directory.
+policy.url.1=file:${java.home}/lib/security/java.policy
+policy.url.2=file:${user.home}/.java.policy
+
+# whether or not we expand properties in the policy file
+# if this is set to false, properties (${...}) will not be expanded in policy
+# files.
+policy.expandProperties=true
+
+# whether or not we allow an extra policy to be passed on the command line
+# with -Djava.security.policy=somefile. Comment out this line to disable
+# this feature.
+policy.allowSystemProperty=true
+
+# whether or not we look into the IdentityScope for trusted Identities
+# when encountering a 1.1 signed JAR file. If the identity is found
+# and is trusted, we grant it AllPermission.
+policy.ignoreIdentityScope=false
+
+#
+# Default keystore type.
+#
+keystore.type=jks
+
+#
+# Class to instantiate as the system scope:
+#
+system.scope=sun.security.provider.IdentityDatabase
+
+#
+# List of comma-separated packages that start with or equal this string
+# will cause a security exception to be thrown when
+# passed to checkPackageAccess unless the
+# corresponding RuntimePermission ("accessClassInPackage."+package) has
+# been granted.
+package.access=sun.
+
+#
+# List of comma-separated packages that start with or equal this string
+# will cause a security exception to be thrown when
+# passed to checkPackageDefinition unless the
+# corresponding RuntimePermission ("defineClassInPackage."+package) has
+# been granted.
+#
+# by default, no packages are restricted for definition, and none of
+# the class loaders supplied with the JDK call checkPackageDefinition.
+#
+#package.definition=
+
+#
+# Determines whether this properties file can be appended to
+# or overridden on the command line via -Djava.security.properties
+#
+security.overridePropertiesFile=true
+
+#
+# Determines the default key and trust manager factory algorithms for
+# the javax.net.ssl package.
+#
+ssl.KeyManagerFactory.algorithm=SunX509
+ssl.TrustManagerFactory.algorithm=PKIX
+
+#
+# Determines the default SSLSocketFactory and SSLServerSocketFactory
+# provider implementations for the javax.net.ssl package. If, due to
+# export and/or import regulations, the providers are not allowed to be
+# replaced, changing these values will produce non-functional
+# SocketFactory or ServerSocketFactory implementations.
+#
+#ssl.SocketFactory.provider=
+#ssl.ServerSocketFactory.provider=
+
+#
+# The Java-level namelookup cache policy for successful lookups:
+#
+# any negative value: caching forever
+# any positive value: the number of seconds to cache an address for
+# zero: do not cache
+#
+# default value is forever (FOREVER). For security reasons, this
+# caching is made forever when a security manager is set.
+#
+# NOTE: setting this to anything other than the default value can have
+# serious security implications. Do not set it unless
+# you are sure you are not exposed to DNS spoofing attack.
+#
+#networkaddress.cache.ttl=-1
+
+# The Java-level namelookup cache policy for failed lookups:
+#
+# any negative value: cache forever
+# any positive value: the number of seconds to cache negative lookup results
+# zero: do not cache
+#
+# In some Microsoft Windows networking environments that employ
+# the WINS name service in addition to DNS, name service lookups
+# that fail may take a noticeably long time to return (approx. 5 seconds).
+# For this reason the default caching policy is to maintain these
+# results for 10 seconds.
+#
+#
+networkaddress.cache.negative.ttl=10
+
+#
+# Properties to configure OCSP for certificate revocation checking
+#
+
+# Enable OCSP
+#
+# By default, OCSP is not used for certificate revocation checking.
+# This property enables the use of OCSP when set to the value "true".
+#
+# NOTE: SocketPermission is required to connect to an OCSP responder.
+#
+# Example,
+# ocsp.enable=true
+
+#
+# Location of the OCSP responder
+#
+# By default, the location of the OCSP responder is determined implicitly
+# from the certificate being validated. This property explicitly specifies
+# the location of the OCSP responder. The property is used when the
+# Authority Information Access extension (defined in RFC 3280) is absent
+# from the certificate or when it requires overriding.
+#
+# Example,
+# ocsp.responderURL=http://ocsp.example.net:80
+
+#
+# Subject name of the OCSP responder's certificate
+#
+# By default, the certificate of the OCSP responder is that of the issuer
+# of the certificate being validated. This property identifies the certificate
+# of the OCSP responder when the default does not apply. Its value is a string
+# distinguished name (defined in RFC 2253) which identifies a certificate in
+# the set of certificates supplied during cert path validation. In cases where
+# the subject name alone is not sufficient to uniquely identify the certificate
+# then both the "ocsp.responderCertIssuerName" and
+# "ocsp.responderCertSerialNumber" properties must be used instead. When this
+# property is set then those two properties are ignored.
+#
+# Example,
+# ocsp.responderCertSubjectName="CN=OCSP Responder, O=XYZ Corp"
+
+#
+# Issuer name of the OCSP responder's certificate
+#
+# By default, the certificate of the OCSP responder is that of the issuer
+# of the certificate being validated. This property identifies the certificate
+# of the OCSP responder when the default does not apply. Its value is a string
+# distinguished name (defined in RFC 2253) which identifies a certificate in
+# the set of certificates supplied during cert path validation. When this
+# property is set then the "ocsp.responderCertSerialNumber" property must also
+# be set. When the "ocsp.responderCertSubjectName" property is set then this
+# property is ignored.
+#
+# Example,
+# ocsp.responderCertIssuerName="CN=Enterprise CA, O=XYZ Corp"
+
+#
+# Serial number of the OCSP responder's certificate
+#
+# By default, the certificate of the OCSP responder is that of the issuer
+# of the certificate being validated. This property identifies the certificate
+# of the OCSP responder when the default does not apply. Its value is a string
+# of hexadecimal digits (colon or space separators may be present) which
+# identifies a certificate in the set of certificates supplied during cert path
+# validation. When this property is set then the "ocsp.responderCertIssuerName"
+# property must also be set. When the "ocsp.responderCertSubjectName" property
+# is set then this property is ignored.
+#
+# Example,
+# ocsp.responderCertSerialNumber=2A:FF:00
+
diff --git a/org.eclipse.riena.tests/config/sample_jaas.config b/org.eclipse.riena.tests/config/sample_jaas.config
new file mode 100644
index 0000000..28c68cc
--- /dev/null
+++ b/org.eclipse.riena.tests/config/sample_jaas.config
@@ -0,0 +1,9 @@
+/** Login Configuration for the JAAS Sample Application **/
+
+Test {
+ org.eclipse.riena.security.services.itest.module.LocalLoginModule required debug=true;
+};
+
+Remote {
+ org.eclipse.riena.security.services.itest.module.ClientRemoteLoginModule required debug=true;
+}; \ No newline at end of file
diff --git a/org.eclipse.riena.tests/config/sampleazn.policy b/org.eclipse.riena.tests/config/sampleazn.policy
new file mode 100644
index 0000000..9a54d22
--- /dev/null
+++ b/org.eclipse.riena.tests/config/sampleazn.policy
@@ -0,0 +1,41 @@
+/** Java 2 Access Control Policy for the JAAS Sample Application **/
+
+/* grant the sample LoginModule permissions */
+grant {
+permission java.security.AllPermission;
+};
+/*grant {
+ permission javax.security.auth.AuthPermission "modifyPrincipals";
+ permission java.io.FilePermission "<<ALL FILES>>", "read";
+ permission java.io.FilePermission "C:\\projekte\\riena2\\.metadata\\-", "read,write,delete";
+ permission java.io.FilePermission "C:\\projekte\\riena2\\.metadata", "read,write";
+ permission java.io.FilePermission "C:\\develop\\RCPLabs-Runtime\\Eclipse-3.3","read,write,delete";
+ permission java.io.FilePermission "C:\\develop\\RCPLabs-Runtime\\Eclipse-3.3\\-","read,write,delete";
+ permission java.io.FilePermission "C:\\develop\\eclipse-3.3\\workspace\\.metadata", "read,write";
+ permission java.io.FilePermission "C:\\develop\\eclipse-3.3\\workspace\\.metadata\\-", "read,write";
+ permission org.osgi.framework.AdminPermission;
+ permission java.lang.RuntimePermission "*";
+ permission org.osgi.framework.ServicePermission "*","register,get";
+ permission java.net.SocketPermission "*", "accept,listen,connect,resolve";
+ permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
+ permission java.net.NetPermission "specifyStreamHandler";
+ permission java.security.SecurityPermission "getPolicy";
+ permission org.eclipse.riena.securityimplementation.server.internal.TestPermission "salary","*";
+ permission org.osgi.framework.PackagePermission "*","export,import";
+ permission org.osgi.framework.BundlePermission "*","provide,require";
+ permission java.security.SecurityPermission "setPolicy";
+};*/
+
+/* permission java.lang.RuntimePermission "createClassLoader";
+ permission java.lang.RuntimePermission "getClassLoader";
+ permission java.lang.RuntimePermission "shutdownHooks";
+ permission java.lang.RuntimePermission "accessDeclaredMembers";
+ */
+
+/*grant {
+
+ permission javax.security.auth.AuthPermission "createLoginContext.Test";
+ permission javax.security.auth.AuthPermission "createLoginContext.Remote";
+ permission javax.security.auth.AuthPermission "doAsPrivileged";
+ permission java.util.PropertyPermission "*", "read,write";
+};*/
diff --git a/org.eclipse.riena.tests/lib/samplePolicy.jar b/org.eclipse.riena.tests/lib/samplePolicy.jar
new file mode 100644
index 0000000..cc5744b
--- /dev/null
+++ b/org.eclipse.riena.tests/lib/samplePolicy.jar
Binary files differ
diff --git a/org.eclipse.riena.tests/plugin.xml b/org.eclipse.riena.tests/plugin.xml
new file mode 100644
index 0000000..b63e33b
--- /dev/null
+++ b/org.eclipse.riena.tests/plugin.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.riena.config.managedService">
+ <config
+ servicepid="org.eclipse.riena.config.symbols">
+ <property
+ name="company"
+ value="compeople ag">
+ </property>
+ </config>
+ </extension>
+ <extension
+ point="org.eclipse.riena.config.managedService">
+ <config
+ servicepid="org.eclipse.riena.business.pid">
+ <property
+ name="name"
+ value="christian campo ${company}">
+ </property>
+ </config>
+ </extension>
+ <extension-point id="core.test.extpoint" name="core test extensionpoint" schema="schema/core.test.extpoint.exsd"/>
+ <extension
+ point="core.test.extpoint">
+ <test
+ boolean="true"
+ executable="java.lang.String"
+ string="test1">
+ </test>
+ </extension>
+</plugin>
diff --git a/org.eclipse.riena.tests/schema/core.test.extpoint.exsd b/org.eclipse.riena.tests/schema/core.test.extpoint.exsd
new file mode 100644
index 0000000..0aabc80
--- /dev/null
+++ b/org.eclipse.riena.tests/schema/core.test.extpoint.exsd
@@ -0,0 +1,119 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="de.compeople.scp.core.tests">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="de.compeople.scp.core.tests" id="core.test.extpoint" name="extpoint"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="test"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="test">
+ <complexType>
+ <attribute name="string" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="boolean" type="boolean">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="executable" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/AllTests.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/AllTests.java
new file mode 100644
index 0000000..caf7047
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/AllTests.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.riena.core.config.ConfigTest;
+import org.eclipse.riena.core.exception.ExceptionHandlerManagerTest;
+import org.eclipse.riena.core.extension.util.ExtensionUtilTest;
+import org.eclipse.riena.core.service.ServiceInjectorTest;
+
+/**
+ * Tests all test cases within package:
+ *
+ * org.eclipse.riena.exceptionmanager.test.internal
+ */
+public class AllTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTestSuite(ConfigTest.class);
+ suite.addTestSuite(ExceptionHandlerManagerTest.class);
+ suite.addTestSuite(ExtensionUtilTest.class);
+ suite.addTestSuite(ServiceInjectorTest.class);
+ return suite;
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/config/BusinessClass.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/config/BusinessClass.java
new file mode 100644
index 0000000..6d27664
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/config/BusinessClass.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.config;
+
+/**
+ * Test Business Java POJO that is configured through the ConfigUtility
+ *
+ */
+public class BusinessClass {
+
+ public String name = "default";
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void invoke(String step) {
+ System.out.println("(" + step + ")" + " name=" + name + " " + System.currentTimeMillis());
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/config/ConfigTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/config/ConfigTest.java
new file mode 100644
index 0000000..cf4a9e1
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/config/ConfigTest.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.config;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.riena.internal.tests.Activator;
+import org.eclipse.riena.tests.RienaTestCase;
+
+/**
+ * @author christian
+ *
+ */
+public class ConfigTest extends RienaTestCase {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ startBundles("org\\.eclipse\\.equinox\\.cm.*", null);
+ startBundles("org\\.eclipse\\.riena\\.core", null);
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void tearDown() throws Exception {
+ }
+
+ public void testConfigBusinessClass() {
+ // create new business class instance
+ final BusinessClass bc = new BusinessClass();
+ final ErrorStatus status = new ErrorStatus();
+
+ assertTrue(bc.getName().equals("default"));
+
+ // wrap with proxy
+ new ConfigUtility(Activator.getContext()).createConfigProxy(bc, "org.eclipse.riena.business.pid");
+
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ try {
+ // wait a short time until config is applied
+ Thread.sleep(200);
+ // invoke the business call method
+ bc.invoke("first call");
+ assertTrue(bc.getName().equals("christian campo compeople ag"));
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (AssertionFailedError e) {
+ status.setTestSuccesfull(false);
+ }
+ }
+
+ };
+ t.start();
+ try {
+ t.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ assertTrue(status.isTestSuccesfull());
+ }
+
+ public class ErrorStatus {
+ private boolean testSuccesfull = true;
+
+ public boolean isTestSuccesfull() {
+ return testSuccesfull;
+ }
+
+ public void setTestSuccesfull(boolean testSuccesfull) {
+ this.testSuccesfull = testSuccesfull;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/exception/ExceptionHandlerManagerTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/exception/ExceptionHandlerManagerTest.java
new file mode 100644
index 0000000..6b6926b
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/exception/ExceptionHandlerManagerTest.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.exception;
+
+import java.util.Hashtable;
+
+import junit.framework.Assert;
+
+import org.eclipse.riena.core.exception.IExceptionHandler;
+import org.eclipse.riena.core.exception.IExceptionHandlerManager;
+import org.eclipse.riena.internal.tests.Activator;
+import org.eclipse.riena.tests.RienaTestCase;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ *
+ */
+public class ExceptionHandlerManagerTest extends RienaTestCase {
+
+ public void setUp() throws BundleException {
+ startBundles("org\\.eclipse\\.riena\\.exception.*",null);
+ }
+
+
+ public void testGetManager() {
+ BundleContext context = Activator.getContext();
+
+ ServiceReference managerRef = context.getServiceReference(IExceptionHandlerManager.ID);
+ Assert.assertNotNull(managerRef);
+
+ IExceptionHandlerManager manager = (IExceptionHandlerManager) context.getService(managerRef);
+ Assert.assertNotNull(manager);
+
+ }
+
+ public void testAddHandler() {
+ BundleContext context = Activator.getContext();
+ TestExceptionHandler test = new TestExceptionHandler();
+ test.name = "test.scp.handler1";
+
+ Hashtable<String, String> properties = new Hashtable<String, String>(0);
+ context.registerService(IExceptionHandler.ID, test, properties);
+
+ ServiceReference managerRef = context.getServiceReference(IExceptionHandlerManager.ID);
+ Assert.assertNotNull(managerRef);
+
+ IExceptionHandlerManager manager = (IExceptionHandlerManager) context.getService(managerRef);
+ Assert.assertNotNull(manager);
+
+ Exception exception = new Exception("test");
+ manager.handleCaught(exception);
+
+ Assert.assertEquals("expected exception", test.throwable, exception);
+ }
+
+ public void testAddHandlerChain() {
+ BundleContext context = Activator.getContext();
+ TestExceptionHandler test1 = new TestExceptionHandler();
+ test1.name = "test.scp.handler1";
+
+ Hashtable<String, String> properties = new Hashtable<String, String>(0);
+ context.registerService(IExceptionHandler.ID, test1, properties);
+
+ TestExceptionHandler test2 = new TestExceptionHandler();
+ test2.name = "test.scp.handler2";
+ test2.before = "test.scp.handler1";
+ test2.action = IExceptionHandlerManager.Action.Ok;
+
+ properties = new Hashtable<String, String>(0);
+ context.registerService(IExceptionHandler.ID, test2, properties);
+
+ ServiceReference managerRef = context.getServiceReference(IExceptionHandlerManager.ID);
+ Assert.assertNotNull(managerRef);
+
+ IExceptionHandlerManager manager = (IExceptionHandlerManager) context.getService(managerRef);
+ Assert.assertNotNull(manager);
+
+ Exception exception = new Exception("test");
+ manager.handleCaught(exception);
+
+ Assert.assertEquals("expected exception", test2.throwable, exception);
+ Assert.assertNull("expected no exception", test1.throwable);
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/exception/TestExceptionHandler.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/exception/TestExceptionHandler.java
new file mode 100644
index 0000000..0f088f3
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/exception/TestExceptionHandler.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.exception;
+
+import org.eclipse.equinox.log.Logger;
+import org.eclipse.riena.core.exception.IExceptionHandler;
+import org.eclipse.riena.core.exception.IExceptionHandlerManager;
+import org.eclipse.riena.core.exception.IExceptionHandlerManager.Action;
+
+
+/**
+ * Test class for ExceptionHandler
+ */
+public class TestExceptionHandler implements IExceptionHandler {
+
+ String name;
+ String before;
+ Throwable throwable;
+ Action action = IExceptionHandlerManager.Action.NotHandled;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.core.exception.IExceptionHandler#getBefore()
+ */
+ public String getBefore() {
+ // TODO Auto-generated method stub
+ return before;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.core.exception.IExceptionHandler#getName()
+ */
+ public String getName() {
+ // TODO Auto-generated method stub
+ return name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.core.exception.IExceptionHandler#handleCaught(java.lang.Throwable, java.lang.Object,
+ * org.eclipse.equinox.log.Logger)
+ */
+ public Action handleCaught(Throwable t, String msg, Logger logger) {
+ throwable = t;
+ return action;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.core.exception.IExceptionHandler#handleUncaught(java.lang.Throwable,
+ * java.lang.Object, org.eclipse.equinox.log.Logger)
+ */
+ public Action handleUncaught(Throwable t, String msg, Logger logger) {
+ throwable = t;
+ return action;
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/extension/util/ExtensionUtilTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/extension/util/ExtensionUtilTest.java
new file mode 100644
index 0000000..027c041
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/extension/util/ExtensionUtilTest.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.extension.util;
+
+import org.eclipse.riena.tests.RienaTestCase;
+
+public class ExtensionUtilTest extends RienaTestCase {
+
+ public void testExceptionUtil1() {
+ System.out.println("test");
+ ITest[] tests = ExtensionUtility.readExtensions("core.test.extpoint", ITest.class);
+ assertNotNull(tests);
+ assertTrue(tests[0].getString().equals("test1"));
+ assertTrue(tests[0].getBoolean());
+ assertTrue(tests[0].createExecutable() instanceof String);
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/extension/util/ITest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/extension/util/ITest.java
new file mode 100644
index 0000000..fb7218a
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/extension/util/ITest.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.extension.util;
+
+public interface ITest {
+
+ String getString();
+
+ boolean getBoolean();
+
+ Object createExecutable();
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/ServiceInjectorTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/ServiceInjectorTest.java
new file mode 100644
index 0000000..ca96c4e
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/ServiceInjectorTest.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.service;
+
+import junit.framework.TestCase;
+
+public class ServiceInjectorTest extends TestCase {
+
+ public void testValidateMethod() {
+ ServiceInjector si = new ServiceInjector();
+ Object to = new Object() {
+ public void method1() {
+
+ }
+ };
+ assertTrue(si.methodExists(to, "method1"));
+ assertFalse(si.methodExists(to, "method2"));
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/exceptionmanager/AllTests.java b/org.eclipse.riena.tests/src/org/eclipse/riena/exceptionmanager/AllTests.java
new file mode 100644
index 0000000..bee8301
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/exceptionmanager/AllTests.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.exceptionmanager;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Tests all test cases within package:
+ *
+ * org.eclipse.riena.exceptionmanager.test.internal
+ */
+public class AllTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTestSuite(TopologicalSortTest.class);
+ return suite;
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/exceptionmanager/TopologicalSortTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/exceptionmanager/TopologicalSortTest.java
new file mode 100644
index 0000000..7fd2b1f
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/exceptionmanager/TopologicalSortTest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.exceptionmanager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.eclipse.riena.internal.exceptionmanager.TopologicalNode;
+import org.eclipse.riena.internal.exceptionmanager.TopologicalSort;
+
+/**
+ * Tests the Topological sorting
+ */
+public class TopologicalSortTest extends TestCase {
+
+ public void testSortEmpty() {
+ List<TopologicalNode<Integer>> nodes = new ArrayList<TopologicalNode<Integer>>();
+ List<Integer> result = TopologicalSort.sort(nodes);
+
+ Assert.assertNotNull(result);
+ Assert.assertEquals("expected size", 0, result.size());
+ }
+
+ public void testSortSimple() {
+ List<TopologicalNode<Integer>> nodes = new ArrayList<TopologicalNode<Integer>>();
+ TopologicalNode<Integer> node = new TopologicalNode<Integer>("shoes", null, 1);
+ nodes.add(node);
+ List<Integer> result = TopologicalSort.sort(nodes);
+
+ Assert.assertNotNull(result);
+ Assert.assertEquals("expected size", 1, result.size());
+ Assert.assertEquals("expected type", Integer.class, result.get(0).getClass());
+ }
+
+ public void testSortTwo() {
+ List<TopologicalNode<Integer>> nodes = new ArrayList<TopologicalNode<Integer>>();
+ TopologicalNode<Integer> node = new TopologicalNode<Integer>("shoes", null, 1);
+ nodes.add(node);
+ node = new TopologicalNode<Integer>("socks", "shoes", 2);
+ nodes.add(node);
+
+ List<Integer> result = TopologicalSort.sort(nodes);
+
+ Assert.assertNotNull(result);
+ Assert.assertEquals("expected size", 2, result.size());
+ Assert.assertEquals("expected element", 2, (int) result.get(0));
+ Assert.assertEquals("expected element", 1, (int) result.get(1));
+ }
+
+ public void testSortTwoSwitched() {
+ List<TopologicalNode<Integer>> nodes = new ArrayList<TopologicalNode<Integer>>();
+ TopologicalNode<Integer> node;
+ node = new TopologicalNode<Integer>("socks", "shoes", 2);
+ nodes.add(node);
+ node = new TopologicalNode<Integer>("shoes", null, 1);
+ nodes.add(node);
+
+ List<Integer> result = TopologicalSort.sort(nodes);
+
+ Assert.assertNotNull(result);
+ Assert.assertEquals("expected size", 2, result.size());
+ Assert.assertEquals("expected element", 2, (int) result.get(0));
+ Assert.assertEquals("expected element", 1, (int) result.get(1));
+ }
+
+ public void testSortTwoPointOne() {
+ List<TopologicalNode<Integer>> nodes = new ArrayList<TopologicalNode<Integer>>();
+ TopologicalNode<Integer> node = new TopologicalNode<Integer>("shoes", null, 1);
+ nodes.add(node);
+ node = new TopologicalNode<Integer>("socks", "shoes", 2);
+ nodes.add(node);
+ node = new TopologicalNode<Integer>("pant", "shoes", 3);
+ nodes.add(node);
+
+ List<Integer> result = TopologicalSort.sort(nodes);
+
+ Assert.assertNotNull(result);
+ Assert.assertEquals("expected size", 3, result.size());
+ Assert.assertEquals("expected element", 2, (int) result.get(0));
+ Assert.assertEquals("expected element", 3, (int) result.get(1));
+ Assert.assertEquals("expected element", 1, (int) result.get(2));
+ }
+
+ public void testSortTwoPointPoint() {
+ List<TopologicalNode<Integer>> nodes = new ArrayList<TopologicalNode<Integer>>();
+ TopologicalNode<Integer> node;
+ node = new TopologicalNode<Integer>("socks", "shoes", 2);
+ nodes.add(node);
+ node = new TopologicalNode<Integer>("shoes", "socks", 3);
+ nodes.add(node);
+
+ List<Integer> result = TopologicalSort.sort(nodes);
+
+ Assert.assertNotNull(result);
+ Assert.assertEquals("expected size", 2, result.size());
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/tests/Activator.java b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/tests/Activator.java
new file mode 100644
index 0000000..c62a360
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/tests/Activator.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.tests;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.equinox.log.Logger;
+import org.eclipse.riena.core.logging.LogUtil;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.riena.tests";
+
+ // The shared instance
+ private static Activator plugin;
+ private static BundleContext CONTEXT;
+ private LogUtil logUtil;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ CONTEXT = context;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ plugin = null;
+ CONTEXT = null;
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ public static BundleContext getContext() {
+ return CONTEXT;
+ }
+
+ public Logger getLogger(String name) {
+ if (logUtil == null) {
+ logUtil = new LogUtil(CONTEXT);
+ }
+ return logUtil.getLogger(name);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/sample/TestCustomersPermissions.java b/org.eclipse.riena.tests/src/org/eclipse/riena/sample/TestCustomersPermissions.java
new file mode 100644
index 0000000..4232620
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/sample/TestCustomersPermissions.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.sample;
+
+import org.eclipse.riena.sample.app.common.model.CustomersPermission;
+
+import junit.framework.TestCase;
+
+/**
+ * @author christian
+ *
+ */
+public class TestCustomersPermissions extends TestCase {
+
+ public void testCustomersPermission() {
+ CustomersPermission cp1 = new CustomersPermission("german", "load,save");
+ CustomersPermission cp2 = new CustomersPermission("german", "load,save");
+ assertTrue(cp1.equals(cp2));
+ CustomersPermission cp3 = new CustomersPermission("german", "save,load");
+ assertTrue(cp1.equals(cp3));
+ CustomersPermission cp4 = new CustomersPermission("german", "load");
+ assertFalse(cp1.equals(cp4));
+ assertTrue(cp1.implies(cp4));
+ assertFalse(cp4.implies(cp1));
+ CustomersPermission cp5 = new CustomersPermission("english", "load,save");
+ assertFalse(cp1.equals(cp5));
+ CustomersPermission cp6 = new CustomersPermission("english", "load");
+ assertFalse(cp1.implies(cp6));
+ assertFalse(cp6.implies(cp1));
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/AllManualTests.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/AllManualTests.java
new file mode 100644
index 0000000..67d59f9
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/AllManualTests.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.riena.security.authorizationservice.AuthorizationTest;
+import org.eclipse.riena.security.services.itest.authentication.AuthenticationClientITest;
+import org.eclipse.riena.security.services.itest.authentication.AuthenticationLoginModuleITest;
+import org.eclipse.riena.security.services.itest.authorization.AuthorizationServiceITest;
+import org.eclipse.riena.security.services.itest.session.SessionServiceITest;
+
+/**
+ * Tests all test cases within package:
+ *
+ * org.eclipse.riena.exceptionmanager.test.internal
+ */
+public class AllManualTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllManualTests.class.getName());
+ suite.addTestSuite(AuthenticationClientITest.class);
+ suite.addTestSuite(AuthenticationLoginModuleITest.class);
+ suite.addTestSuite(AuthorizationServiceITest.class);
+ suite.addTestSuite(SessionServiceITest.class);
+ suite.addTestSuite(AuthorizationTest.class);
+ return suite;
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/AllTests.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/AllTests.java
new file mode 100644
index 0000000..3ebb658
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/AllTests.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.riena.security.authorizationservice.FilePermissionStoreTest;
+import org.eclipse.riena.security.common.Callback2CredentialConverterTest;
+
+/**
+ * Tests all test cases within package:
+ *
+ * org.eclipse.riena.exceptionmanager.test.internal
+ */
+public class AllTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTestSuite(FilePermissionStoreTest.class);
+ suite.addTestSuite(Callback2CredentialConverterTest.class);
+ return suite;
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/AuthorizationTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/AuthorizationTest.java
new file mode 100644
index 0000000..00a5891
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/AuthorizationTest.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.authorizationservice;
+
+import java.io.InputStream;
+import java.security.PrivilegedAction;
+
+import javax.security.auth.Subject;
+
+import org.eclipse.riena.internal.tests.Activator;
+import org.eclipse.riena.security.authorizationservice.store.FilePermissionStore;
+import org.eclipse.riena.security.common.authentication.SimplePrincipal;
+import org.eclipse.riena.security.common.authorization.IAuthorizationService;
+import org.eclipse.riena.security.common.authorization.RienaPolicy;
+import org.eclipse.riena.tests.RienaTestCase;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+public class AuthorizationTest extends RienaTestCase {
+
+ private ServiceRegistration fileStoreReg;
+ private ServiceRegistration authorizationServiceReg;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ // activate RienaPolicy
+ // I need to add a FilePermissionStore so that it can read the
+ // permissions for this test TODO
+ InputStream inputStream = this.getClass().getResourceAsStream("policy-def-test.xml");
+ FilePermissionStore store = new FilePermissionStore(inputStream);
+ fileStoreReg = Activator.getContext().registerService(IPermissionStore.ID, store, null);
+ ServiceReference ref = Activator.getContext().getServiceReference(IAuthorizationService.ID);
+ if (ref != null) {
+ ref.getBundle().stop();
+ }
+ authorizationServiceReg = Activator.getContext().registerService(IAuthorizationService.ID, new AuthorizationService(), null);
+
+ RienaPolicy.init();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ fileStoreReg.unregister();
+ authorizationServiceReg.unregister();
+ }
+
+ public void testWithoutUser() {
+ boolean result = new BusinessTestCase().hasPermission();
+ assertFalse("BusinessTestCase must fail without user", result);
+ }
+
+ public void testWithValidUser() {
+ Subject subject = new Subject();
+ subject.getPrincipals().add(new SimplePrincipal("testuser"));
+ Object x = System.getSecurityManager().getSecurityContext();
+
+ Boolean result = (Boolean) Subject.doAsPrivileged(subject, new PrivilegedAction() {
+
+ public Object run() {
+ return new Boolean(new BusinessTestCase().hasPermission());
+ }
+ }, null);
+ assertTrue("BusinessTestCase must work with valid user", result.equals(Boolean.TRUE));
+ }
+
+ public void testWithInvalidUser() {
+ Subject subject = new Subject();
+ subject.getPrincipals().add(new SimplePrincipal("anotheruser"));
+ Boolean result = (Boolean) Subject.doAsPrivileged(subject, new PrivilegedAction() {
+
+ public Object run() {
+ return new Boolean(new BusinessTestCase().hasPermission());
+ }
+ }, null);
+ assertTrue("BusinessTestCase must fail with invalid user", result.equals(Boolean.FALSE));
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/BusinessTestCase.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/BusinessTestCase.java
new file mode 100644
index 0000000..5b21882
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/BusinessTestCase.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.authorizationservice;
+
+import java.security.AccessControlException;
+
+/**
+ *
+ */
+public class BusinessTestCase {
+
+ boolean hasPermission() {
+ try {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPermission(new TestcasePermission("testPerm"));
+ return true;
+ }
+ return true;
+ } catch (AccessControlException ex) {
+ return false;
+ }
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/FilePermissionStoreTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/FilePermissionStoreTest.java
new file mode 100644
index 0000000..86c9aba
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/FilePermissionStoreTest.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.authorizationservice;
+
+import java.io.FileNotFoundException;
+import java.io.FilePermission;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.Permission;
+import java.security.Permissions;
+import java.util.Enumeration;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.riena.security.authorizationservice.store.FilePermissionStore;
+import org.eclipse.riena.security.common.authentication.SimplePrincipal;
+import org.xml.sax.SAXException;
+
+public class FilePermissionStoreTest extends TestCase {
+
+ public void testReadPermission() throws FileNotFoundException, SAXException, IOException, ParserConfigurationException {
+ InputStream inputStream = this.getClass().getResourceAsStream("policy-def-test.xml");
+ FilePermissionStore permStore = new FilePermissionStore(inputStream);
+ Permissions perms = permStore.loadPermissions(new SimplePrincipal("christian"));
+ assertTrue(perms != null);
+ Enumeration<Permission> enumPerms = perms.elements();
+ Permission p;
+ int count = 0;
+
+ while (enumPerms.hasMoreElements()) {
+ p = enumPerms.nextElement();
+ count++;
+ if (p instanceof FilePermission) {
+ FilePermission fp = (FilePermission) p;
+ assertEquals("*.tmp", fp.getName());
+ assertTrue(fp.getActions().equals("read"));
+ } else {
+ if (p instanceof TestcasePermission) {
+ TestcasePermission tcp = (TestcasePermission) p;
+ assertEquals("testPerm", tcp.getName());
+ } else {
+ assertTrue("unknown permission " + p, false);
+ }
+ }
+ }
+ assertTrue(count == 2);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/TestcasePermission.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/TestcasePermission.java
new file mode 100644
index 0000000..d761bd9
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/TestcasePermission.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.authorizationservice;
+
+import java.security.Permission;
+
+/**
+ *
+ */
+public class TestcasePermission extends Permission {
+
+ /**
+ * @param name
+ */
+ public TestcasePermission(String name) {
+ super(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.security.Permission#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof TestcasePermission) {
+ if (((TestcasePermission) obj).getName().equals(this.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.security.Permission#getActions()
+ */
+ @Override
+ public String getActions() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.security.Permission#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.security.Permission#implies(java.security.Permission)
+ */
+ @Override
+ public boolean implies(Permission permission) {
+ if (permission.equals(this)) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/policy-def-test.xml b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/policy-def-test.xml
new file mode 100644
index 0000000..7422eab
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/policy-def-test.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+
+<policy>
+
+ <principal
+ class="org.eclipse.riena.security.common.authentication.SimplePrincipal"
+ name="christian">
+ <permission class="java.io.FilePermission" name="*.tmp"
+ action="read" />
+ <permission
+ class="org.eclipse.riena.security.authorizationservice.TestcasePermission"
+ name="testPerm" />
+ </principal>
+ <principal
+ class="org.eclipse.riena.security.common.authentication.SimplePrincipal"
+ name="testuser">
+ <permission class="java.io.FilePermission" name="*.tmp"
+ action="read" />
+ <permission
+ class="org.eclipse.riena.security.authorizationservice.TestcasePermission"
+ name="testPerm" />
+ </principal>
+ <principal
+ class="org.eclipse.riena.security.common.authentication.SimplePrincipal"
+ name="anotheruser">
+ <permission class="java.io.FilePermission" name="*.tmp"
+ action="read" />
+ </principal>
+
+</policy>
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/common/Callback2CredentialConverterTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/common/Callback2CredentialConverterTest.java
new file mode 100644
index 0000000..318261c
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/common/Callback2CredentialConverterTest.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.common;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.TextInputCallback;
+
+import junit.framework.TestCase;
+
+import org.eclipse.riena.security.common.authentication.Callback2CredentialConverter;
+import org.eclipse.riena.security.common.authentication.credentials.AbstractCredential;
+import org.eclipse.riena.security.common.authentication.credentials.CustomCredential;
+import org.eclipse.riena.security.common.authentication.credentials.NameCredential;
+import org.eclipse.riena.security.common.authentication.credentials.PasswordCredential;
+import org.eclipse.riena.security.common.authentication.credentials.TextInputCredential;
+
+/**
+ *
+ */
+public class Callback2CredentialConverterTest extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testSimpleName1() {
+ Callback[] callbacks = new Callback[] { new NameCallback("userid", "cca") };
+
+ AbstractCredential[] credentials = Callback2CredentialConverter.callbacks2Credentials(callbacks);
+ assertTrue(credentials.length == 1);
+ assertTrue(credentials[0] instanceof NameCredential);
+ NameCredential nCred = (NameCredential) credentials[0];
+ assertTrue(nCred.getPrompt().equals("userid"));
+ assertTrue(nCred.getDefaultName().equals("cca"));
+ assertTrue(nCred.getName() == null);
+
+ Callback[] callbacksReturned = Callback2CredentialConverter.credentials2Callbacks(credentials);
+ assertTrue(callbacksReturned.length == 1);
+ assertTrue(callbacksReturned[0] instanceof NameCallback);
+ NameCallback ncb = (NameCallback) callbacksReturned[0];
+ assertTrue(ncb.getPrompt().equals("userid"));
+ assertTrue(ncb.getDefaultName().equals("cca"));
+ assertTrue(ncb.getName() == null);
+ }
+
+ public void testSimpleName2() {
+ NameCallback temp = new NameCallback("userid", "cca");
+ temp.setName("christian");
+ Callback[] callbacks = new Callback[] { temp };
+
+ AbstractCredential[] credentials = Callback2CredentialConverter.callbacks2Credentials(callbacks);
+ assertTrue(credentials.length == 1);
+ assertTrue(credentials[0] instanceof NameCredential);
+ NameCredential nCred = (NameCredential) credentials[0];
+ assertTrue(nCred.getPrompt().equals("userid"));
+ assertTrue(nCred.getDefaultName().equals("cca"));
+ assertTrue(nCred.getName().equals("christian"));
+
+ Callback[] callbacksReturned = Callback2CredentialConverter.credentials2Callbacks(credentials);
+ assertTrue(callbacksReturned.length == 1);
+ assertTrue(callbacksReturned[0] instanceof NameCallback);
+ NameCallback ncb = (NameCallback) callbacksReturned[0];
+ assertTrue(ncb.getPrompt().equals("userid"));
+ assertTrue(ncb.getDefaultName().equals("cca"));
+ assertTrue(ncb.getName().equals("christian"));
+ }
+
+ public void testMultipleCredentials() {
+ Callback[] callbacks = new Callback[] { new PasswordCallback("password", false), new TextInputCallback("textinp", "default-text") };
+
+ AbstractCredential[] credentials = Callback2CredentialConverter.callbacks2Credentials(callbacks);
+ assertTrue(credentials.length == 2);
+ assertTrue(credentials[0] instanceof PasswordCredential);
+ assertTrue(credentials[1] instanceof TextInputCredential);
+ PasswordCredential pc = (PasswordCredential) credentials[0];
+ TextInputCredential tic = (TextInputCredential) credentials[1];
+ assertTrue(pc.getPrompt().equals("password"));
+ assertTrue(pc.isEchoOn() == false);
+ assertTrue(tic.getPrompt().equals("textinp"));
+ assertTrue(tic.getDefaultText().equals("default-text"));
+ assertTrue(tic.getText() == null);
+
+ Callback[] callbacksReturned = Callback2CredentialConverter.credentials2Callbacks(credentials);
+ assertTrue(callbacksReturned.length == 2);
+ assertTrue(callbacksReturned[0] instanceof PasswordCallback);
+ assertTrue(callbacksReturned[1] instanceof TextInputCallback);
+ PasswordCallback pcb = (PasswordCallback) callbacksReturned[0];
+ TextInputCallback ticb = (TextInputCallback) callbacksReturned[1];
+ assertTrue(pcb.getPrompt().equals("password"));
+ assertTrue(pcb.isEchoOn() == false);
+ assertTrue(ticb.getPrompt().equals("textinp"));
+ assertTrue(ticb.getDefaultText().equals("default-text"));
+ assertTrue(ticb.getText() == null);
+ }
+
+ public void testCustomCredentials() {
+ Callback[] callbacks = new Callback[] { new MyCallback("valueOne", "valueTwo") };
+
+ AbstractCredential[] credentials = Callback2CredentialConverter.callbacks2Credentials(callbacks);
+
+ assertTrue(credentials.length == 1);
+ assertTrue(credentials[0] instanceof CustomCredential);
+
+ Callback[] callbacksReturned = Callback2CredentialConverter.credentials2Callbacks(credentials);
+ assertTrue(callbacksReturned.length == 1);
+ assertTrue(callbacksReturned[0] instanceof MyCallback);
+ MyCallback mycb = (MyCallback) callbacksReturned[0];
+ assertTrue(mycb.getValue1().equals("valueOne"));
+ assertTrue(mycb.getValue2().equals("valueTwo"));
+ }
+
+ public class MyCallback implements Callback {
+ private String value1;
+ private String value2;
+
+ public MyCallback(String value1, String value2) {
+ this.value1 = value1;
+ this.value2 = value2;
+ }
+
+ public String getValue1() {
+ return value1;
+ }
+
+ public String getValue2() {
+ return value2;
+ }
+
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/MyCallbackHandler.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/MyCallbackHandler.java
new file mode 100644
index 0000000..c885af5
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/MyCallbackHandler.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.services.itest;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.TextOutputCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+public class MyCallbackHandler implements CallbackHandler {
+
+ private String name;
+ private String password;
+
+ public MyCallbackHandler(String name, String password) {
+ this.name = name;
+ this.password = password;
+ }
+
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ for (int i = 0; i < callbacks.length; i++) {
+ if (callbacks[i] instanceof TextOutputCallback) {
+
+ // display the message according to the specified type
+ TextOutputCallback toc = (TextOutputCallback) callbacks[i];
+ switch (toc.getMessageType()) {
+ case TextOutputCallback.INFORMATION:
+ System.out.println(toc.getMessage());
+ break;
+ case TextOutputCallback.ERROR:
+ System.out.println("ERROR: " + toc.getMessage());
+ break;
+ case TextOutputCallback.WARNING:
+ System.out.println("WARNING: " + toc.getMessage());
+ break;
+ default:
+ throw new IOException("Unsupported message type: " + toc.getMessageType());
+ }
+
+ } else if (callbacks[i] instanceof NameCallback) {
+ // prompt the user for a username
+ NameCallback nc = (NameCallback) callbacks[i];
+
+ // System.err.print(nc.getPrompt());
+ // System.err.flush();
+ // nc.setName((new BufferedReader(new
+ // InputStreamReader(System.in))).readLine());
+ nc.setName(name);
+
+ } else if (callbacks[i] instanceof PasswordCallback) {
+
+ // prompt the user for sensitive information
+ PasswordCallback pc = (PasswordCallback) callbacks[i];
+ // System.err.print(pc.getPrompt());
+ // System.err.flush();
+ // pc.setPassword((new BufferedReader(new
+ // InputStreamReader(System.in))).readLine().toCharArray());
+ pc.setPassword(password.toCharArray());
+ }
+
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authentication/AuthenticationClientITest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authentication/AuthenticationClientITest.java
new file mode 100644
index 0000000..096c97e
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authentication/AuthenticationClientITest.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.services.itest.authentication;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+import org.eclipse.equinox.log.Logger;
+import org.eclipse.riena.communication.core.IRemoteServiceRegistration;
+import org.eclipse.riena.communication.core.factory.RemoteServiceFactory;
+import org.eclipse.riena.internal.tests.Activator;
+import org.eclipse.riena.security.common.ISubjectHolderService;
+import org.eclipse.riena.security.common.authentication.AuthenticationFailure;
+import org.eclipse.riena.security.common.authentication.AuthenticationTicket;
+import org.eclipse.riena.security.common.authentication.IAuthenticationService;
+import org.eclipse.riena.security.common.authentication.credentials.AbstractCredential;
+import org.eclipse.riena.security.common.authentication.credentials.NameCredential;
+import org.eclipse.riena.security.common.authentication.credentials.PasswordCredential;
+import org.eclipse.riena.security.server.session.ISessionService;
+import org.eclipse.riena.tests.RienaTestCase;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+/**
+ * Test client for authentication service.
+ *
+ */
+public class AuthenticationClientITest extends RienaTestCase {
+
+ private final static Logger LOGGER = Activator.getDefault().getLogger(AuthenticationClientITest.class.getName());
+ private IRemoteServiceRegistration sessionServiceRegistration;
+ private IRemoteServiceRegistration authenticationServiceRegistration;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ startBundles("org\\.eclipse\\.equinox\\.cm.*", null);
+ startBundles("org\\.eclipse\\.equinox\\.log.*", null);
+ startBundles("org\\.eclipse\\.riena.communication.core", null);
+ startBundles("org\\.eclipse\\.riena.communication.factory.hessian", null);
+ startBundles("org\\.eclipse\\.riena.communication.registry", null);
+ sessionServiceRegistration = new RemoteServiceFactory().createAndRegisterProxy(ISessionService.class, "http://localhost:8080/hessian/SessionService",
+ "hessian", "org.eclipse.riena.sessionservice");
+ authenticationServiceRegistration = new RemoteServiceFactory().createAndRegisterProxy(IAuthenticationService.class,
+ "http://localhost:8080/hessian/AuthenticationService", "hessian", "org.eclipse.riena.authenticationservice");
+
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ sessionServiceRegistration.unregister();
+ authenticationServiceRegistration.unregister();
+ }
+
+ /**
+ * org.eclipse.riena.tests the webservice call to authentication service
+ * with typeMapping
+ *
+ * @throws Exception
+ */
+ public void testLogin() throws Exception {
+ trace("Looking up Authentication Service...: ");
+
+ ServiceReference ref = Activator.getContext().getServiceReference(IAuthenticationService.ID);
+ IAuthenticationService authenticationService = (IAuthenticationService) Activator.getContext().getService(ref);
+
+ trace("Service looked up: " + authenticationService.getClass().getName());
+
+ AbstractCredential[] creds = new AbstractCredential[2];
+ NameCredential nc = new NameCredential("username: ", "xx");
+ nc.setName("cca");
+ creds[0] = nc;
+ PasswordCredential pc = new PasswordCredential("password: ", false);
+ pc.setPassword("christian".toCharArray());
+ creds[1] = pc;
+ trace("Add credential: " + creds);
+
+ AuthenticationTicket ticket = authenticationService.login("Test", creds);
+
+ trace("Return from login() - ticket: " + ticket);
+
+ assertNotNull(ticket);
+ assertNotNull(ticket.getSession());
+ assertNotNull(ticket.getPrincipals());
+
+ trace("Login successful - ticket: " + ticket);
+
+ // sign off
+ authenticationService.logout(ticket.getSession());
+
+ trace("Logoff successful.");
+ }
+
+ public void testInvalidLogin() throws Exception {
+
+ try {
+ ServiceReference ref = Activator.getContext().getServiceReference(IAuthenticationService.ID);
+ IAuthenticationService authenticationService = (IAuthenticationService) Activator.getContext().getService(ref);
+ AbstractCredential[] creds = new AbstractCredential[2];
+ NameCredential nc = new NameCredential("username: ", "xx");
+ nc.setName("john");
+ creds[0] = nc;
+ PasswordCredential pc = new PasswordCredential("password: ", false);
+ pc.setPassword("jane".toCharArray());
+ creds[1] = pc;
+ AuthenticationTicket ticket = authenticationService.login("Test", creds);
+ throw new RuntimeException("exception expected");
+ } catch (AuthenticationFailure e) {
+ // ok();
+ }
+ }
+
+ public void testSubjectLogin() throws Exception {
+ ServiceReference ref = Activator.getContext().getServiceReference(IAuthenticationService.ID);
+ IAuthenticationService authenticationService = (IAuthenticationService) Activator.getContext().getService(ref);
+
+ trace("Service looked up: " + authenticationService.getClass().getName());
+
+ AbstractCredential[] creds = new AbstractCredential[2];
+ NameCredential nc = new NameCredential("username: ", "xx");
+ nc.setName("cca");
+ creds[0] = nc;
+ PasswordCredential pc = new PasswordCredential("password: ", false);
+ pc.setPassword("christian".toCharArray());
+ creds[1] = pc;
+
+ AuthenticationTicket ticket = authenticationService.login("Test", creds);
+
+ trace("Return from login() - ticket: " + ticket);
+ Subject subject = new Subject();
+ for (Principal p : ticket.getPrincipals()) {
+ subject.getPrincipals().add(p);
+ }
+ ServiceReference ref2 = Activator.getContext().getServiceReference(ISubjectHolderService.ID);
+ ISubjectHolderService subHolderService = (ISubjectHolderService) Activator.getContext().getService(ref2);
+ subHolderService.fetchSubjectHolder().setSubject(subject);
+
+ assertTrue(subHolderService.fetchSubjectHolder().getSubject() == subject);
+ }
+
+ private void trace(String msg) {
+ LOGGER.log(LogService.LOG_INFO, "|--->" + msg);
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authentication/AuthenticationLoginModuleITest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authentication/AuthenticationLoginModuleITest.java
new file mode 100644
index 0000000..98f4e74
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authentication/AuthenticationLoginModuleITest.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.services.itest.authentication;
+
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+import org.eclipse.riena.communication.core.IRemoteServiceRegistration;
+import org.eclipse.riena.communication.core.factory.RemoteServiceFactory;
+import org.eclipse.riena.internal.tests.Activator;
+import org.eclipse.riena.security.common.authentication.IAuthenticationService;
+import org.eclipse.riena.security.common.session.ISessionHolderService;
+import org.eclipse.riena.security.services.itest.MyCallbackHandler;
+import org.eclipse.riena.tests.RienaTestCase;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @author campo
+ *
+ */
+public class AuthenticationLoginModuleITest extends RienaTestCase {
+
+ private IRemoteServiceRegistration authenticationService;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ startBundles("org\\.eclipse\\.riena.communication.core", null);
+ startBundles("org\\.eclipse\\.riena.communication.factory.hessian", null);
+ startBundles("org\\.eclipse\\.riena.communication.registry", null);
+ authenticationService = new RemoteServiceFactory().createAndRegisterProxy(IAuthenticationService.class,
+ "http://localhost:8080/hessian/AuthenticationService", "hessian", "org.eclipse.riena.authenticationservice");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ authenticationService.unregister();
+ }
+
+ public void testLogin() throws LoginException {
+ LoginContext lc = new LoginContext("Test", new MyCallbackHandler("testuser", "testpass"));
+ lc.login();
+ System.out.println("subject:" + lc.getSubject());
+ System.out.println("login in sucessful");
+ }
+
+ public void testRemoteLogin() throws LoginException {
+ LoginContext lc = new LoginContext("Remote", new MyCallbackHandler("testuser", "testpass"));
+ lc.login();
+ ServiceReference ref = Activator.getContext().getServiceReference(IAuthenticationService.ID);
+ IAuthenticationService as = (IAuthenticationService) Activator.getContext().getService(ref);
+ System.out.println("subject:" + lc.getSubject());
+ System.out.println("login in sucessful");
+ ISessionHolderService shs = (ISessionHolderService) Activator.getContext().getService(
+ Activator.getContext().getServiceReference(ISessionHolderService.ID));
+ as.logout(shs.fetchSessionHolder().getSession());
+ System.out.println("logoff sucessful");
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authorization/AuthorizationServiceITest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authorization/AuthorizationServiceITest.java
new file mode 100644
index 0000000..7d4656b
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/authorization/AuthorizationServiceITest.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.services.itest.authorization;
+
+import java.security.AccessControlException;
+
+import javax.security.auth.login.LoginContext;
+
+import org.eclipse.riena.communication.core.IRemoteServiceRegistration;
+import org.eclipse.riena.communication.core.factory.RemoteServiceFactory;
+import org.eclipse.riena.internal.tests.Activator;
+import org.eclipse.riena.sample.app.common.model.Customer;
+import org.eclipse.riena.sample.app.common.model.ICustomerSearch;
+import org.eclipse.riena.security.common.authentication.IAuthenticationService;
+import org.eclipse.riena.security.common.authorization.IAuthorizationService;
+import org.eclipse.riena.security.common.session.ISessionHolderService;
+import org.eclipse.riena.security.services.itest.MyCallbackHandler;
+import org.eclipse.riena.tests.RienaTestCase;
+import org.osgi.framework.ServiceReference;
+
+/**
+ *
+ */
+public class AuthorizationServiceITest extends RienaTestCase {
+
+ private IRemoteServiceRegistration authenticationService;
+ private IRemoteServiceRegistration authorizationService;
+ private IRemoteServiceRegistration customerService;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ startBundles("org\\.eclipse\\.riena.communication.core", null);
+ startBundles("org\\.eclipse\\.riena.communication.factory.hessian", null);
+ startBundles("org\\.eclipse\\.riena.communication.registry", null);
+ authenticationService = new RemoteServiceFactory().createAndRegisterProxy(IAuthenticationService.class,
+ "http://localhost:8080/hessian/AuthenticationService", "hessian", "org.eclipse.riena.authenticationservice");
+ authorizationService = new RemoteServiceFactory().createAndRegisterProxy(IAuthorizationService.class,
+ "http://localhost:8080/hessian/AuthorizationService", "hessian", "org.eclipse.riena.authorizationservice");
+ customerService = new RemoteServiceFactory().createAndRegisterProxy(ICustomerSearch.class, "http://localhost:8080/hessian/CustomerSearchWS", "hessian",
+ "org.eclipse.riena.customersearchservice");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ // TODO Auto-generated method stub
+ super.tearDown();
+ authenticationService.unregister();
+ authorizationService.unregister();
+ customerService.unregister();
+ }
+
+ public void testLoginWithUserWithRights() throws Exception {
+ LoginContext lc = new LoginContext("Remote", new MyCallbackHandler("testuser", "testpass"));
+ lc.login();
+ ServiceReference ref = Activator.getContext().getServiceReference(IAuthenticationService.ID);
+ IAuthenticationService as = (IAuthenticationService) Activator.getContext().getService(ref);
+ System.out.println("subject:" + lc.getSubject());
+ System.out.println("login in sucessful");
+ ISessionHolderService shs = (ISessionHolderService) Activator.getContext().getService(
+ Activator.getContext().getServiceReference(ISessionHolderService.ID));
+
+ // call the customerService
+ ICustomerSearch cs = (ICustomerSearch) Activator.getContext().getService(Activator.getContext().getServiceReference(ICustomerSearch.ID));
+ Customer cust = new Customer();
+ cust.setLastName("Solo");
+ cust.setFirstName("Han");
+ cust.setCustomerNumber(1);
+ Customer[] foundCustomers = cs.findCustomer(cust);
+ assertTrue(foundCustomers != null);
+ assertTrue(foundCustomers.length > 0);
+ assertTrue(foundCustomers[0].getLastName().equals("Solo"));
+
+ as.logout(shs.fetchSessionHolder().getSession());
+ System.out.println("logoff sucessful");
+ }
+
+ public void testLoginWithUserWithoutRights() throws Exception {
+ LoginContext lc = new LoginContext("Remote", new MyCallbackHandler("testuser2", "testpass2"));
+ lc.login();
+ ServiceReference ref = Activator.getContext().getServiceReference(IAuthenticationService.ID);
+ IAuthenticationService as = (IAuthenticationService) Activator.getContext().getService(ref);
+ System.out.println("subject:" + lc.getSubject());
+ System.out.println("login in sucessful");
+ ISessionHolderService shs = (ISessionHolderService) Activator.getContext().getService(
+ Activator.getContext().getServiceReference(ISessionHolderService.ID));
+
+ try {
+ // call the customerService
+ ICustomerSearch cs = (ICustomerSearch) Activator.getContext().getService(Activator.getContext().getServiceReference(ICustomerSearch.ID));
+ Customer cust = new Customer();
+ cust.setLastName("Solo");
+ cust.setFirstName("Han");
+ cust.setCustomerNumber(1);
+ Customer[] foundCustomers = cs.findCustomer(cust);
+ assertFalse("findCustomer must not work for testuser2 since it has to authorization", true);
+ // assertTrue(foundCustomers != null);
+ // assertTrue(foundCustomers.length > 0);
+ // assertTrue(foundCustomers[0].getLastName().equals("Solo"));
+ } catch (AccessControlException ex) {
+ // expected exception
+ }
+
+ as.logout(shs.fetchSessionHolder().getSession());
+ System.out.println("logoff sucessful");
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/module/ClientRemoteLoginModule.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/module/ClientRemoteLoginModule.java
new file mode 100644
index 0000000..615d7b3
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/module/ClientRemoteLoginModule.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.services.itest.module;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+import org.eclipse.riena.security.common.authentication.AuthenticationTicket;
+import org.eclipse.riena.security.common.authentication.ClientLogin;
+
+/**
+ * Test module that implements the JAAS LoginModule interface
+ *
+ */
+public class ClientRemoteLoginModule implements LoginModule {
+
+ private Subject subject;
+ private CallbackHandler callbackHandler;
+ private Map<String, ?> sharedState;
+ private Map<String, ?> options;
+
+ // configurable option
+ private boolean debug = false;
+
+ String username;
+ String password;
+ AuthenticationTicket ticket;
+ ClientLogin clientLogin;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#abort()
+ */
+ public boolean abort() throws LoginException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#commit()
+ */
+ public boolean commit() throws LoginException {
+ return clientLogin.commit();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#initialize(javax.security.auth.Subject,
+ * javax.security.auth.callback.CallbackHandler, java.util.Map,
+ * java.util.Map)
+ */
+ public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
+ this.subject = subject;
+ this.callbackHandler = callbackHandler;
+ this.sharedState = sharedState;
+ this.options = options;
+ this.clientLogin = new ClientLogin("Test", subject);
+
+ // initialize any configured options
+ debug = "true".equalsIgnoreCase((String) options.get("debug"));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#login()
+ */
+ public boolean login() throws LoginException {
+ Callback[] callbacks = new Callback[2];
+ callbacks[0] = new NameCallback("username: ");
+ callbacks[1] = new PasswordCallback("password: ", false);
+ if (callbackHandler == null) {
+ System.out.println("callbackhandler cant be null");
+ return false;
+ }
+ try {
+ callbackHandler.handle(callbacks);
+ username = ((NameCallback) callbacks[0]).getName();
+ password = new String(((PasswordCallback) callbacks[1]).getPassword());
+ return clientLogin.login(callbacks);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ } catch (UnsupportedCallbackException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#logout()
+ */
+ public boolean logout() throws LoginException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/module/LocalLoginModule.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/module/LocalLoginModule.java
new file mode 100644
index 0000000..fcde012
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/module/LocalLoginModule.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.services.itest.module;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+import org.eclipse.riena.security.common.authentication.SimplePrincipal;
+
+/**
+ * Test module that implements the JAAS LoginModule interface
+ *
+ */
+public class LocalLoginModule implements LoginModule {
+
+ private Subject subject;
+ private CallbackHandler callbackHandler;
+ private Map<String, ?> sharedState;
+ private Map<String, ?> options;
+
+ // configurable option
+ private boolean debug = false;
+
+ String username;
+ String password;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#abort()
+ */
+ public boolean abort() throws LoginException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#commit()
+ */
+ public boolean commit() throws LoginException {
+ subject.getPrincipals().add(new SimplePrincipal(username));
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#initialize(javax.security.auth.Subject,
+ * javax.security.auth.callback.CallbackHandler, java.util.Map,
+ * java.util.Map)
+ */
+ public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
+ this.subject = subject;
+ this.callbackHandler = callbackHandler;
+ this.sharedState = sharedState;
+ this.options = options;
+
+ // initialize any configured options
+ debug = "true".equalsIgnoreCase((String) options.get("debug"));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#login()
+ */
+ public boolean login() throws LoginException {
+ Callback[] callbacks = new Callback[2];
+ callbacks[0] = new NameCallback("username: ");
+ callbacks[1] = new PasswordCallback("password: ", false);
+ if (callbackHandler == null) {
+ System.out.println("callbackhandler cant be null");
+ return false;
+ }
+ try {
+ callbackHandler.handle(callbacks);
+ username = ((NameCallback) callbacks[0]).getName();
+ password = new String(((PasswordCallback) callbacks[1]).getPassword());
+ if (username != null && username.equals("testuser") && password != null && password.equals("testpass")) {
+ return true;
+ } else {
+ if (username != null && username.equals("cca") && password != null && password.equals("christian")) {
+ return true;
+ }
+ }
+
+ return false;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ } catch (UnsupportedCallbackException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.security.auth.spi.LoginModule#logout()
+ */
+ public boolean logout() throws LoginException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/session/SessionServiceITest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/session/SessionServiceITest.java
new file mode 100644
index 0000000..6be2070
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/services/itest/session/SessionServiceITest.java
@@ -0,0 +1,155 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.security.services.itest.session;
+
+import java.security.Principal;
+
+import org.eclipse.riena.communication.core.factory.RemoteServiceFactory;
+import org.eclipse.riena.internal.tests.Activator;
+import org.eclipse.riena.security.common.authentication.SimplePrincipal;
+import org.eclipse.riena.security.common.session.Session;
+import org.eclipse.riena.security.server.session.ISessionService;
+import org.eclipse.riena.tests.RienaTestCase;
+import org.osgi.framework.ServiceReference;
+
+
+/**
+ * Tests the SessionService with single user. There is also a disabled multiuser
+ * test. Its disabled because it seems to fail for problem laying the webservice
+ * area.
+ *
+ */
+public class SessionServiceITest extends RienaTestCase {
+
+ private final static int LOOP_5 = 5;
+ private final static int LOOP_20 = 20;
+ private final static int LOOP_100 = 100;
+ private final static int LOOP_400 = 400;
+ private final static int THREAD_5 = 5;
+ private final static int THREAD_20 = 20;
+ private final static int THREAD_100 = 100;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ startBundles("org\\.eclipse\\.equinox\\.cm.*", null);
+ startBundles("org\\.eclipse\\.equinox\\.log.*", null);
+ startBundles("org\\.eclipse\\.riena.communication.core", null);
+ startBundles("org\\.eclipse\\.riena.communication.factory.hessian", null);
+ startBundles("org\\.eclipse\\.riena.communication.registry", null);
+ new RemoteServiceFactory().createAndRegisterProxy(ISessionService.class, "http://localhost:8080/hessian/SessionService", "hessian",
+ "org.eclipse.riena.sessionservice");
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * @throws Exception
+ */
+ public void testController1() throws Exception {
+ ServiceReference ref = Activator.getContext().getServiceReference(ISessionService.ID);
+ ISessionService sessionService = (ISessionService) Activator.getContext().getService(ref);
+ assertNotNull("SessionControllerAccessor returns null", sessionService);
+ Session session = sessionService.generateSession(new Principal[] { new SimplePrincipal("testuid") });
+ assertNotNull("generateSession returns null", session);
+
+ Principal[] principals = sessionService.findPrincipals(session);
+ assertNotNull("findUser returns null", principals);
+ assertTrue("returned userid is not equal to the correct one", principals[0].getName().equals("testuid"));
+
+ sessionService.invalidateSession(session);
+ assertFalse("session should be invalid", sessionService.isValidSession(session));
+
+ Principal[] temp = sessionService.findPrincipals(session);
+ assertNull("no user should be found for invalid session", temp);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public void texxstMultiuser() throws Exception {
+ createNNNThreads(THREAD_5, LOOP_5);
+ createNNNThreads(THREAD_5, LOOP_20);
+ createNNNThreads(THREAD_20, LOOP_20);
+ createNNNThreads(THREAD_100, LOOP_20);
+ createNNNThreads(THREAD_100, LOOP_100);
+ createNNNThreads(THREAD_100, LOOP_400);
+ }
+
+ private void createNNNThreads(int noOfThreads, int loopCounter) {
+ Thread[] t = new Thread[noOfThreads];
+ // trace("threads=" + noOfThreads + " loop=" + loopCounter);
+ // create threads
+ for (int i = 0; i < noOfThreads; i++) {
+ t[i] = new Threader(loopCounter);
+ // trace("C");
+ }
+
+ // start threads
+ for (int i = 0; i < noOfThreads; i++) {
+ t[i].start();
+ // trace("S");
+ }
+
+ // wait for them to finish
+ int activeThreads = noOfThreads;
+ while (activeThreads > 0) {
+ for (int i = 0; i < noOfThreads && activeThreads > 0; i++) {
+ if (t[i] != null) {
+ if (!t[i].isAlive()) {
+ activeThreads--;
+ // trace("D");
+ }
+ }
+ }
+ }
+ // trace("");
+ }
+
+ class Threader extends Thread {
+ private ISessionService sessionService;
+ private int loopCounter;
+
+ Threader(int loopCounter) {
+ ServiceReference ref = Activator.getContext().getServiceReference(ISessionService.ID);
+ sessionService = (ISessionService) Activator.getContext().getService(ref);
+ this.loopCounter = loopCounter;
+ assertNotNull("SessionServiceAccessor returns null", sessionService);
+ }
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ for (int i = 0; i < loopCounter; i++) {
+ Session session = sessionService.generateSession(new Principal[] { new SimplePrincipal("testuid") });
+ assertNotNull("generateSession returns null", session);
+
+ Principal[] principals = sessionService.findPrincipals(session);
+ assertTrue("returned userid is not equal to the correct one", principals == null || principals[0].getName().equals("testuid"));
+
+ sessionService.invalidateSession(session);
+
+ Principal[] temp = sessionService.findPrincipals(session);
+ assertTrue("no user should be found for invalid session", temp == null || temp[0].getName().equals("testuid"));
+ }
+ // SessionServiceITest.this.trace("K");
+ }
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/tests/AllTests.java b/org.eclipse.riena.tests/src/org/eclipse/riena/tests/AllTests.java
new file mode 100644
index 0000000..a2b1e95
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/tests/AllTests.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.tests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Tests all test cases within this bundle
+ */
+public class AllTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTest(org.eclipse.riena.core.AllTests.suite());
+ suite.addTest(org.eclipse.riena.exceptionmanager.AllTests.suite());
+ suite.addTest(org.eclipse.riena.security.AllTests.suite());
+ return suite;
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/tests/RienaTestCase.java b/org.eclipse.riena.tests/src/org/eclipse/riena/tests/RienaTestCase.java
new file mode 100644
index 0000000..740aa4d
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/tests/RienaTestCase.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.tests;
+
+import java.util.regex.Pattern;
+
+import junit.framework.TestCase;
+
+import org.eclipse.riena.internal.tests.Activator;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+/**
+ * @author campo
+ *
+ */
+public class RienaTestCase extends TestCase {
+
+ /**
+ *
+ */
+ public RienaTestCase() {
+ super();
+ }
+
+ /**
+ * @param name
+ */
+ public RienaTestCase(String name) {
+ super(name);
+ }
+
+ public void startBundles(String truePattern, String falsePattern) throws BundleException {
+ if (truePattern == null) {
+ throw new UnsupportedOperationException("truePattern must be set");
+ }
+ if (falsePattern == null) {
+ falsePattern = "";
+ }
+ Pattern truePat = Pattern.compile(truePattern);
+ Pattern falsePat = Pattern.compile(falsePattern);
+ BundleContext context = Activator.getContext();
+
+ Bundle[] bundles = context.getBundles();
+ for (Bundle bundle : bundles) {
+ if (truePat.matcher(bundle.getSymbolicName()).matches() && !(falsePat.matcher(bundle.getSymbolicName()).matches())
+ && (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING) /*
+ * &&
+ * !(bundle
+ * instanceof
+ * BundleFragment)
+ */) {
+ bundle.start();
+ }
+ }
+
+ }
+
+}