Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Guest role added to State doesn't allow guest access #1098

Closed
mleanos opened this issue Dec 11, 2015 · 0 comments
Closed

Guest role added to State doesn't allow guest access #1098

mleanos opened this issue Dec 11, 2015 · 0 comments
Assignees
Milestone

Comments

@mleanos
Copy link
Member

mleanos commented Dec 11, 2015

When adding the guest role to any client route's data.roles array, it doesn't have any effect on the resolving of that route; the route is inaccessible to the unauthenticated user.

To reproduce, just add the following to this route config articles.client.routes

data: {
  roles: ['guest']
}

Currently, this route is accessible to unauthenticated user because of how the core client app init $stateChangeStart is working.

It doesn't take into account that when the toState.data.roles has length, but there's no authenticated user. It just continues processing and never checks for guest access.

I realize that if a client route has guest access, then the data.roles probably wouldn't have any other roles defined; and most likely, it would not have this setting on the route. However, this is still a bug because of the intended use of data.roles is to allow complete flexibility,& the developer should have complete control.

One should be able to define a client route with data.roles = ['user', 'admin', 'guest'], or any combination that suits their needs.

The simple fix is to add || role === 'guest' to the $stateChangeStart code like so, and should satisfy this bug..

var allowed = false;
  toState.data.roles.forEach(function (role) {
  if ((Authentication.user.roles !== undefined && Authentication.user.roles.indexOf(role) !== -1) || (role === 'guest')) {
    allowed = true;
    return true;
  }
});
@lirantal lirantal added this to the 0.5.0 milestone Dec 18, 2015
mleanos added a commit to mleanos/mean that referenced this issue Dec 30, 2015
Adds a check for the existence of the "guest" role in the state configuration
that we're transitioning to, in the core $stateChangeStart event handler. If
it exists, then we allow access.

Also, added validation of Authentication.user object. While writing
tests, I ran into an issue here when the Authentication service wasn't injected
into a controller. Probably best to have this check in place.

Fixes meanjs#1098
lupinthethirdgentleman pushed a commit to lupinthethirdgentleman/mean-dashboard that referenced this issue Aug 5, 2021
Adds a check for the existence of the "guest" role in the state configuration
that we're transitioning to, in the core $stateChangeStart event handler. If
it exists, then we allow access.

Also, added validation of Authentication.user object. While writing
tests, I ran into an issue here when the Authentication service wasn't injected
into a controller. Probably best to have this check in place.

Fixes meanjs/mean#1098
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants