uAdmin the Golang Web Framework #6 Authentication and Permissions

Abdullah Alrasheed
4 min readNov 10, 2018

--

With the user model you can create new users and assign them to groups using the group model. Both user and group can be assigned permissions to access parts of your system. By default the system creates one user which is the admin user who has full permission to read, add edit and delete data from every model. So let’s create a new user in the system.

To do that, go to “USERS” model in your dashboard and create a new user.

Notice the the password field is masked and you should click on the blue button to show it’s content. Don’t worry your password will be be saved in the DB in clear text. It will be hashed using bcrypt with fairly high level of difficulty (It almost take 500ms to hash the password). Also, make sure that you made the user “Active” or you will not be able to login with that user.

Finally, the user should be able to access the app remotely, then check “Remote Access”. If it is not checked, you will only be able to login if you are connected to the server using a private IP e.g. (10.x.x.x,192.168.x.x, 127.x.x.x or ::1)

Now save your use and logout. then login with the new username. Notice that we don’t have access to any dashboard models.

Let’s give our user some permissions. First, logout and login again as admin. then go to the new user and open the second tab “USER PERMISSION”

Add a few permissions to your user:

Logout and login again with the new user.

Notice that you have now access to the models that you have permission to. Logout and login again as admin. Now go to “USER GROUPS” and add a new group. After you save it, go to the second tab “GROUP PERMISSION” and add a new permission that you don’t have in the user level and only check “Read”.

Notice that your group has Read only access to log. Add your user to the new group.

Logout and login again with your user and notice that you have now access to the models from your user and from your group.

By default you get permission to all the models that your group has permission to. Your user permissions override these in case of a model existing in group permissions and user permissions. To test that give your user Add, Save and Delete to the model that your group has Read only access. (You have to do that from admin)

Now log in again with your user and check that you have full access to this model even when your group has Read only access.

You can also use that to give the user less permission than what the group is giving them. Go back to admin and uncheck Read, Add, Edit and Delete from the model that your group has.

Login in again with your user and notice that you lost your permission to access the model that your group has access to.

Congrats, you now know how to:

  • Manage users and groups
  • Customize group permissions
  • Override group permission with user permissions

In part 7, we will talk about Logs.

--

--