summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Campo2008-01-17 09:58:54 (EST)
committerChristian Campo2008-01-17 09:58:54 (EST)
commit24d40056a3f12b0cf3b5153df01f0dd9cb141d4c (patch)
treea108a356ba03da7cbac973deae4bd89fbf47dbd1
parentcd468f15eecda0c82b1c2eefa36703dd47b36a5d (diff)
downloadorg.eclipse.riena-24d40056a3f12b0cf3b5153df01f0dd9cb141d4c.zip
org.eclipse.riena-24d40056a3f12b0cf3b5153df01f0dd9cb141d4c.tar.gz
org.eclipse.riena-24d40056a3f12b0cf3b5153df01f0dd9cb141d4c.tar.bz2
added test for new Sentinal called SentinelTest
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/SentinelTest.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/SentinelTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/SentinelTest.java
new file mode 100644
index 0000000..b703170
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/security/authorizationservice/SentinelTest.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.security.authorizationservice;
+
+import java.io.InputStream;
+
+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.ISubjectHolderService;
+import org.eclipse.riena.security.common.authentication.SimplePrincipal;
+import org.eclipse.riena.security.common.authorization.IAuthorizationService;
+import org.eclipse.riena.security.common.authorization.Sentinel;
+import org.eclipse.riena.tests.RienaTestCase;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Tests the Sentinal which means we are testing for permissions without
+ * actually activating java security. Permissions are checked by the Sentinel
+ * instead
+ */
+public class SentinelTest extends RienaTestCase {
+ private ServiceRegistration fileStoreReg;
+ private ServiceRegistration authorizationServiceReg;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ fileStoreReg.unregister();
+ authorizationServiceReg.unregister();
+ }
+
+ public void testWithoutUser() {
+ boolean result = Sentinel.checkAccess(new TestcasePermission("testPerm"));
+ assertFalse("no permission if there is no subject", result);
+ }
+
+ public void testValidUser() {
+ Subject subject = new Subject();
+ subject.getPrincipals().add(new SimplePrincipal("testuser"));
+ ISubjectHolderService subjectHolderService = (ISubjectHolderService) Activator.getContext().getService(
+ Activator.getContext().getServiceReference(ISubjectHolderService.ID));
+ subjectHolderService.fetchSubjectHolder().setSubject(subject);
+
+ boolean result = Sentinel.checkAccess(new TestcasePermission("testPerm"));
+ assertTrue("has permission since valid subject", result);
+ }
+
+ public void testValidUserMissingPermissions() {
+ Subject subject = new Subject();
+ subject.getPrincipals().add(new SimplePrincipal("anotheruser"));
+ ISubjectHolderService subjectHolderService = (ISubjectHolderService) Activator.getContext().getService(
+ Activator.getContext().getServiceReference(ISubjectHolderService.ID));
+ subjectHolderService.fetchSubjectHolder().setSubject(subject);
+
+ boolean result = Sentinel.checkAccess(new TestcasePermission("testPerm"));
+ assertFalse("has no permission since subject has no permission", result);
+
+ }
+}