You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by re...@apache.org on 2012/08/23 21:50:09 UTC
svn commit: r1376665 [1/2] - in /incubator/stanbol/trunk: commons/
commons/authentication.basic/ commons/authentication.basic/.settings/
commons/authentication.basic/src/ commons/authentication.basic/src/main/
commons/authentication.basic/src/main/appe...
Author: reto
Date: Thu Aug 23 19:50:06 2012
New Revision: 1376665
URL: http://svn.apache.org/viewvc?rev=1376665&view=rev
Log:
CLEREZZA-721: enabling a security context for now only when started with -s option. Added filter that ensures servlet execution as the logged in user, doing basic-auth to identify the user if the users request results in a SecurityException
Added:
incubator/stanbol/trunk/commons/authentication.basic/ (with props)
incubator/stanbol/trunk/commons/authentication.basic/.classpath
incubator/stanbol/trunk/commons/authentication.basic/.project
incubator/stanbol/trunk/commons/authentication.basic/.settings/
incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.core.resources.prefs
incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.jdt.core.prefs
incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.m2e.core.prefs
incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.pde.core.prefs
incubator/stanbol/trunk/commons/authentication.basic/LICENSE
incubator/stanbol/trunk/commons/authentication.basic/pom.xml
incubator/stanbol/trunk/commons/authentication.basic/src/
incubator/stanbol/trunk/commons/authentication.basic/src/main/
incubator/stanbol/trunk/commons/authentication.basic/src/main/appended-resources/
incubator/stanbol/trunk/commons/authentication.basic/src/main/appended-resources/META-INF/
incubator/stanbol/trunk/commons/authentication.basic/src/main/java/
incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/
incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/
incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/stanbol/
incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/stanbol/commons/
incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/
incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/basic/
incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/basic/BasicAuthentication.java
incubator/stanbol/trunk/commons/security/ (with props)
incubator/stanbol/trunk/commons/security/.classpath
incubator/stanbol/trunk/commons/security/.project
incubator/stanbol/trunk/commons/security/.settings/
incubator/stanbol/trunk/commons/security/.settings/org.eclipse.core.resources.prefs
incubator/stanbol/trunk/commons/security/.settings/org.eclipse.jdt.core.prefs
incubator/stanbol/trunk/commons/security/.settings/org.eclipse.m2e.core.prefs
incubator/stanbol/trunk/commons/security/.settings/org.eclipse.pde.core.prefs
incubator/stanbol/trunk/commons/security/LICENSE
incubator/stanbol/trunk/commons/security/pom.xml
incubator/stanbol/trunk/commons/security/src/
incubator/stanbol/trunk/commons/security/src/main/
incubator/stanbol/trunk/commons/security/src/main/appended-resources/
incubator/stanbol/trunk/commons/security/src/main/appended-resources/META-INF/
incubator/stanbol/trunk/commons/security/src/main/java/
incubator/stanbol/trunk/commons/security/src/main/java/org/
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PasswordUtil.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PermissionDefinitions.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/SecurityActivator.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserAwarePolicy.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserPermissionsCache.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUnregisteredException.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUtil.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/WebIdBasedPermissionProvider.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticatingFilter.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationChecker.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationCheckerImpl.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationMethod.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationService.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/CheckAuthenticationPermission.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/LoginException.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/LoginListener.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/NoSuchAgent.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/PrincipalImpl.java
incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/auth/WeightedAuthenticationMethod.java
incubator/stanbol/trunk/commons/security/src/main/resources/
incubator/stanbol/trunk/commons/security/src/main/resources/META-INF/
incubator/stanbol/trunk/commons/security/src/main/resources/META-INF/documentation.nt
incubator/stanbol/trunk/commons/security/src/test/
incubator/stanbol/trunk/commons/security/src/test/java/
incubator/stanbol/trunk/commons/security/src/test/java/org/
incubator/stanbol/trunk/commons/security/src/test/java/org/apache/
incubator/stanbol/trunk/commons/security/src/test/java/org/apache/stanbol/
incubator/stanbol/trunk/commons/security/src/test/java/org/apache/stanbol/commons/
incubator/stanbol/trunk/commons/security/src/test/java/org/apache/stanbol/commons/security/
incubator/stanbol/trunk/commons/security/src/test/java/org/apache/stanbol/commons/security/PermissionDefinitionsTest.java
incubator/stanbol/trunk/commons/security/src/test/resources/
incubator/stanbol/trunk/commons/security/src/test/resources/org/
incubator/stanbol/trunk/commons/security/src/test/resources/org/apache/
incubator/stanbol/trunk/commons/security/src/test/resources/org/apache/stanbol/
incubator/stanbol/trunk/commons/security/src/test/resources/org/apache/stanbol/commons/
incubator/stanbol/trunk/commons/security/src/test/resources/org/apache/stanbol/commons/security/
incubator/stanbol/trunk/commons/security/src/test/resources/org/apache/stanbol/commons/security/systemgraph.nt
Modified:
incubator/stanbol/trunk/commons/ (props changed)
incubator/stanbol/trunk/commons/launchpad/src/main/java/org/apache/stanbol/launchpad/Main.java
incubator/stanbol/trunk/commons/pom.xml
incubator/stanbol/trunk/launchers/bundlelists/stanbolcommons/src/main/bundles/list.xml
incubator/stanbol/trunk/launchers/full/ (props changed)
Propchange: incubator/stanbol/trunk/commons/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Aug 23 19:50:06 2012
@@ -8,3 +8,4 @@ bin
.classpath
.externalToolBuilders
maven-eclipse.xml
+.pom.xml.swp
Propchange: incubator/stanbol/trunk/commons/authentication.basic/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 23 19:50:06 2012
@@ -0,0 +1 @@
+target
Added: incubator/stanbol/trunk/commons/authentication.basic/.classpath
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/authentication.basic/.classpath?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/authentication.basic/.classpath (added)
+++ incubator/stanbol/trunk/commons/authentication.basic/.classpath Thu Aug 23 19:50:06 2012
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: incubator/stanbol/trunk/commons/authentication.basic/.project
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/authentication.basic/.project?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/authentication.basic/.project (added)
+++ incubator/stanbol/trunk/commons/authentication.basic/.project Thu Aug 23 19:50:06 2012
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.apache.stanbol.commons.authentication.basic</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.core.resources.prefs
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.core.resources.prefs?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.core.resources.prefs (added)
+++ incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.core.resources.prefs Thu Aug 23 19:50:06 2012
@@ -0,0 +1,4 @@
+#Thu Aug 23 14:35:11 CEST 2012
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding/<project>=UTF-8
Added: incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.jdt.core.prefs?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.jdt.core.prefs Thu Aug 23 19:50:06 2012
@@ -0,0 +1,6 @@
+#Thu Aug 23 14:35:11 CEST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
Added: incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.m2e.core.prefs
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.m2e.core.prefs?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.m2e.core.prefs (added)
+++ incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.m2e.core.prefs Thu Aug 23 19:50:06 2012
@@ -0,0 +1,5 @@
+#Thu Aug 23 14:31:44 CEST 2012
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
Added: incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.pde.core.prefs
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.pde.core.prefs?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.pde.core.prefs (added)
+++ incubator/stanbol/trunk/commons/authentication.basic/.settings/org.eclipse.pde.core.prefs Thu Aug 23 19:50:06 2012
@@ -0,0 +1,3 @@
+#Thu Aug 23 14:35:11 CEST 2012
+BUNDLE_ROOT_PATH=target/classes
+eclipse.preferences.version=1
Added: incubator/stanbol/trunk/commons/authentication.basic/LICENSE
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/authentication.basic/LICENSE?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/authentication.basic/LICENSE (added)
+++ incubator/stanbol/trunk/commons/authentication.basic/LICENSE Thu Aug 23 19:50:06 2012
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
Added: incubator/stanbol/trunk/commons/authentication.basic/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/authentication.basic/pom.xml?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/authentication.basic/pom.xml (added)
+++ incubator/stanbol/trunk/commons/authentication.basic/pom.xml Thu Aug 23 19:50:06 2012
@@ -0,0 +1,69 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>stanbol-parent</artifactId>
+ <version>2-incubating-SNAPSHOT</version>
+ <relativePath>../../parent</relativePath>
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.authentication.basic</artifactId>
+ <version>0.10.0-incubating-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Stanbol Commons Basic Authenticator</name>
+ <description>An Authenticator for HTTP Basic auth.</description>
+ <build>
+ <!-- make it an OSGi bundle -->
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.core</artifactId>
+ </dependency>
+ <!-- <dependency>
+ <groupId>org.wymiwyg</groupId>
+ <artifactId>wymiwyg-commons-core</artifactId>
+ </dependency> -->
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.security</artifactId>
+ <version>0.10.0-incubating-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/basic/BasicAuthentication.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/basic/BasicAuthentication.java?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/basic/BasicAuthentication.java (added)
+++ incubator/stanbol/trunk/commons/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/basic/BasicAuthentication.java Thu Aug 23 19:50:06 2012
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stanbol.commons.authentication.basic;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.security.AccessControlException;
+
+import javax.security.auth.Subject;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.security.UserUtil;
+import org.apache.stanbol.commons.security.auth.AuthenticationService;
+import org.apache.stanbol.commons.security.auth.LoginException;
+import org.apache.stanbol.commons.security.auth.NoSuchAgent;
+import org.apache.stanbol.commons.security.auth.PrincipalImpl;
+import org.apache.stanbol.commons.security.auth.WeightedAuthenticationMethod;
+import org.osgi.service.component.ComponentContext;
+import org.wymiwyg.commons.util.Base64;
+
+
+@Component
+@Service(WeightedAuthenticationMethod.class)
+@Property(name = "weight", intValue = 10)
+public class BasicAuthentication implements WeightedAuthenticationMethod {
+
+ /**
+ * weight of the authentication method
+ */
+ private int weight = 10;
+
+ @Reference
+ AuthenticationService authenticationService;
+
+ public void activate(ComponentContext componentContext) {
+ weight = (Integer) componentContext.getProperties().get("weight");
+ }
+
+ @Override
+ public boolean authenticate(HttpServletRequest request, Subject subject)
+ throws LoginException, ServletException {
+ String authorization = request.getHeader("Authorization");
+ if (authorization != null) {
+ String authBase64 = authorization.substring(authorization.indexOf(' ') + 1);
+ String[] credentials = new String(Base64.decode(authBase64)).split(":");
+ String userName = credentials[0];
+ String password;
+ if (credentials.length > 1) {
+ password = credentials[1];
+ } else {
+ password = "";
+ }
+ try {
+ if (authenticationService.authenticateUser(userName, password)) {
+ subject.getPrincipals().remove(UserUtil.ANONYMOUS);
+ subject.getPrincipals().add(new PrincipalImpl(userName));
+ return true;
+ } else {
+ throw new LoginException(LoginException.PASSWORD_NOT_MATCHING);
+ }
+ } catch (NoSuchAgent ex) {
+ throw new LoginException(LoginException.USER_NOT_EXISTING);
+ }
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean writeLoginResponse(HttpServletRequest request,
+ HttpServletResponse response, Throwable cause) throws ServletException, IOException {
+ if (cause == null || cause instanceof AccessControlException) {
+ setUnauthorizedResponse(response,
+ "<html><body>unauthorized</body></html>");
+ return true;
+ }
+ if (cause instanceof LoginException) {
+ LoginException loginException = (LoginException) cause;
+ String type = loginException.getType();
+ if (type.equals(LoginException.PASSWORD_NOT_MATCHING)) {
+ setUnauthorizedResponse(response,
+ "<html><body>Username and password do not match</body></html>");
+ return true;
+ }
+ if (type.equals(LoginException.USER_NOT_EXISTING)) {
+ setUnauthorizedResponse(response,
+ "<html><body>User does not exist</body></html>");
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void setUnauthorizedResponse(final HttpServletResponse response, String message)
+ throws ServletException, IOException {
+ response.setStatus(401);
+ response.addHeader("WWW-Authenticate",
+ "Basic realm=\"Clerezza Platform authentication needed\"");
+ final java.io.InputStream pipedIn = new ByteArrayInputStream(message.getBytes());
+ response.setHeader("Content-Length", ""+message.getBytes().length);
+ response.getOutputStream().write(message.getBytes());
+ }
+
+ @Override
+ public int getWeight() {
+ return weight;
+ }
+
+
+
+}
Modified: incubator/stanbol/trunk/commons/launchpad/src/main/java/org/apache/stanbol/launchpad/Main.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/launchpad/src/main/java/org/apache/stanbol/launchpad/Main.java?rev=1376665&r1=1376664&r2=1376665&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/launchpad/src/main/java/org/apache/stanbol/launchpad/Main.java (original)
+++ incubator/stanbol/trunk/commons/launchpad/src/main/java/org/apache/stanbol/launchpad/Main.java Thu Aug 23 19:50:06 2012
@@ -19,6 +19,16 @@ package org.apache.stanbol.launchpad;
import static org.apache.sling.launchpad.base.shared.SharedConstants.SLING_HOME;
import java.io.File;
+import java.security.AllPermission;
+import java.security.PermissionCollection;
+import java.security.Permissions;
+import java.security.Policy;
+import java.security.ProtectionDomain;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
public class Main {
@@ -33,6 +43,20 @@ public class Main {
home = new File(DEFAULT_STANBOL_HOME).getAbsolutePath();
System.setProperty(SLING_HOME, home);
} //else do not override user configured values
+ List<String> argsList = new ArrayList<String>(Arrays.asList(args));
+ if (argsList.contains("-s")) {
+ argsList.remove("-s");
+ args = argsList.toArray(new String[argsList.size()]);
+ Policy.setPolicy(new Policy() {
+ @Override
+ public PermissionCollection getPermissions(ProtectionDomain domain) {
+ PermissionCollection result = new Permissions();
+ result.add(new AllPermission());
+ return result;
+ }
+ });
+ System.setSecurityManager(new SecurityManager());
+ }
//now use the standard Apache Sling launcher to do the job
org.apache.sling.launchpad.app.Main.main(args);
}
Modified: incubator/stanbol/trunk/commons/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/pom.xml?rev=1376665&r1=1376664&r2=1376665&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/pom.xml (original)
+++ incubator/stanbol/trunk/commons/pom.xml Thu Aug 23 19:50:06 2012
@@ -61,6 +61,8 @@
<module>ldpath/clerezza</module>
<module>httpqueryheaders</module>
<module>launchpad</module>
+ <module>security</module>
+ <module>authentication.basic</module>
<module>testing/jarexec</module>
<module>testing/http</module>
Propchange: incubator/stanbol/trunk/commons/security/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 23 19:50:06 2012
@@ -0,0 +1 @@
+target
Added: incubator/stanbol/trunk/commons/security/.classpath
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/.classpath?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/.classpath (added)
+++ incubator/stanbol/trunk/commons/security/.classpath Thu Aug 23 19:50:06 2012
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: incubator/stanbol/trunk/commons/security/.project
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/.project?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/.project (added)
+++ incubator/stanbol/trunk/commons/security/.project Thu Aug 23 19:50:06 2012
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.apache.stanbol.commons.authentication</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: incubator/stanbol/trunk/commons/security/.settings/org.eclipse.core.resources.prefs
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/.settings/org.eclipse.core.resources.prefs?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/.settings/org.eclipse.core.resources.prefs (added)
+++ incubator/stanbol/trunk/commons/security/.settings/org.eclipse.core.resources.prefs Thu Aug 23 19:50:06 2012
@@ -0,0 +1,7 @@
+#Thu Aug 23 11:35:40 CEST 2012
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
+encoding//src/test/java=UTF-8
+encoding//src/test/resources=UTF-8
+encoding/<project>=UTF-8
Added: incubator/stanbol/trunk/commons/security/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/.settings/org.eclipse.jdt.core.prefs?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/stanbol/trunk/commons/security/.settings/org.eclipse.jdt.core.prefs Thu Aug 23 19:50:06 2012
@@ -0,0 +1,6 @@
+#Thu Aug 23 11:35:40 CEST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
Added: incubator/stanbol/trunk/commons/security/.settings/org.eclipse.m2e.core.prefs
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/.settings/org.eclipse.m2e.core.prefs?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/.settings/org.eclipse.m2e.core.prefs (added)
+++ incubator/stanbol/trunk/commons/security/.settings/org.eclipse.m2e.core.prefs Thu Aug 23 19:50:06 2012
@@ -0,0 +1,5 @@
+#Thu Aug 23 11:31:52 CEST 2012
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
Added: incubator/stanbol/trunk/commons/security/.settings/org.eclipse.pde.core.prefs
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/.settings/org.eclipse.pde.core.prefs?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/.settings/org.eclipse.pde.core.prefs (added)
+++ incubator/stanbol/trunk/commons/security/.settings/org.eclipse.pde.core.prefs Thu Aug 23 19:50:06 2012
@@ -0,0 +1,3 @@
+#Thu Aug 23 11:35:40 CEST 2012
+BUNDLE_ROOT_PATH=target/classes
+eclipse.preferences.version=1
Added: incubator/stanbol/trunk/commons/security/LICENSE
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/LICENSE?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/LICENSE (added)
+++ incubator/stanbol/trunk/commons/security/LICENSE Thu Aug 23 19:50:06 2012
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
Added: incubator/stanbol/trunk/commons/security/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/pom.xml?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/pom.xml (added)
+++ incubator/stanbol/trunk/commons/security/pom.xml Thu Aug 23 19:50:06 2012
@@ -0,0 +1,114 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>stanbol-parent</artifactId>
+ <version>2-incubating-SNAPSHOT</version>
+ <relativePath>../../parent</relativePath>
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.security</artifactId>
+ <version>0.10.0-incubating-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Stanbol Commons Security</name>
+ <description>An Servlet Filter authenticating the user if a security exception
+ occurs and executes the following handling chain as the authenticated user.
+ Significant portions of the code are ported from apache clerezza platform.security</description>
+ <build>
+ <!-- make it an OSGi bundle -->
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>org.apache.stanbol.commons.security,org.apache.stanbol.commons.security.auth</Export-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.jena.parser</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.ontologies</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>platform.config</artifactId>
+ <version>0.3-incubating</version>
+ </dependency>
+ <!-- <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>permissiondescriptions</artifactId>
+ <version>0.1-incubating</version>
+ </dependency> -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PasswordUtil.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PasswordUtil.java?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PasswordUtil.java (added)
+++ incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PasswordUtil.java Thu Aug 23 19:50:06 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stanbol.commons.security;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * Utility methods for converting passwords.
+ *
+ */
+public class PasswordUtil {
+
+ private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();
+
+ /**
+ * @param bytes
+ * array of bytes to be converted to a String of hexadecimal
+ * numbers
+ * @return String of hexadecimal numbers representing the byte array
+ */
+ public static String bytes2HexString(byte[] bytes) {
+ char[] result = new char[bytes.length << 1];
+ for (int i = 0, j = 0; i < bytes.length; i++) {
+ result[j++] = HEXDIGITS[bytes[i] >> 4 & 0xF];
+ result[j++] = HEXDIGITS[bytes[i] & 0xF];
+ }
+ return new String(result);
+ }
+
+ /**
+ * Encrypt the password with the SHA1 algorithm
+ *
+ * @param password
+ * @return the converted passwort as String
+ */
+ public static String convertPassword(String password) {
+ try {
+ return bytes2HexString(MessageDigest.getInstance("SHA1").digest(
+ password.getBytes("UTF-8")));
+ } catch (NoSuchAlgorithmException nsae) {
+ throw new RuntimeException();
+ } catch (UnsupportedEncodingException uee) {
+ throw new RuntimeException();
+ }
+ }
+}
Added: incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PermissionDefinitions.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PermissionDefinitions.java?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PermissionDefinitions.java (added)
+++ incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/PermissionDefinitions.java Thu Aug 23 19:50:06 2012
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stanbol.commons.security;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.osgi.service.permissionadmin.PermissionInfo;
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.ontologies.OSGI;
+import org.apache.clerezza.rdf.ontologies.PERMISSION;
+import org.apache.clerezza.rdf.ontologies.SIOC;
+
+/**
+ * Provides utility methods to extract infomation for the permission assignment.
+ *
+ * @author clemens
+ */
+class PermissionDefinitions {
+
+ private MGraph systemGraph;
+
+ PermissionDefinitions(MGraph systeGraph) {
+ this.systemGraph = systeGraph;
+ }
+
+ /**
+ * Returns the permissions of a specified location.
+ * I.e. the permissions of all permission assignments matching <code>location</code>.
+ *
+ * @param location the location of a bundle
+ * @return an array with <code>PermissionInfo</code> elements
+ */
+ PermissionInfo[] retrievePermissions(String location) {
+ List<PermissionInfo> permInfoList = new ArrayList<PermissionInfo>();
+
+ Iterator<Triple> ownerTriples =
+ systemGraph.filter(new UriRef(location), OSGI.owner, null);
+
+ if (ownerTriples.hasNext()) {
+ NonLiteral user = (NonLiteral) ownerTriples.next().getObject();
+ lookForPermissions(user, permInfoList);
+ }
+
+ if (permInfoList.isEmpty()) {
+ return null;
+ }
+ return permInfoList.toArray(new PermissionInfo[permInfoList.size()]);
+ }
+
+ /**
+ * Look for all permissions of a role and add them to a list.
+ * And if the role has another role, then execute this function recursively,
+ * until all permissions are found.
+ *
+ * @param role a <code>NonLiteral</code> which is either a user or a role
+ * @param permInfoList a list with all the added permissions of this bundle
+ */
+ private void lookForPermissions(NonLiteral role, List<PermissionInfo> permInfoList) {
+ Iterator<Triple> permissionTriples =
+ systemGraph.filter(role, PERMISSION.hasPermission, null);
+
+ while (permissionTriples.hasNext()) {
+
+ NonLiteral permission = (NonLiteral) permissionTriples.next().getObject();
+
+ Iterator<Triple> javaPermissionTriples =
+ systemGraph.filter(permission, PERMISSION.javaPermissionEntry, null);
+
+ while (javaPermissionTriples.hasNext()) {
+
+ Triple t = javaPermissionTriples.next();
+ Literal permEntry = (Literal) t.getObject();
+
+ permInfoList.add(new PermissionInfo(permEntry.getLexicalForm()));
+ }
+ }
+
+ Iterator<Triple> roleTriples =
+ systemGraph.filter(role, SIOC.has_function, null);
+
+ while (roleTriples.hasNext()) {
+ NonLiteral anotherRole = (NonLiteral) roleTriples.next().getObject();
+ this.lookForPermissions(anotherRole, permInfoList);
+ }
+ }
+}
Added: incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/SecurityActivator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/SecurityActivator.java?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/SecurityActivator.java (added)
+++ incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/SecurityActivator.java Thu Aug 23 19:50:06 2012
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2010 reto.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+package org.apache.stanbol.commons.security;
+
+import java.security.PermissionCollection;
+import java.security.Permissions;
+import java.security.Policy;
+import java.security.Principal;
+import java.security.ProtectionDomain;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * A component with no required dependency ensuring that the UserAwarePolicy is
+ * activated if available or otherwise a restrictive default policy is set
+ *
+ * @author reto
+ */
+@Component
+@Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY,
+name = "userAwarePolicy",
+policy = ReferencePolicy.DYNAMIC,
+referenceInterface = UserAwarePolicy.class)
+public class SecurityActivator {
+
+ private Policy originalPolicy;
+ private Policy fallBackPolicy = new Policy() {
+
+ @Override
+ public PermissionCollection getPermissions(final ProtectionDomain domain) {
+
+ PermissionCollection result;
+
+ Principal[] principals = domain.getPrincipals();
+ if (principals.length > 0) {
+ result = new Permissions();
+ } else {
+ result = originalPolicy.getPermissions(domain);
+ }
+ return result;
+ }
+ };
+
+ protected void activate(final ComponentContext context) throws Exception {
+ originalPolicy = Policy.getPolicy();
+ }
+
+ protected void deactivate(final ComponentContext context) throws Exception {
+ Policy.setPolicy(originalPolicy);
+ }
+
+ protected void bindUserAwarePolicy(UserAwarePolicy userAwarePolicy) {
+ Policy.setPolicy(userAwarePolicy);
+ }
+
+ protected void unbindUserAwarePolicy(UserAwarePolicy userAwarePolicy) {
+ Policy.setPolicy(fallBackPolicy);
+ }
+}
Added: incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserAwarePolicy.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserAwarePolicy.java?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserAwarePolicy.java (added)
+++ incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserAwarePolicy.java Thu Aug 23 19:50:06 2012
@@ -0,0 +1,273 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stanbol.commons.security;
+
+import java.security.AccessController;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Permissions;
+import java.security.Policy;
+import java.security.Principal;
+import java.security.PrivilegedAction;
+import java.security.ProtectionDomain;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.clerezza.platform.config.SystemConfig;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.ontologies.PERMISSION;
+import org.apache.clerezza.rdf.ontologies.PLATFORM;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.ontologies.SIOC;
+import org.apache.clerezza.utils.security.PermissionParser;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.Service;
+
+/**
+ *
+ * @author mir
+ */
+@Component
+@Service(UserAwarePolicy.class)
+@Reference(name = "webIdPermissionProvider",
+cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
+policy = ReferencePolicy.DYNAMIC,
+referenceInterface = WebIdBasedPermissionProvider.class)
+public class UserAwarePolicy extends Policy {
+
+ final Logger logger = LoggerFactory.getLogger(UserAwarePolicy.class);
+
+ @Reference(target=SystemConfig.SYSTEM_GRAPH_FILTER)
+ private MGraph systemGraph;
+
+ /**
+ * Stores the mapping between a String describing the permission and the
+ * described <code>Permission</code> object.
+ */
+ private Map<String, Permission> permissionMap = new HashMap<String, Permission>();
+
+ /**
+ * Cache for user permissions
+ */
+ private UserPermissionsCache cache = new UserPermissionsCache();
+
+ private Policy originalPolicy;
+ private final Set<WebIdBasedPermissionProvider> permissionProviders =
+ Collections.synchronizedSet(new HashSet<WebIdBasedPermissionProvider>());
+
+ public UserAwarePolicy() {
+ this.originalPolicy = Policy.getPolicy();
+ }
+
+ @Override
+ public PermissionCollection getPermissions(final ProtectionDomain domain) {
+
+ PermissionCollection result;
+
+ Principal[] principals = domain.getPrincipals();
+ if (principals.length > 0) {
+ final Principal user = domain.getPrincipals()[0];
+
+ result = cache.getCachedUserPermissions(user);
+ if (result != null) {
+ return result;
+ } else {
+ result = getUserPermissionsFromSystemGraph(user);
+ cache.cacheUserPermissions(user, result);
+ }
+ } else {
+ result = originalPolicy.getPermissions(domain);
+ }
+ return result;
+ }
+
+ @Override
+ public void refresh() {
+ cache.clear();
+ }
+
+ /**
+ * Returns the permissions of the specified user according to the entries in
+ * the sytemGraph.
+ *
+ * @param user
+ * @return
+ * @throws java.lang.IllegalArgumentException
+ * @throws java.lang.SecurityException
+ */
+ private PermissionCollection getUserPermissionsFromSystemGraph(
+ final Principal user) throws IllegalArgumentException,
+ SecurityException, UserUnregisteredException {
+ final PermissionCollection result = new Permissions();
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+
+ @Override
+ public Object run() {
+ logger.debug("Get permissions for user " + user.getName());
+
+ List<String> permissions = getAllPermissionsOfAUserByName(user
+ .getName());
+ for (String permissionStr : permissions) {
+ logger.debug("Add permission {}", permissionStr);
+ Permission perm = permissionMap.get(permissionStr);
+ // make new permission, if the required
+ // <code>Permission</code> object is not in the map.
+ if (perm == null) {
+ try {
+ perm = PermissionParser.getPermission(permissionStr,
+ getClass().getClassLoader());
+ } catch (IllegalArgumentException e) {
+ logger.error("parsing "+permissionStr,e);
+ continue;
+ } catch (RuntimeException e) {
+ logger.error("instantiating "+permissionStr,e);
+ continue;
+ }
+ }
+ result.add(perm);
+ }
+ return null;
+ }
+ });
+ return result;
+ }
+
+ /**
+ * Returns the string representations of all permissions of a user. Those
+ * are his/her own permissions and the permissions of his roles
+ *
+ */
+ private List<String> getAllPermissionsOfAUserByName(String userName)
+ throws UserUnregisteredException {
+
+ NonLiteral user = getUserByName(userName);
+
+ List<String> result = getPermissionEntriesOfAUser(user, userName);
+ Iterator<Triple> roleTriples = systemGraph.filter(user,
+ SIOC.has_function, null);
+
+ while (roleTriples.hasNext()) {
+ NonLiteral anotherRole = (NonLiteral) roleTriples.next()
+ .getObject();
+ result.addAll(getPermissionEntriesOfARole(anotherRole, userName, user));
+ }
+ Iterator<NonLiteral> baseRoles = getResourcesOfType(PERMISSION.BaseRole);
+ while(baseRoles.hasNext()) {
+ result.addAll(getPermissionEntriesOfARole(baseRoles.next(), userName, user));
+ }
+ return result;
+ }
+
+ private NonLiteral getUserByName(String userName)
+ throws UserUnregisteredException {
+ Iterator<Triple> triples = systemGraph.filter(null, PLATFORM.userName,
+ new PlainLiteralImpl(userName));
+
+ if (triples.hasNext()) {
+ return triples.next().getSubject();
+ }
+ throw new UserUnregisteredException(userName);
+ }
+
+ private List<String> getPermissionEntriesOfAUser(NonLiteral user, String userName) {
+ List<String> result = getPermissionEntriesOfARole(user, userName, user);
+ if (user instanceof UriRef) {
+ synchronized(permissionProviders) {
+ for (WebIdBasedPermissionProvider p : permissionProviders) {
+ result.addAll(p.getPermissions((UriRef)user));
+ }
+ }
+ }
+ return result;
+ }
+ //note that users are roles too
+ private List<String> getPermissionEntriesOfARole(NonLiteral role, String userName, NonLiteral user) {
+ List<String> result = new ArrayList<String>();
+ Iterator<Triple> permsForRole = systemGraph.filter(role,
+ PERMISSION.hasPermission, null);
+
+ while (permsForRole.hasNext()) {
+ Iterator<Triple> javaPermForRole = systemGraph.filter(
+ (BNode) permsForRole.next().getObject(),
+ PERMISSION.javaPermissionEntry, null);
+ if (javaPermForRole.hasNext()) {
+ PlainLiteralImpl permissionEntry = (PlainLiteralImpl) javaPermForRole
+ .next().getObject();
+ String permission = permissionEntry.getLexicalForm();
+ if(permission.contains("{username}")) {
+ permission = permission.replace("{username}",userName);
+ }
+ result.add(permission);
+ }
+ }
+ return result;
+ }
+
+ private Iterator<NonLiteral> getResourcesOfType(UriRef type) {
+ final Iterator<Triple> triples =
+ systemGraph.filter(null, RDF.type, type);
+ return new Iterator<NonLiteral>() {
+
+ @Override
+ public boolean hasNext() {
+ return triples.hasNext();
+ }
+
+ @Override
+ public NonLiteral next() {
+ return triples.next().getSubject();
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ };
+ }
+
+ protected void bindWebIdPermissionProvider(WebIdBasedPermissionProvider p) {
+ permissionProviders.add(p);
+ refresh();
+ }
+
+ protected void unbindWebIdPermissionProvider(WebIdBasedPermissionProvider p) {
+ permissionProviders.remove(p);
+ refresh();
+ }
+
+}
Added: incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserPermissionsCache.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserPermissionsCache.java?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserPermissionsCache.java (added)
+++ incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserPermissionsCache.java Thu Aug 23 19:50:06 2012
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stanbol.commons.security;
+
+import java.security.PermissionCollection;
+import java.security.Principal;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Caches <code>PermissonCollection</code>S of users
+ *
+ * @author mir
+ */
+public class UserPermissionsCache {
+ /**
+ * Stores the mapping between a <code>Principal</code> representing the user
+ * and his/her <code>PermissionCollection</code>.
+ */
+ private Map<Principal, PermissionCollection> userPermissionsMap
+ = new HashMap<Principal, PermissionCollection>();
+
+ /**
+ * Return the cached <code>PermissionCollection</code> containing the users
+ * <code>Permission</code>S.
+ *
+ * @param user
+ * @return
+ */
+ public PermissionCollection getCachedUserPermissions(Principal user) {
+ return userPermissionsMap.get(user);
+ }
+
+ /**
+ * Caches the <code>PermissionCollection</code> for the specified user
+ *
+ * @param user
+ * @param permissions
+ */
+ public void cacheUserPermissions(Principal user,
+ PermissionCollection permissions) {
+ userPermissionsMap.put(user, permissions);
+ }
+
+ /**
+ * Clears the cache.
+ */
+ public void clear() {
+ userPermissionsMap.clear();
+ }
+}
Added: incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUnregisteredException.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUnregisteredException.java?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUnregisteredException.java (added)
+++ incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUnregisteredException.java Thu Aug 23 19:50:06 2012
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stanbol.commons.security;
+
+/**
+ * Thrown if a user with the specified name is supposed to be but not registered
+ * in the system graph
+ *
+ * @author hasan
+ */
+public class UserUnregisteredException extends RuntimeException {
+
+ public UserUnregisteredException(String name) {
+ super("User " + name + " does not exist in the system graph");
+ }
+}
Added: incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUtil.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUtil.java?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUtil.java (added)
+++ incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/UserUtil.java Thu Aug 23 19:50:06 2012
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stanbol.commons.security;
+
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.Principal;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Set;
+import javax.security.auth.Subject;
+
+import org.apache.stanbol.commons.security.auth.PrincipalImpl;
+
+/**
+ * Utility methods for retrieving user information.
+ *
+ *
+ * @author mir, tio
+ */
+public class UserUtil {
+
+ /**
+ *
+ * @return the name of user which is associated to the
+ * <code>AccessControlContext</code> of the current thread.
+ */
+ public static String getCurrentUserName() {
+ return getUserName(AccessController.getContext());
+ }
+
+ /**
+ *
+ * @return the subject which is associated to the
+ * <code>AccessControlContext</code> of the current thread.
+ */
+ public static Subject getCurrentSubject() {
+ return getSubject(AccessController.getContext());
+ }
+
+
+ /**
+ * Returns the name of the user associtated with the specified
+ * <code>AccessControlContext</code>.
+ *
+ * @param context
+ * @return the username of the current user or null if no
+ * user name is associated with the provided <code>AccessControlContext</code>.
+ */
+ public static String getUserName(final AccessControlContext context) {
+ Subject subject = getSubject(context);
+ if (subject == null) return null;
+ Set<Principal> principals = subject.getPrincipals();
+ if (principals==null) return null;
+ Iterator<Principal> iter = principals.iterator();
+ String name = null;
+ if (iter.hasNext()) {
+ name = iter.next().getName();
+ }
+ return name;
+ }
+
+ /**
+ * Returns the name of the user associtated with the specified
+ * <code>AccessControlContext</code>.
+ *
+ * @param context
+ * @return the username of the current user or null if no
+ * user name is associated with the provided <code>AccessControlContext</code>.
+ */
+ public static Subject getSubject(final AccessControlContext context) {
+ Subject subject;
+ try {
+ subject = AccessController.doPrivileged(new PrivilegedExceptionAction<Subject>() {
+
+ @Override
+ public Subject run() throws Exception {
+ return Subject.getSubject(context);
+ }
+ });
+ } catch (PrivilegedActionException ex) {
+ Exception cause = (Exception)ex.getCause();
+ if (cause instanceof RuntimeException) {
+ throw (RuntimeException) cause;
+ }
+ throw new RuntimeException(cause);
+ }
+ return subject;
+ }
+
+ public static final Principal ANONYMOUS = new PrincipalImpl("anonymous");
+
+ public static Subject createSubject(String userName) {
+ return new Subject(true,
+ Collections.singleton(new PrincipalImpl(userName)), Collections.EMPTY_SET,
+ Collections.EMPTY_SET);
+ }
+}
Added: incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/WebIdBasedPermissionProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/WebIdBasedPermissionProvider.java?rev=1376665&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/WebIdBasedPermissionProvider.java (added)
+++ incubator/stanbol/trunk/commons/security/src/main/java/org/apache/stanbol/commons/security/WebIdBasedPermissionProvider.java Thu Aug 23 19:50:06 2012
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2010 reto.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package org.apache.stanbol.commons.security;
+
+import java.util.Collection;
+import org.apache.clerezza.rdf.core.UriRef;
+
+/**
+ * Services implementing this interface provide additional permissions
+ * to users with a Web-Id.
+ *
+ * Typically this is used to assign permissions to roaming users.
+ *
+ * @author reto
+ */
+public interface WebIdBasedPermissionProvider {
+ /**
+ * This methods returns string descriptions of the permissions to be granted
+ * to the user with a specified Web-Id. The permissions are described
+ * using the conventional format '("ClassName" "name" "actions")'.
+ *
+ * @param webId the uri identifying the user (aka Web-Id)
+ * @return the string descriptions of the permissions
+ */
+ Collection<String> getPermissions(UriRef webId);
+}