LoopBack's default ACLs are more specific than the ones you are defining, so that yours don't have effect at the end. The @authenticated and @unauthenticated ALLOW rules doesn't have precedence over DENY all rules. But custom roles do, and using a custom ADMINISTRATOR role is the right way in the framework.
- You need to create a Role for an specific user.
- Map that role to the user using the RoleMapping model.
Steps 1 and 2 can be done with this boot script (ex: App/server/boot/create-admin-user.js):
module.exports = function(app) {
var User = app.models.ExtendedUser;
var Role = app.models.Role;
var RoleMapping = app.models.RoleMapping;
User.findOrCreate({ where: { username: 'admin', email: '[email protected]' } },
{
username: 'admin',
email: '[email protected]',
password: 'admin123'
},
function(err, user) {
if (err) return console.log(err);
// Create the admin role
Role.findOrCreate({where: { name: 'ADMINISTRATOR' }},
{ name: 'ADMINISTRATOR' },
function(err, role) {
if (err) return debug(err);
console.log("Role Created: " + role.name);
// Assign admin role
RoleMapping.findOrCreate({where: { roleId: role.id, principalId: user.id }},
{ roleId: role.id, principalId: user.id, principalType: RoleMapping.USER },
function(err, roleMapping) {
if (err) return console.log(err);
console.log("ADMINISTRATOR Role assigned to " + user.username);
});
});
});
};
- Create an ACL entry in your
ExtendedUser model to ALLOW the ROLE ADMINISTRATOR to WRITE:
```
{
"name": "ExtendedUser",
"base": "User",
/* ... */
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "ADMINISTRATOR",
"permission": "ALLOW"
}
]
}