{"action":"created","comment":{"url":"https://api.github.com/repos/uberfire/uberfire/pulls/comments/58433435","id":58433435,"diff_hunk":"@@ -0,0 +1,109 @@\n+/*\n+ * Copyright 2016 JBoss, by Red Hat, Inc\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *       http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.uberfire.backend.server.security;\n+\n+import java.io.File;\n+import java.net.URL;\n+import java.util.HashSet;\n+import java.util.Iterator;\n+import java.util.List;\n+import java.util.Set;\n+\n+import javax.annotation.PostConstruct;\n+import javax.enterprise.context.ApplicationScoped;\n+\n+import org.apache.commons.lang3.StringUtils;\n+import org.jdom.Document;\n+import org.jdom.Element;\n+import org.jdom.input.SAXBuilder;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+import org.uberfire.commons.services.cdi.Startup;\n+import org.uberfire.commons.services.cdi.StartupType;\n+\n+/**\n+ * Startup class that read the roles declared in the webapp's web.xml and register them into the {@link RoleRegistry}.\n+ */\n+@Startup(StartupType.BOOTSTRAP)\n+@ApplicationScoped\n+public class RoleLoader {\n+\n+    Logger logger = LoggerFactory.getLogger(RoleLoader.class);\n+\n+    @PostConstruct\n+    public void registerRolesFromwWebXml() {\n+        File webXml = getWebXmlFile();\n+        if (webXml != null) {\n+            try {\n+                Set<String> roles = loadRolesFromwWebXml(webXml);\n+                for (String role : roles) {\n+                    RoleRegistry.get().registerRole(role);\n+                }\n+                if (!roles.isEmpty()) {\n+                    logger.info(\"Roles registered \\\"\" + StringUtils.join(roles.toArray(), \",\") + \"\\\"\");\n+                }\n+            }\n+            catch (Exception e) {\n+                logger.error(\"Error reading roles from web.xml\", e);\n+            }\n+        }\n+    }\n+\n+    protected File getWebXmlFile() {\n+        String[] paths = new String[] {\n+                \"security-policy.properties\",\n+                \"security-management.properties\",\n+                \"WEB-INF/classes/security-policy.properties\",\n+                \"WEB-INF/classes/security-management.properties\"};\n+\n+        for (String path : paths) {\n+            URL pathURL = Thread.currentThread().getContextClassLoader().getResource(path);\n+            if (pathURL != null) {\n+                File webInf = new File(pathURL.getPath()).getParentFile().getParentFile();\n+                return new File(webInf, \"web.xml\");","path":"uberfire-backend/uberfire-backend-server/src/main/java/org/uberfire/backend/server/security/RoleLoader.java","position":77,"original_position":77,"commit_id":"1019c61a31890f5406af7d466be6696d2845cbb7","original_commit_id":"1019c61a31890f5406af7d466be6696d2845cbb7","user":{"login":"porcelli","id":119395,"avatar_url":"https://avatars.githubusercontent.com/u/119395?v=3","gravatar_id":"","url":"https://api.github.com/users/porcelli","html_url":"https://github.com/porcelli","followers_url":"https://api.github.com/users/porcelli/followers","following_url":"https://api.github.com/users/porcelli/following{/other_user}","gists_url":"https://api.github.com/users/porcelli/gists{/gist_id}","starred_url":"https://api.github.com/users/porcelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/porcelli/subscriptions","organizations_url":"https://api.github.com/users/porcelli/orgs","repos_url":"https://api.github.com/users/porcelli/repos","events_url":"https://api.github.com/users/porcelli/events{/privacy}","received_events_url":"https://api.github.com/users/porcelli/received_events","type":"User","site_admin":false},"body":"use file:// from VFS","created_at":"2016-04-04T19:29:25Z","updated_at":"2016-04-04T19:29:25Z","html_url":"https://github.com/uberfire/uberfire/pull/321#discussion_r58433435","pull_request_url":"https://api.github.com/repos/uberfire/uberfire/pulls/321","_links":{"self":{"href":"https://api.github.com/repos/uberfire/uberfire/pulls/comments/58433435"},"html":{"href":"https://github.com/uberfire/uberfire/pull/321#discussion_r58433435"},"pull_request":{"href":"https://api.github.com/repos/uberfire/uberfire/pulls/321"}}},"pull_request":{"url":"https://api.github.com/repos/uberfire/uberfire/pulls/321","id":62946503,"html_url":"https://github.com/uberfire/uberfire/pull/321","diff_url":"https://github.com/uberfire/uberfire/pull/321.diff","patch_url":"https://github.com/uberfire/uberfire/pull/321.patch","issue_url":"https://api.github.com/repos/uberfire/uberfire/issues/321","number":321,"state":"open","locked":false,"title":"UF-280: Authz Management","user":{"login":"dgutierr","id":2429839,"avatar_url":"https://avatars.githubusercontent.com/u/2429839?v=3","gravatar_id":"","url":"https://api.github.com/users/dgutierr","html_url":"https://github.com/dgutierr","followers_url":"https://api.github.com/users/dgutierr/followers","following_url":"https://api.github.com/users/dgutierr/following{/other_user}","gists_url":"https://api.github.com/users/dgutierr/gists{/gist_id}","starred_url":"https://api.github.com/users/dgutierr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgutierr/subscriptions","organizations_url":"https://api.github.com/users/dgutierr/orgs","repos_url":"https://api.github.com/users/dgutierr/repos","events_url":"https://api.github.com/users/dgutierr/events{/privacy}","received_events_url":"https://api.github.com/users/dgutierr/received_events","type":"User","site_admin":false},"body":"This is the first PR towards the full implementation of the following ticket:\r\n\r\nhttps://issues.jboss.org/browse/UF-280\r\n\r\n.. and it also contains this one:\r\n\r\nhttps://issues.jboss.org/browse/UF-290\r\n\r\n\r\nThe PR contains the authorization management APIs, client/backend implementations and tests. In this very first milestone the following features are supported:\r\n\r\n* A security policy can be defined at webapp level. For example: \r\n\r\nhttps://github.com/dgutierr/uberfire/blob/UF-280/uberfire-showcase/uberfire-webapp/src/main/resources/security-policy.properties\r\n\r\nThe security policy allows for declaring permissions over managed resources (currently only perspectives, screens, editors, splash screens, popups or menu entries). \r\n\r\nEvery webapp can provide a custom policy (a file named _security-policy.properties_ available under the webapp's classpath). If no policy is available then the UF security module will behave **exactly** as before the new API was added, i:e. checking the user's roles against the roles attached to Resource instances.\r\n\r\n* Permissions can be granted/denied either to a set of resources or over a single resource. For example:\r\n\r\n  \"Users with role analyst can view all perspectives except _Administration_\"\r\n\r\n        role.analyst.permission.perspective.view.*=true  \r\n        role.analyst.permission.perspective.view.Administration=false\r\n\r\n* The permission types can be easily extended to support in the future other workbench resources like repositories, projects or organizational units, just by adding new _PermissionType_ implementations.\r\n\r\n* Ability to set the _Home_ perspective the user will be redirected after login.\r\n\r\n           role.admin.home=AdminHomePerspective\r\n\r\n\r\n\r\nNext steps to fully implement the UF-280 ticket are:\r\n\r\n* Security policy editor to let users to modify the security policy right from the UI\r\n* Security policy storage under the UF's system repo\r\n* Support for filesystem/repository/path permissions \r\n* Documentation \r\n\r\n@porcelli Can you review & merge please?","created_at":"2016-03-15T17:35:58Z","updated_at":"2016-04-04T19:29:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"094d4f5a16a5d0eb7b1d3a97a5233b2a14245d00","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/uberfire/uberfire/pulls/321/commits","review_comments_url":"https://api.github.com/repos/uberfire/uberfire/pulls/321/comments","review_comment_url":"https://api.github.com/repos/uberfire/uberfire/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uberfire/uberfire/issues/321/comments","statuses_url":"https://api.github.com/repos/uberfire/uberfire/statuses/1019c61a31890f5406af7d466be6696d2845cbb7","head":{"label":"dgutierr:UF-280","ref":"UF-280","sha":"1019c61a31890f5406af7d466be6696d2845cbb7","user":{"login":"dgutierr","id":2429839,"avatar_url":"https://avatars.githubusercontent.com/u/2429839?v=3","gravatar_id":"","url":"https://api.github.com/users/dgutierr","html_url":"https://github.com/dgutierr","followers_url":"https://api.github.com/users/dgutierr/followers","following_url":"https://api.github.com/users/dgutierr/following{/other_user}","gists_url":"https://api.github.com/users/dgutierr/gists{/gist_id}","starred_url":"https://api.github.com/users/dgutierr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgutierr/subscriptions","organizations_url":"https://api.github.com/users/dgutierr/orgs","repos_url":"https://api.github.com/users/dgutierr/repos","events_url":"https://api.github.com/users/dgutierr/events{/privacy}","received_events_url":"https://api.github.com/users/dgutierr/received_events","type":"User","site_admin":false},"repo":{"id":24107609,"name":"uberfire","full_name":"dgutierr/uberfire","owner":{"login":"dgutierr","id":2429839,"avatar_url":"https://avatars.githubusercontent.com/u/2429839?v=3","gravatar_id":"","url":"https://api.github.com/users/dgutierr","html_url":"https://github.com/dgutierr","followers_url":"https://api.github.com/users/dgutierr/followers","following_url":"https://api.github.com/users/dgutierr/following{/other_user}","gists_url":"https://api.github.com/users/dgutierr/gists{/gist_id}","starred_url":"https://api.github.com/users/dgutierr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgutierr/subscriptions","organizations_url":"https://api.github.com/users/dgutierr/orgs","repos_url":"https://api.github.com/users/dgutierr/repos","events_url":"https://api.github.com/users/dgutierr/events{/privacy}","received_events_url":"https://api.github.com/users/dgutierr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dgutierr/uberfire","description":"UberFire Framework","fork":true,"url":"https://api.github.com/repos/dgutierr/uberfire","forks_url":"https://api.github.com/repos/dgutierr/uberfire/forks","keys_url":"https://api.github.com/repos/dgutierr/uberfire/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dgutierr/uberfire/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dgutierr/uberfire/teams","hooks_url":"https://api.github.com/repos/dgutierr/uberfire/hooks","issue_events_url":"https://api.github.com/repos/dgutierr/uberfire/issues/events{/number}","events_url":"https://api.github.com/repos/dgutierr/uberfire/events","assignees_url":"https://api.github.com/repos/dgutierr/uberfire/assignees{/user}","branches_url":"https://api.github.com/repos/dgutierr/uberfire/branches{/branch}","tags_url":"https://api.github.com/repos/dgutierr/uberfire/tags","blobs_url":"https://api.github.com/repos/dgutierr/uberfire/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dgutierr/uberfire/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dgutierr/uberfire/git/refs{/sha}","trees_url":"https://api.github.com/repos/dgutierr/uberfire/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dgutierr/uberfire/statuses/{sha}","languages_url":"https://api.github.com/repos/dgutierr/uberfire/languages","stargazers_url":"https://api.github.com/repos/dgutierr/uberfire/stargazers","contributors_url":"https://api.github.com/repos/dgutierr/uberfire/contributors","subscribers_url":"https://api.github.com/repos/dgutierr/uberfire/subscribers","subscription_url":"https://api.github.com/repos/dgutierr/uberfire/subscription","commits_url":"https://api.github.com/repos/dgutierr/uberfire/commits{/sha}","git_commits_url":"https://api.github.com/repos/dgutierr/uberfire/git/commits{/sha}","comments_url":"https://api.github.com/repos/dgutierr/uberfire/comments{/number}","issue_comment_url":"https://api.github.com/repos/dgutierr/uberfire/issues/comments{/number}","contents_url":"https://api.github.com/repos/dgutierr/uberfire/contents/{+path}","compare_url":"https://api.github.com/repos/dgutierr/uberfire/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dgutierr/uberfire/merges","archive_url":"https://api.github.com/repos/dgutierr/uberfire/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dgutierr/uberfire/downloads","issues_url":"https://api.github.com/repos/dgutierr/uberfire/issues{/number}","pulls_url":"https://api.github.com/repos/dgutierr/uberfire/pulls{/number}","milestones_url":"https://api.github.com/repos/dgutierr/uberfire/milestones{/number}","notifications_url":"https://api.github.com/repos/dgutierr/uberfire/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dgutierr/uberfire/labels{/name}","releases_url":"https://api.github.com/repos/dgutierr/uberfire/releases{/id}","deployments_url":"https://api.github.com/repos/dgutierr/uberfire/deployments","created_at":"2014-09-16T16:23:12Z","updated_at":"2016-02-08T13:03:43Z","pushed_at":"2016-04-04T14:14:49Z","git_url":"git://github.com/dgutierr/uberfire.git","ssh_url":"git@github.com:dgutierr/uberfire.git","clone_url":"https://github.com/dgutierr/uberfire.git","svn_url":"https://github.com/dgutierr/uberfire","homepage":"http://www.uberfireframework.org","size":21596,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"uberfire:master","ref":"master","sha":"a0bf142be9c6cc63704e0de0e13d6ea5ec460d81","user":{"login":"uberfire","id":5167699,"avatar_url":"https://avatars.githubusercontent.com/u/5167699?v=3","gravatar_id":"","url":"https://api.github.com/users/uberfire","html_url":"https://github.com/uberfire","followers_url":"https://api.github.com/users/uberfire/followers","following_url":"https://api.github.com/users/uberfire/following{/other_user}","gists_url":"https://api.github.com/users/uberfire/gists{/gist_id}","starred_url":"https://api.github.com/users/uberfire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uberfire/subscriptions","organizations_url":"https://api.github.com/users/uberfire/orgs","repos_url":"https://api.github.com/users/uberfire/repos","events_url":"https://api.github.com/users/uberfire/events{/privacy}","received_events_url":"https://api.github.com/users/uberfire/received_events","type":"Organization","site_admin":false},"repo":{"id":4335576,"name":"uberfire","full_name":"uberfire/uberfire","owner":{"login":"uberfire","id":5167699,"avatar_url":"https://avatars.githubusercontent.com/u/5167699?v=3","gravatar_id":"","url":"https://api.github.com/users/uberfire","html_url":"https://github.com/uberfire","followers_url":"https://api.github.com/users/uberfire/followers","following_url":"https://api.github.com/users/uberfire/following{/other_user}","gists_url":"https://api.github.com/users/uberfire/gists{/gist_id}","starred_url":"https://api.github.com/users/uberfire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uberfire/subscriptions","organizations_url":"https://api.github.com/users/uberfire/orgs","repos_url":"https://api.github.com/users/uberfire/repos","events_url":"https://api.github.com/users/uberfire/events{/privacy}","received_events_url":"https://api.github.com/users/uberfire/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uberfire/uberfire","description":"UberFire Framework","fork":false,"url":"https://api.github.com/repos/uberfire/uberfire","forks_url":"https://api.github.com/repos/uberfire/uberfire/forks","keys_url":"https://api.github.com/repos/uberfire/uberfire/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uberfire/uberfire/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uberfire/uberfire/teams","hooks_url":"https://api.github.com/repos/uberfire/uberfire/hooks","issue_events_url":"https://api.github.com/repos/uberfire/uberfire/issues/events{/number}","events_url":"https://api.github.com/repos/uberfire/uberfire/events","assignees_url":"https://api.github.com/repos/uberfire/uberfire/assignees{/user}","branches_url":"https://api.github.com/repos/uberfire/uberfire/branches{/branch}","tags_url":"https://api.github.com/repos/uberfire/uberfire/tags","blobs_url":"https://api.github.com/repos/uberfire/uberfire/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uberfire/uberfire/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uberfire/uberfire/git/refs{/sha}","trees_url":"https://api.github.com/repos/uberfire/uberfire/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uberfire/uberfire/statuses/{sha}","languages_url":"https://api.github.com/repos/uberfire/uberfire/languages","stargazers_url":"https://api.github.com/repos/uberfire/uberfire/stargazers","contributors_url":"https://api.github.com/repos/uberfire/uberfire/contributors","subscribers_url":"https://api.github.com/repos/uberfire/uberfire/subscribers","subscription_url":"https://api.github.com/repos/uberfire/uberfire/subscription","commits_url":"https://api.github.com/repos/uberfire/uberfire/commits{/sha}","git_commits_url":"https://api.github.com/repos/uberfire/uberfire/git/commits{/sha}","comments_url":"https://api.github.com/repos/uberfire/uberfire/comments{/number}","issue_comment_url":"https://api.github.com/repos/uberfire/uberfire/issues/comments{/number}","contents_url":"https://api.github.com/repos/uberfire/uberfire/contents/{+path}","compare_url":"https://api.github.com/repos/uberfire/uberfire/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uberfire/uberfire/merges","archive_url":"https://api.github.com/repos/uberfire/uberfire/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uberfire/uberfire/downloads","issues_url":"https://api.github.com/repos/uberfire/uberfire/issues{/number}","pulls_url":"https://api.github.com/repos/uberfire/uberfire/pulls{/number}","milestones_url":"https://api.github.com/repos/uberfire/uberfire/milestones{/number}","notifications_url":"https://api.github.com/repos/uberfire/uberfire/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uberfire/uberfire/labels{/name}","releases_url":"https://api.github.com/repos/uberfire/uberfire/releases{/id}","deployments_url":"https://api.github.com/repos/uberfire/uberfire/deployments","created_at":"2012-05-15T12:40:55Z","updated_at":"2016-02-01T02:17:10Z","pushed_at":"2016-04-04T14:14:49Z","git_url":"git://github.com/uberfire/uberfire.git","ssh_url":"git@github.com:uberfire/uberfire.git","clone_url":"https://github.com/uberfire/uberfire.git","svn_url":"https://github.com/uberfire/uberfire","homepage":"http://www.uberfireframework.org","size":21298,"stargazers_count":53,"watchers_count":53,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":84,"mirror_url":null,"open_issues_count":3,"forks":84,"open_issues":3,"watchers":53,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uberfire/uberfire/pulls/321"},"html":{"href":"https://github.com/uberfire/uberfire/pull/321"},"issue":{"href":"https://api.github.com/repos/uberfire/uberfire/issues/321"},"comments":{"href":"https://api.github.com/repos/uberfire/uberfire/issues/321/comments"},"review_comments":{"href":"https://api.github.com/repos/uberfire/uberfire/pulls/321/comments"},"review_comment":{"href":"https://api.github.com/repos/uberfire/uberfire/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uberfire/uberfire/pulls/321/commits"},"statuses":{"href":"https://api.github.com/repos/uberfire/uberfire/statuses/1019c61a31890f5406af7d466be6696d2845cbb7"}}}}