[maven-release-plugin] copy for tag org.apache.stanbol.commons.security-0.99
git-svn-id: https://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99@1599059 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/security-0.99/LICENSE b/security-0.99/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/security-0.99/LICENSE
@@ -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.
diff --git a/security-0.99/authentication.basic/LICENSE b/security-0.99/authentication.basic/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/security-0.99/authentication.basic/LICENSE
@@ -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.
diff --git a/security-0.99/authentication.basic/pom.xml b/security-0.99/authentication.basic/pom.xml
new file mode 100644
index 0000000..9eff2c6
--- /dev/null
+++ b/security-0.99/authentication.basic/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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>4</version>
+ <relativePath />
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.authentication.basic</artifactId>
+ <version>0.99</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Stanbol Commons Basic Authenticator</name>
+ <description>An Authenticator for HTTP Basic auth.</description>
+
+ <inceptionYear>2012</inceptionYear>
+ <licenses>
+ <license>
+ <name>Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ <comments>A business-friendly OSS license</comments>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99/authentication.basic
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99/authentication.basic
+ </developerConnection>
+ <url>scm:svn:https://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99/stanbol.apache.org</url>
+ </scm>
+
+ <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>
+ <Import-Package><!-- increase default version range to support current SNAPSHOT -->
+ org.apache.stanbol.commons.security.auth; provide:=true; version="[0.11,1.1)",
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.security.core</artifactId>
+ <version>0.99</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/security-0.99/authentication.basic/src/license/THIRD-PARTY.properties b/security-0.99/authentication.basic/src/license/THIRD-PARTY.properties
new file mode 100644
index 0000000..92548f4
--- /dev/null
+++ b/security-0.99/authentication.basic/src/license/THIRD-PARTY.properties
@@ -0,0 +1,25 @@
+# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
+#-------------------------------------------------------------------------------
+# Already used licenses in project :
+# - Apache Software License
+# - Apache Software License, Version 2.0
+# - BSD License
+# - Common Development And Distribution License (CDDL), Version 1.0
+# - Common Development And Distribution License (CDDL), Version 1.1
+# - Common Public License, Version 1.0
+# - Eclipse Public License, Version 1.0
+# - GNU General Public License (GPL), Version 2 with classpath exception
+# - GNU Lesser General Public License (LGPL)
+# - GNU Lesser General Public License (LGPL), Version 2.1
+# - ICU License
+# - MIT License
+# - New BSD License
+# - Public Domain License
+#-------------------------------------------------------------------------------
+# Please fill the missing licenses for dependencies :
+#
+#
+#Thu Dec 13 14:39:22 CET 2012
+javax.servlet--servlet-api--2.5=Common Development And Distribution License (CDDL), Version 1.0
+org.osgi--org.osgi.compendium--4.1.0=The Apache Software License, Version 2.0
+org.osgi--org.osgi.core--4.1.0=The Apache Software License, Version 2.0
diff --git a/security-0.99/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/basic/BasicAuthentication.java b/security-0.99/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/basic/BasicAuthentication.java
new file mode 100644
index 0000000..ac48244
--- /dev/null
+++ b/security-0.99/authentication.basic/src/main/java/org/apache/stanbol/commons/authentication/basic/BasicAuthentication.java
@@ -0,0 +1,136 @@
+/*
+ * 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.security.AccessControlException;
+
+import javax.security.auth.Subject;
+import javax.servlet.ServletException;
+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(":");
+ if (credentials.length == 0) {
+ return false;
+ }
+ 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=\"Apache Stanbol 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;
+ }
+
+
+
+}
diff --git a/security-0.99/core/LICENSE b/security-0.99/core/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/security-0.99/core/LICENSE
@@ -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.
diff --git a/security-0.99/core/pom.xml b/security-0.99/core/pom.xml
new file mode 100644
index 0000000..beff0d1
--- /dev/null
+++ b/security-0.99/core/pom.xml
@@ -0,0 +1,159 @@
+<!--
+
+ 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>4</version>
+ <relativePath />
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.security.core</artifactId>
+ <version>0.99</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Stanbol Commons Security Core</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>
+
+ <inceptionYear>2012</inceptionYear>
+ <licenses>
+ <license>
+ <name>Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ <comments>A business-friendly OSS license</comments>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>
+ scm:svn:https://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99/core
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99/core
+ </developerConnection>
+ <url>scm:svn:https://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99/stanbol.apache.org</url>
+ </scm>
+
+ <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>
+ <Import-Package>
+ javax.servlet.*; version="[2.5.0,4.0.0)",
+ org.apache.stanbol.commons.security,
+ org.apache.stanbol.commons.security.auth,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.stanbol.commons.security;version=${project.version},
+ org.apache.stanbol.commons.security.auth;version=${project.version}
+ </Export-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludeSubProjects>false</excludeSubProjects>
+ <excludes>
+ <exclude>src/license/THIRD-PARTY.properties</exclude>
+
+ <!-- Apache License 2.0 -->
+ <exclude>src/test/resources/org/apache/stanbol/commons/security/systemgraph.nt</exclude>
+ <exclude>src/main/resources/META-INF/documentation.nt</exclude>
+ </excludes>
+ </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>
diff --git a/security-0.99/core/src/license/THIRD-PARTY.properties b/security-0.99/core/src/license/THIRD-PARTY.properties
new file mode 100644
index 0000000..08c612c
--- /dev/null
+++ b/security-0.99/core/src/license/THIRD-PARTY.properties
@@ -0,0 +1,27 @@
+# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
+#-------------------------------------------------------------------------------
+# Already used licenses in project :
+# - ASF 2.0
+# - Apache Software License
+# - Apache Software License, Version 2.0
+# - BSD License
+# - Common Development And Distribution License (CDDL), Version 1.0
+# - Common Development And Distribution License (CDDL), Version 1.1
+# - Common Public License, Version 1.0
+# - Eclipse Public License, Version 1.0
+# - GNU General Public License (GPL), Version 2 with classpath exception
+# - GNU Lesser General Public License (LGPL)
+# - GNU Lesser General Public License (LGPL), Version 2.1
+# - ICU License
+# - MIT License
+# - New BSD License
+# - Public Domain License
+#-------------------------------------------------------------------------------
+# Please fill the missing licenses for dependencies :
+#
+#
+#Thu Dec 13 14:30:45 CET 2012
+javax.servlet--servlet-api--2.5=Common Development And Distribution License (CDDL), Version 1.0
+org.osgi--org.osgi.compendium--4.1.0=The Apache Software License, Version 2.0
+org.osgi--org.osgi.core--4.1.0=The Apache Software License, Version 2.0
+xerces--xercesImpl--2.7.1=The Apache Software License, Version 2.0
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/PasswordUtil.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/PasswordUtil.java
new file mode 100644
index 0000000..3f8f017
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/PasswordUtil.java
@@ -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.
+ */
+package org.apache.stanbol.commons.security;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * Utility methods for converting passwords.
+ *
+ */
+public final class PasswordUtil {
+
+ /**
+ * Restrict instantiation
+ */
+ private 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();
+ }
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/PermissionDefinitions.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/PermissionDefinitions.java
new file mode 100644
index 0000000..c130ec0
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/PermissionDefinitions.java
@@ -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);
+ }
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/SecurityActivator.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/SecurityActivator.java
new file mode 100644
index 0000000..12d603d
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/SecurityActivator.java
@@ -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);
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserAwarePolicy.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserAwarePolicy.java
new file mode 100644
index 0000000..9a5fd74
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserAwarePolicy.java
@@ -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();
+ }
+
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserPermissionsCache.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserPermissionsCache.java
new file mode 100644
index 0000000..04bcef3
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserPermissionsCache.java
@@ -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();
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserUnregisteredException.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserUnregisteredException.java
new file mode 100644
index 0000000..a12718f
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserUnregisteredException.java
@@ -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");
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserUtil.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserUtil.java
new file mode 100644
index 0000000..394620e
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/UserUtil.java
@@ -0,0 +1,121 @@
+/*
+ * 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 final class UserUtil {
+
+ /**
+ * Restrict instantiation
+ */
+ private 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);
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/WebIdBasedPermissionProvider.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/WebIdBasedPermissionProvider.java
new file mode 100644
index 0000000..9f77ab2
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/WebIdBasedPermissionProvider.java
@@ -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);
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticatingFilter.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticatingFilter.java
new file mode 100644
index 0000000..7f27728
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticatingFilter.java
@@ -0,0 +1,250 @@
+/*
+ * 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.auth;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.security.Principal;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.security.auth.Subject;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+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;
+import org.apache.stanbol.commons.security.UserUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(immediate = true)
+@Service(Filter.class)
+@Properties(value = {
+ @Property(name = "pattern", value = ".*"),
+ @Property(name = "service.ranking", intValue = Integer.MAX_VALUE)
+})
+@Reference(name = "weightedAuthenticationMethod",
+ cardinality = ReferenceCardinality.MANDATORY_MULTIPLE,
+ policy = ReferencePolicy.DYNAMIC,
+ referenceInterface = WeightedAuthenticationMethod.class)
+public class AuthenticatingFilter implements Filter {
+
+ private final Logger logger = LoggerFactory.getLogger(AuthenticatingFilter.class);
+ private SortedSet<WeightedAuthenticationMethod> methodList =
+ new TreeSet<WeightedAuthenticationMethod>(new WeightedAuthMethodComparator());
+
+ private Subject getSubject() {
+ Subject subject = UserUtil.getCurrentSubject();
+ if (subject == null) {
+ subject = new Subject();
+ }
+ return subject;
+ }
+
+ /**
+ * Registers a
+ * <code>WeightedAuthenticationMethod</code>
+ *
+ * @param method the method to be registered
+ */
+ protected void bindWeightedAuthenticationMethod(WeightedAuthenticationMethod method) {
+ methodList.add(method);
+ }
+
+ /**
+ * Unregister a
+ * <code>WeightedAuthenticationMethod</code>
+ *
+ * @param method the method to be unregistered
+ */
+ protected void unbindWeightedAuthenticationMethod(WeightedAuthenticationMethod method) {
+ methodList.remove(method);
+ }
+
+ /**
+ * Compares the WeightedAuthenticationMethods, descending for weight and
+ * ascending by name
+ */
+ static class WeightedAuthMethodComparator
+ implements Comparator<WeightedAuthenticationMethod> {
+
+ @Override
+ public int compare(WeightedAuthenticationMethod o1,
+ WeightedAuthenticationMethod o2) {
+ int o1Weight = o1.getWeight();
+ int o2Weight = o2.getWeight();
+ if (o1Weight != o2Weight) {
+ return o2Weight - o1Weight;
+ }
+ return o1.getClass().toString().compareTo(o2.getClass().toString());
+ }
+ }
+
+ private void writeLoginResponse(final HttpServletRequest request, final HttpServletResponse response, Throwable e) throws ServletException, IOException {
+ logger.debug("SecurityException: {}", e);
+ try {
+ for (AuthenticationMethod authMethod : methodList) {
+ if (authMethod.writeLoginResponse(request, response, e)) {
+ break;
+ }
+ }
+ } catch (IOException ex) {
+ //only needed because jetty is doing a bad job at logging
+ logger.error("Exception writing loging respone", e);
+ throw ex;
+ }
+ }
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
+ final FilterChain chain) throws IOException, ServletException {
+
+ logger.debug("filtering request");
+ final HttpServletRequest request = (HttpServletRequest) servletRequest;
+ final HttpServletResponse response = (HttpServletResponse) servletResponse;
+ final Subject subject = getSubject();
+ {
+ AuthenticationMethod authenticationMethod = null;
+ try {
+ for (Iterator<WeightedAuthenticationMethod> it = methodList.iterator(); it.hasNext();) {
+ authenticationMethod = it.next();
+ if (authenticationMethod.authenticate(request, subject)) {
+ break;
+ }
+ }
+ } catch (LoginException ex) {
+ if (!authenticationMethod.writeLoginResponse(request, response, ex)) {
+ writeLoginResponse(request, response, ex);
+ }
+ return;
+ }
+ }
+
+ Set<Principal> principals = subject.getPrincipals();
+ if (principals.size() == 0) {
+ principals.add(UserUtil.ANONYMOUS);
+ }
+ //the response wrapping is because of JERSEY-1926
+ final ServletOutputStream[] out = new ServletOutputStream[1];
+ final boolean[] closed = new boolean[1];
+ final String[] sentErrorMsg = new String[1];
+ final int[] sentErrorCode = new int[1];
+ sentErrorCode[0] = -1;
+ try {
+ Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Object>() {
+ @Override
+ public Object run() throws Exception {
+ HttpServletResponse wrapped = new HttpServletResponseWrapper(response) {
+ @Override
+ public ServletOutputStream getOutputStream() throws IOException {
+ final ServletOutputStream orig = response.getOutputStream();
+ out[0] = orig;
+ return new ServletOutputStream() {
+
+ @Override
+ public void write(int i) throws IOException {
+ orig.write(i);
+ }
+
+ @Override
+ public void close() throws IOException {
+ closed[0] = true;
+ }
+
+ };
+ }
+
+
+ @Override
+ public void sendError(int sc, String msg) throws IOException {
+ sentErrorCode[0] = sc;
+ sentErrorMsg[0] = msg;
+ }
+
+ };
+ chain.doFilter(request, wrapped);
+ return null;
+ }
+ }, null);
+
+ } catch (PrivilegedActionException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof ServletException) {
+ if (cause.getCause() instanceof SecurityException) {
+ //working around JERSEY-1926
+ writeLoginResponse(request, response,
+ cause.getCause());
+ } else {
+ throw (ServletException) cause;
+ }
+ }
+ if (cause instanceof RuntimeException) {
+ throw (RuntimeException) cause;
+ }
+ throw new RuntimeException(e);
+ } catch (SecurityException e) {
+ writeLoginResponse(request, response, e);
+ }
+ if (!response.isCommitted()) {
+ if (closed[0]) {
+ try {
+ out[0].close();
+ } catch (IOException e) {
+ //do nothing
+ }
+ }
+ if (sentErrorCode[0] > -1) {
+ response.sendError(sentErrorCode[0], sentErrorMsg[0]);
+ }
+ }
+
+ }
+
+ @Override
+ public void destroy() {
+ // TODO Auto-generated method stub
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationChecker.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationChecker.java
new file mode 100644
index 0000000..206cc21
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationChecker.java
@@ -0,0 +1,45 @@
+/*
+ * 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.auth;
+
+/**
+ * A service that checks if a provided username and password matches a
+ * username and password in a credentials store.
+ *
+ * @author mir
+ */
+public interface AuthenticationChecker {
+
+ /**
+ * Checks if the provided username and password matches a username and
+ * password in a credentials store.
+ * @param userName
+ * The name of the user to authenticate. The name uniquely identifies
+ * the user.
+ * @param password
+ * The password used to authenticate the user identified by the user
+ * name.
+ * @return true is the user has been authenticated, false if the user can
+ * not be authenticated
+ * @throws NoSuchAgent if no user could be found for the provided user name
+ */
+ boolean authenticate(String userName, String password) throws NoSuchAgent;
+
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationCheckerImpl.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationCheckerImpl.java
new file mode 100644
index 0000000..3845e27
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationCheckerImpl.java
@@ -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.
+ */
+package org.apache.stanbol.commons.security.auth;
+
+import java.security.AccessController;
+import java.util.Iterator;
+import java.util.concurrent.locks.Lock;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.security.PasswordUtil;
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.ontologies.PERMISSION;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.clerezza.platform.config.SystemConfig;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.ontologies.PLATFORM;
+
+/**
+ * A service that checks if a provided username and password matches a
+ * username and password stored in the system graph
+ *
+ * @author mir
+ */
+@Component
+@Service(value=AuthenticationChecker.class)
+public class AuthenticationCheckerImpl implements AuthenticationChecker {
+
+ private final static Logger logger = LoggerFactory.getLogger(AuthenticationCheckerImpl.class);
+
+ @Reference(target=SystemConfig.SYSTEM_GRAPH_FILTER)
+ private LockableMGraph systemGraph;
+
+ /**
+ * Checks if the provided username and password matches a username and
+ * password stored in the system graph
+ *
+ * @param userName
+ * @param password
+ * @return true if the password matched, false otherwise
+ * @throws org.apache.stanbol.commons.security.auth.NoSuchAgent
+ */
+ @Override
+ public boolean authenticate(String userName, String password) throws NoSuchAgent
+ {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ AccessController.checkPermission(new CheckAuthenticationPermission());
+ }
+ NonLiteral agent = getAgentFromGraph(userName);
+ String storedPassword = getPasswordOfAgent(agent);
+ if (storedPassword.equals(PasswordUtil.convertPassword(password))) {
+ logger.debug("user {} successfully authenticated", userName);
+ return true;
+ } else {
+ logger.debug("unsuccessful authentication attempt as user {}", userName);
+ return false;
+ }
+ }
+
+ private NonLiteral getAgentFromGraph(String userName) throws NoSuchAgent {
+ NonLiteral agent;
+ Lock l = systemGraph.getLock().readLock();
+ l.lock();
+ try {
+ Iterator<Triple> agents = systemGraph.filter(null, PLATFORM.userName, new PlainLiteralImpl(userName));
+ if (agents.hasNext()) {
+ agent = agents.next().getSubject();
+ } else {
+ logger.debug("unsuccessful authentication attempt as non-existent user {}", userName);
+ throw new NoSuchAgent();
+ }
+ } finally {
+ l.unlock();
+ }
+ return agent;
+ }
+
+ private String getPasswordOfAgent(NonLiteral agent) {
+ String storedPassword = "";
+ Lock l = systemGraph.getLock().readLock();
+ l.lock();
+ try {
+ Iterator<Triple> agentPassword = systemGraph.filter(agent, PERMISSION.passwordSha1, null);
+ if (agentPassword.hasNext()) {
+ storedPassword = ((Literal) agentPassword.next().getObject()).getLexicalForm();
+ }
+ } finally {
+ l.unlock();
+ }
+ return storedPassword;
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationMethod.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationMethod.java
new file mode 100644
index 0000000..8f86ae6
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationMethod.java
@@ -0,0 +1,60 @@
+/*
+ * 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.auth;
+
+import java.io.IOException;
+
+import javax.security.auth.Subject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Classes implementing this interface provide a method to authenticate a
+ * a user with the information provided in a http request.
+ */
+public interface AuthenticationMethod {
+
+ /**
+ * Returns the Subject of the authenticate user containing the principal
+ * of the authentication and possibly some credentials. If the authentication failed, an
+ * <code>LoginException</code> will be thrown. If no authentication
+ * information are available null is returned.
+ * @param request containing the information to authenticate a subject
+ * @param subject to add authentication information to
+ * @return true if this method did authenticate, false otherwise
+ * @throws LoginException This exception is thrown in case
+ * the login procedure failed.
+ * @throws HandlerException
+ */
+ public boolean authenticate(HttpServletRequest request, Subject subject)
+ throws LoginException, ServletException;
+
+ /**
+ * Modifies the specified <code>Response</code> according the specified
+ * <code>Request</code> and <code>Throwable</code>
+ * (e.g. <code>LoginException</code> or <code>AccessControllException</code>.
+ * The response leads to or provides further instructions for a client to
+ * log in.
+ * @return true, iff the response was modified
+ */
+ public boolean writeLoginResponse(HttpServletRequest request,HttpServletResponse response,
+ Throwable cause) throws ServletException, IOException;
+
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationService.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationService.java
new file mode 100644
index 0000000..a19f84c
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/AuthenticationService.java
@@ -0,0 +1,109 @@
+/*
+ * 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.auth;
+
+import java.util.ArrayList;
+import java.util.List;
+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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides user authentication given the user credentials.
+ *
+ * This service considers all enabled {@link AuthenticationChecker} services to
+ * authenticate a user. If multiple AuthenticationCheckers are present,
+ * only one needs to positively authenticate the user for the authentication
+ * process to succeed.
+ *
+ * @author daniel
+ */
+@Component
+@Service(AuthenticationService.class)
+@Reference(name = "restrictionElement",
+cardinality = ReferenceCardinality.MANDATORY_MULTIPLE,
+policy = ReferencePolicy.DYNAMIC,
+referenceInterface = AuthenticationChecker.class)
+public class AuthenticationService {
+ private final static Logger logger =
+ LoggerFactory.getLogger(AuthenticationCheckerImpl.class);
+
+ private List<AuthenticationChecker> authenticationCheckers =
+ new ArrayList<AuthenticationChecker>();
+
+
+ /**
+ * Authenticates a user given its user name and password credentials.
+ *
+ * @param userName
+ * The name of the user to authenticate. The name uniquely identifies
+ * the user.
+ * @param password
+ * The password used to authenticate the user identified by the user
+ * name.
+ * @return true is the user has been authenticated, false if the user can
+ * not be authenticated
+ * @throws NoSuchAgent if no user could be found for the provided user name
+ */
+ public boolean authenticateUser(String userName, String password)
+ throws NoSuchAgent {
+
+ boolean userNameExists = false;
+ for(AuthenticationChecker checker : authenticationCheckers) {
+ try {
+ if(checker.authenticate(userName, password)) {
+ return true;
+ }
+ userNameExists = true;
+ } catch (NoSuchAgent ex) {
+ continue;
+ }
+ }
+
+ if(!userNameExists) {
+ logger.info("No service could unsuccessfully authenticate user {}. Reason: user does not exist", userName);
+ throw new NoSuchAgent();
+ }
+ return false;
+ }
+
+ /**
+ * Called when new {@link AuthenticationChecker} services are registered in
+ * the OSGi environment.
+ *
+ * @param service the AuthenticationChecker
+ */
+ protected void bindAuthenticationChecker(AuthenticationChecker service) {
+ authenticationCheckers.add(service);
+ }
+
+ /**
+ * Called when {@link AuthenticationChecker} services are unregistered
+ * in the OSGi environment.
+ *
+ * @param service the AuthenticationChecker
+ */
+ protected void unbindAuthenticationChecker(AuthenticationChecker service) {
+ authenticationCheckers.remove(service);
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/CheckAuthenticationPermission.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/CheckAuthenticationPermission.java
new file mode 100644
index 0000000..8b5ab3c
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/CheckAuthenticationPermission.java
@@ -0,0 +1,65 @@
+/*
+ * 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.auth;
+
+import java.security.Permission;
+
+/*@PermissionInfo(value="Authentication Checker Permission", description=" Grants permission " +
+ "to use the AuthenticationChecker service which checks if a provided username " +
+ "and password matches a username and password stored in the system graph")*/
+public class CheckAuthenticationPermission extends Permission {
+
+ public CheckAuthenticationPermission() {
+ super(null);
+ }
+
+ public CheckAuthenticationPermission(String name, String actions) {
+ super(null);
+ }
+
+ @Override
+ public boolean implies(Permission permission) {
+ if (permission instanceof CheckAuthenticationPermission) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj instanceof CheckAuthenticationPermission) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+
+ @Override
+ public String getActions() {
+ return "authenticate";
+ }
+
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/LoginException.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/LoginException.java
new file mode 100644
index 0000000..1a370ba
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/LoginException.java
@@ -0,0 +1,40 @@
+/*
+ * 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.auth;
+
+/**
+ * This exception is thrown when information needed for authentication is
+ * missing or invalid.
+ *
+ * @author mir
+ */
+public class LoginException extends Exception {
+
+ public static final String USER_NOT_EXISTING = "user not existing";
+ public static final String PASSWORD_NOT_MATCHING = "password did not match";
+ private String type;
+
+ public LoginException(String type) {
+ this.type = type;
+ }
+
+ public String getType() {
+ return type;
+ }
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/LoginListener.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/LoginListener.java
new file mode 100644
index 0000000..7d06a8f
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/LoginListener.java
@@ -0,0 +1,35 @@
+/*
+ * 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.auth;
+
+/**
+ * A Service interface whose implementations will be notified when a user has
+ * successfully logged in.
+ *
+ * @author tio
+ */
+public interface LoginListener {
+
+ /**
+ * Notifies when a user is logged in successfully.
+ *
+ * @param userName of the user who has successfully logged in
+ */
+ public void userLoggedIn(String userName);
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/NoSuchAgent.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/NoSuchAgent.java
new file mode 100644
index 0000000..e267052
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/NoSuchAgent.java
@@ -0,0 +1,23 @@
+/*
+ * 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.auth;
+
+public class NoSuchAgent extends Exception {
+
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/PrincipalImpl.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/PrincipalImpl.java
new file mode 100644
index 0000000..bc65213
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/PrincipalImpl.java
@@ -0,0 +1,52 @@
+/*
+ * 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.auth;
+
+import java.security.Principal;
+
+/**
+ *
+ * @author clemens
+ */
+public class PrincipalImpl implements Principal {
+ private String name;
+
+ public PrincipalImpl(String name){
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof PrincipalImpl)) {
+ return false;
+ }
+ return getName().equals(((PrincipalImpl)obj).getName());
+ }
+
+ @Override
+ public int hashCode() {
+ return getName().hashCode();
+ }
+
+}
diff --git a/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/WeightedAuthenticationMethod.java b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/WeightedAuthenticationMethod.java
new file mode 100644
index 0000000..5c630d5
--- /dev/null
+++ b/security-0.99/core/src/main/java/org/apache/stanbol/commons/security/auth/WeightedAuthenticationMethod.java
@@ -0,0 +1,34 @@
+/*
+ * 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.auth;
+
+/**
+ *
+ * @author mir
+ */
+public interface WeightedAuthenticationMethod extends AuthenticationMethod{
+
+ /**
+ * Get the weight of this method. {@link AuthenticatingFilter}
+ * will prioritize <code>AuthenticationMethod</code>s with greater weight.
+ *
+ * @return a positive number indicating the weight of the method
+ */
+ public int getWeight();
+}
diff --git a/security-0.99/core/src/main/resources/META-INF/documentation.nt b/security-0.99/core/src/main/resources/META-INF/documentation.nt
new file mode 100644
index 0000000..78ecf41
--- /dev/null
+++ b/security-0.99/core/src/main/resources/META-INF/documentation.nt
@@ -0,0 +1,69 @@
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db6 <http://discobits.org/ontology#holds> <bundle:///security-content-el/3-content> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db6 <http://discobits.org/ontology#pos> "1" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db6 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db5 <http://discobits.org/ontology#holds> <bundle:///security-content> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db5 <http://discobits.org/ontology#pos> "1" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db4 <http://discobits.org/ontology#pos> "3" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db4 <http://discobits.org/ontology#holds> <bundle:///security-content-el/1> .
+<bundle:///security-content-el/3-title> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///security-content-el/3-title> <http://discobits.org/ontology#infoBit> "Permission Management"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db3 <http://discobits.org/ontology#holds> <bundle:///security-content-el/1-content> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db3 <http://discobits.org/ontology#pos> "1" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db2 <http://discobits.org/ontology#pos> "0" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db2 <http://discobits.org/ontology#holds> <bundle:///security-content-el/2-title> .
+<bundle:///security-content> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#OrderedContent> .
+<bundle:///security-content> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7db1 .
+<bundle:///security-content> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7db0 .
+<bundle:///security-content> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7daf .
+<bundle:///security-content> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7db4 .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dae <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dae <http://discobits.org/ontology#pos> "1" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dae <http://discobits.org/ontology#holds> <bundle:///security-content-el/2-content> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dad <http://discobits.org/ontology#holds> <bundle:///security-content-el/3-title> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dad <http://discobits.org/ontology#pos> "0" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dad <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dac <http://discobits.org/ontology#holds> <bundle:///security-content-el/1-title> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dac <http://discobits.org/ontology#pos> "0" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dac <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+<bundle:///security-content-el/2-title> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///security-content-el/2-title> <http://discobits.org/ontology#infoBit> "User Authentication"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+<bundle:///security-content-el/3-content> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///security-content-el/3-content> <http://discobits.org/ontology#infoBit> "Permissions can be assigned to any user as well as to any role.\nA permission is defined by three attributes:\n<ul xmlns=\"http://www.w3.org/1999/xhtml\">\n<li>tpye: the qualified class name, e.g., java.io.FilePermission</li>\n<li>name: the name of the permission, e.g., the path in case of java.io.FilePermission</li>\n<li>actions: the actions that the permission allows, e.g., read, write</li>\n</ul>\n"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dab <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dab <http://discobits.org/ontology#holds> <bundle:///security-title> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7dab <http://discobits.org/ontology#pos> "0" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db0 <http://discobits.org/ontology#holds> <bundle:///security-content-el/2> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db0 <http://discobits.org/ontology#pos> "1" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+<bundle:///security-content-el/2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#TitledContent> .
+<bundle:///security-content-el/2> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7db2 .
+<bundle:///security-content-el/2> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7dae .
+<bundle:///security-content-el/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#TitledContent> .
+<bundle:///security-content-el/1> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7dac .
+<bundle:///security-content-el/1> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7db3 .
+<bundle:///security-content-el/3> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7db6 .
+<bundle:///security-content-el/3> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7dad .
+<bundle:///security-content-el/3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#TitledContent> .
+<bundle:///security-title> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///security-title> <http://discobits.org/ontology#infoBit> "Security"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+<bundle:///security-content-el/0> <http://discobits.org/ontology#infoBit> "The following functionalities are provided by the platform with respect to security\n<ul xmlns=\"http://www.w3.org/1999/xhtml\">\n<li>User Authentication</li>\n<li>Permission Management</li>\n<li>Permission Check Service</li>\n<li>User Authorization</li>\n</ul>\n"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+<bundle:///security-content-el/0> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///security-content-el/1-title> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///security-content-el/1-title> <http://discobits.org/ontology#infoBit> "Permission Check Service"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+<bundle:///security-content-el/1-content> <http://discobits.org/ontology#infoBit> "<p xmlns=\"http://www.w3.org/1999/xhtml\">The platform provides a web service to check whether the current user owns a certain permission. This service is invoked with a GET-request specifying the resource path /security/check and the query parameter permission. The parameter has the format: \n</p>\n<p xmlns=\"http://www.w3.org/1999/xhtml\">\n'(' <permission class name> <double-quoted name> <double-quoted actions> ')'.\n</p>\n<p xmlns=\"http://www.w3.org/1999/xhtml\">\nAn example of a valid URL would be: http://localhost:8282/security/check?permission=(java.io.FilePermission \"/tmp/*\" \"read\")\n</p>\n<p xmlns=\"http://www.w3.org/1999/xhtml\">As a result of this check the platform returns a response with the code 204, if the user has this permission.\n</p>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+<bundle:///security-content-el/1-content> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db1 <http://discobits.org/ontology#holds> <bundle:///security-content-el/0> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db1 <http://discobits.org/ontology#pos> "0" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7db1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7daf <http://discobits.org/ontology#pos> "2" .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7daf <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#Entry> .
+_:A6993a12aX3aX123939e7c92X3aXX2dX7daf <http://discobits.org/ontology#holds> <bundle:///security-content-el/3> .
+<bundle:///security> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7db5 .
+<bundle:///security> <http://discobits.org/ontology#contains> _:A6993a12aX3aX123939e7c92X3aXX2dX7dab .
+<bundle:///security> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#TitledContent> .
+<bundle:///security-content-el/2-content> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///security-content-el/2-content> <http://discobits.org/ontology#infoBit> "The platform supports two types of authentication:\n<ul xmlns=\"http://www.w3.org/1999/xhtml\">\n<li>HTTP Basic Authentication</li>\n<li>Cookie-based Authentication</li>\n</ul>\n"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
diff --git a/security-0.99/core/src/test/java/org/apache/stanbol/commons/security/PermissionDefinitionsTest.java b/security-0.99/core/src/test/java/org/apache/stanbol/commons/security/PermissionDefinitionsTest.java
new file mode 100644
index 0000000..c81a13a
--- /dev/null
+++ b/security-0.99/core/src/test/java/org/apache/stanbol/commons/security/PermissionDefinitionsTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.Arrays;
+import java.util.List;
+
+import org.junit.*;
+import org.osgi.service.permissionadmin.PermissionInfo;
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.serializedform.Parser;
+import org.apache.stanbol.commons.security.PermissionDefinitions;
+
+/**
+ *
+ * @author clemens
+ */
+public class PermissionDefinitionsTest {
+
+ private PermissionDefinitions permissionDefinitions;
+ private PermissionInfo[] allPermissions;
+ private PermissionInfo[] nullPermission;
+
+ public PermissionDefinitionsTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+
+ final Graph graph = Parser.getInstance()
+ .parse(getClass().getResourceAsStream("systemgraph.nt"),
+ "text/rdf+n3");
+ this.permissionDefinitions = new PermissionDefinitions(
+ new SimpleMGraph(graph.iterator()));
+
+ this.allPermissions = new PermissionInfo[] {
+ new PermissionInfo(
+ "(java.io.FilePermission \"file:///home/foo/-\" \"read,write,delete\")"),
+ new PermissionInfo(
+ "(java.io.FilePermission \"file:///home/foo/*\" \"read,write\")"),
+ new PermissionInfo(
+ "(java.io.FilePermission \"file:///home/*\" \"read,write\")") };
+ this.nullPermission = null;
+ }
+
+ @Test
+ public void testAllowedBundle() {
+ PermissionInfo[] permInfos = this.permissionDefinitions
+ .retrievePermissions("file:///home/foo/foobar/testbundle-1.0-SNAPSHOT.jar");
+ List<PermissionInfo> permInfoList = Arrays.asList(permInfos);
+ List<PermissionInfo> expectedPermInfos = Arrays.asList(allPermissions);
+
+ Assert.assertTrue(permInfoList.containsAll(expectedPermInfos));
+ Assert.assertTrue(expectedPermInfos.containsAll(permInfoList));
+ }
+
+ @Test
+ public void testUnknownBundle() {
+ Assert.assertNotSame(allPermissions, this.permissionDefinitions
+ .retrievePermissions("file:///foo.jar"));
+ Assert.assertArrayEquals(nullPermission, this.permissionDefinitions
+ .retrievePermissions("file:///foo.jar"));
+ }
+}
\ No newline at end of file
diff --git a/security-0.99/core/src/test/resources/org/apache/stanbol/commons/security/systemgraph.nt b/security-0.99/core/src/test/resources/org/apache/stanbol/commons/security/systemgraph.nt
new file mode 100644
index 0000000..934f8f9
--- /dev/null
+++ b/security-0.99/core/src/test/resources/org/apache/stanbol/commons/security/systemgraph.nt
@@ -0,0 +1,12 @@
+<file:///home/foo/foobar/testbundle-1.0-SNAPSHOT.jar> <http://clerezza.org/2008/11/osgi#owner> _:genid10 .
+<file:///home/testbundle-1.0-SNAPSHOT.jar> <http://clerezza.org/2008/11/osgi#owner> _:genid10 .
+<file:///home/foo/testbundle-1.0-SNAPSHOT.jar> <http://clerezza.org/2008/11/osgi#owner> _:genid10 .
+_:genid10 <http://rdfs.org/sioc/ns#has_function> _:genid20 .
+_:genid20 <http://rdfs.org/sioc/ns#has_function> _:genid22 .
+_:genid22 <http://rdfs.org/sioc/ns#has_function> _:genid23 .
+_:genid23 <http://rdfs.org/sioc/ns#has_function> _:genid24 .
+_:genid24 <http://rdfs.org/sioc/ns#has_function> _:genid21 .
+_:genid21 <http://clerezza.org/2008/10/permission#hasPermission> _:genid30 .
+_:genid30 <http://clerezza.org/2008/10/permission#javaPermissionEntry> "(java.io.FilePermission \"file:///home/foo/-\" \"read,write,delete\")" .
+_:genid30 <http://clerezza.org/2008/10/permission#javaPermissionEntry> "(java.io.FilePermission \"file:///home/foo/*\" \"read,write\")" .
+_:genid30 <http://clerezza.org/2008/10/permission#javaPermissionEntry> "(java.io.FilePermission \"file:///home/*\" \"read,write\")" .
\ No newline at end of file
diff --git a/security-0.99/pom.xml b/security-0.99/pom.xml
new file mode 100644
index 0000000..5f53481
--- /dev/null
+++ b/security-0.99/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+ <!--
+
+ 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.
+ -->
+
+ <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ !!!!!! !!!!!!
+ !!!!!! This pom is only provided !!!!!!
+ !!!!!! for release convenience !!!!!!
+ !!!!!! and is not part of trunk !!!!!!
+ !!!!!! !!!!!!
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>stanbol-parent</artifactId>
+ <version>4</version>
+ <relativePath />
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.security</artifactId>
+ <version>0.99</version>
+ <packaging>pom</packaging>
+ <name>Apache Stanbol Commons Security Reactor</name>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99
+ </developerConnection>
+ <url>scm:svn:https://svn.apache.org/repos/asf/stanbol/tags/org.apache.stanbol.commons.security-0.99</url>
+ </scm>
+
+ <modules>
+ <module>authentication.basic</module>
+ <module>core</module>
+ </modules>
+
+</project>
+