{"action":"created","issue":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1977","labels_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1977/labels{/name}","comments_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1977/comments","events_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1977/events","html_url":"https://github.com/jhipster/generator-jhipster/issues/1977","id":104944517,"number":1977,"title":"Authorization problems with roles in AngularJs","user":{"login":"Chinokao","id":12040509,"avatar_url":"https://avatars.githubusercontent.com/u/12040509?v=3","gravatar_id":"","url":"https://api.github.com/users/Chinokao","html_url":"https://github.com/Chinokao","followers_url":"https://api.github.com/users/Chinokao/followers","following_url":"https://api.github.com/users/Chinokao/following{/other_user}","gists_url":"https://api.github.com/users/Chinokao/gists{/gist_id}","starred_url":"https://api.github.com/users/Chinokao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chinokao/subscriptions","organizations_url":"https://api.github.com/users/Chinokao/orgs","repos_url":"https://api.github.com/users/Chinokao/repos","events_url":"https://api.github.com/users/Chinokao/events{/privacy}","received_events_url":"https://api.github.com/users/Chinokao/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-04T18:35:44Z","updated_at":"2015-09-06T10:28:46Z","closed_at":"2015-09-06T10:28:46Z","body":"I think there is a problem in isInAnyRole Principal Service function, I found that it calls to the same service isInRole function which happens to return a promise if user is authenticated. The problem is that when calling to that function from isInAnyRole without .then() it always returns true. I was looking to the sample project and in that line it doest'n call to isInRole function so it works perfectly.\r\nHere the diferences:\r\nMy project (Release 2.19.0)\r\n```javascript\r\nisInRole: function (role) {\r\n    if (!_authenticated) {\r\n        return false;\r\n    }\r\n    return this.identity().then(function (_id) {\r\n        return _id.roles && _id.roles.indexOf(role) !== -1;\r\n        }, function () {\r\n            return false;\r\n        });\r\n},\r\nisInAnyRole: function (roles) {\r\n    if (!_authenticated || !_identity || !_identity.roles) {\r\n        return false;\r\n    }\r\n    for (var i = 0; i < roles.length; i++) {\r\n        if (this.isInRole(roles[i])) { // this is always true in my project\r\n            return true;\r\n        }\r\n    }\r\n    return false;\r\n}\r\n```\r\nSample project: \r\n```javascript\r\nisInRole: function (role) {\r\n    if (!_authenticated) {\r\n        return false;\r\n    }\r\n    return this.identity().then(function(_id) {\r\n        return _id.roles && _id.roles.indexOf(role) !== -1;\r\n        }, function(err){\r\n            return false;\r\n        });\r\n},\r\nisInAnyRole: function (roles) {\r\n    if (!_authenticated || !_identity || !_identity.roles) {\r\n        return false;\r\n    }\r\n    for (var i = 0; i < roles.length; i++) {\r\n        if (_identity.roles.indexOf(roles[i]) !== -1) { // this is only true when user role is in data.roles\r\n            return true;\r\n        }\r\n    }\r\n    return false;\r\n}\r\n```\r\nThe problem is that authorize function from Auth Service uses isAnyRole function and so hasAnyRole directive, so both function and directive don't work (I can't hide menus with has-any-role neither redirect to accessdenied state when user is not authorized). I fixed it using the sample isInAnyRole function, but I just wanted to tell you about this."},"comment":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/comments/138063818","html_url":"https://github.com/jhipster/generator-jhipster/issues/1977#issuecomment-138063818","issue_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1977","id":138063818,"user":{"login":"jdubois","id":316835,"avatar_url":"https://avatars.githubusercontent.com/u/316835?v=3","gravatar_id":"","url":"https://api.github.com/users/jdubois","html_url":"https://github.com/jdubois","followers_url":"https://api.github.com/users/jdubois/followers","following_url":"https://api.github.com/users/jdubois/following{/other_user}","gists_url":"https://api.github.com/users/jdubois/gists{/gist_id}","starred_url":"https://api.github.com/users/jdubois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdubois/subscriptions","organizations_url":"https://api.github.com/users/jdubois/orgs","repos_url":"https://api.github.com/users/jdubois/repos","events_url":"https://api.github.com/users/jdubois/events{/privacy}","received_events_url":"https://api.github.com/users/jdubois/received_events","type":"User","site_admin":false},"created_at":"2015-09-06T10:28:46Z","updated_at":"2015-09-06T10:28:46Z","body":"Thanks for the feedback.\r\n\r\nWe just merged https://github.com/jhipster/generator-jhipster/pull/1708 and it looks like a duplicate -> that's why I'm closing this, but can you have a look and re-open or send a comment if you disagree?"}}