2016-09-16 5 views
0

나는 다음과 같이 MongoDB를 가진 루프백 응용 프로그램을 가지고있다. 권한 부여 오류가 발생합니다. 내가 접시 역할을 모두 허용으로 바꿀 때만 가능합니다.루프백 오류 : 필요한 권한

어떻게하면 모든 사용자가 DENY 상태를 유지하고 특정 사용자에게만 특정 작업을 허용하도록 원하는 결과를 얻을 수 있습니까? 감사합니다. 여기 내 코드는 ...

응용 프로그램/서버/모델 config.json :

{ 
    "_meta": { 
    "sources": [ 
     "loopback/common/models", 
     "loopback/server/models", 
     "../common/models", 
     "./models" 
    ], 
    "mixins": [ 
     "loopback/common/mixins", 
     "loopback/server/mixins", 
     "../node_modules/loopback-ds-timestamp-mixin", 
     "../common/mixins", 
     "./mixins" 
    ] 
    }, 
    "User": { 
    "dataSource": "db" 
    }, 
    "AccessToken": { 
    "dataSource": "db", 
    "public": false 
    }, 
    "ACL": { 
    "dataSource": "MongoDB", 
    "public": false 
    }, 
    "RoleMapping": { 
    "dataSource": "MongoDB", 
    "public": false 
    }, 
    "Role": { 
    "dataSource": "MongoDB", 
    "public": false 
    }, 
    "dishes": { 
    "dataSource": "MongoDB", 
    "public": true 
    }, 
    "Customer": { 
    "dataSource": "MongoDB", 
    "public": true 
    }, 
    "Comments": { 
    "dataSource": "MongoDB", 
    "public": true 
    } 
} 

응용 프로그램/일반/modles/dishes.json :

{ 
    "name": "dishes", 
    "base": "PersistedModel", 
    "idInjection": true, 
    "options": { 
    "validateUpsert": true 
    }, 
    "properties": { 
    "name": { 
     "type": "string", 
     "required": true 
    }, 
    "description": { 
     "type": "string", 
     "required": true 
    }, 
    "category": { 
     "type": "string", 
     "required": true 
    }, 
    "image": { 
     "type": "string", 
     "required": true 
    }, 
    "label": { 
     "type": "string", 
     "required": true, 
     "default": "''" 
    }, 
    "price": { 
     "type": "string", 
     "required": true, 
     "default": "0" 
    } 
    }, 
    "mixins": { 
    "TimeStamp": true 
    }, 
    "validations": [], 
    "relations": { 
    "comments": { 
     "type": "hasMany", 
     "model": "Comments", 
     "foreignKey": "" 
    }, 
    "customers": { 
     "type": "hasMany", 
     "model": "Customer", 
     "foreignKey": "" 
    } 
    }, 
    "acls": [ 
    { 
     "accessType": "*", 
     "principalType": "ROLE", 
     "principalId": "$everyone", 
     "permission": "DENY" 
    }, 
    { 
     "accessType": "READ", 
     "principalType": "ROLE", 
     "principalId": "$authenticated", 
     "permission": "ALLOW" 
    }, 
    { 
     "accessType": "EXECUTE", 
     "principalType": "ROLE", 
     "principalId": "admin", 
     "permission": "ALLOW", 
     "property": "create" 
    }, 
    { 
     "accessType": "WRITE", 
     "principalType": "ROLE", 
     "principalId": "admin", 
     "permission": "ALLOW" 
    } 
    ], 
    "methods": {} 
} 

응용 프로그램/일반/modles/comments.json :

{ 
    "name": "Comments", 
    "base": "PersistedModel", 
    "idInjection": true, 
    "options": { 
    "validateUpsert": true 
    }, 
    "properties": { 
    "Rating": { 
     "type": "number", 
     "required": true, 
     "default": 5 
    }, 
    "comment": { 
     "type": "string", 
     "required": true 
    } 
    }, 
    "mixins": { 
    "TimeStamp": true 
    }, 
    "validations": [], 
    "relations": { 
    "dishes": { 
     "type": "belongsTo", 
     "model": "dishes", 
     "foreignKey": "" 
    }, 
    "customer": { 
     "type": "belongsTo", 
     "model": "Customer", 
     "foreignKey": "customerId" 
    } 
    }, 
    "acls": [ 
    { 
     "accessType": "*", 
     "principalType": "ROLE", 
     "principalId": "$everyone", 
     "permission": "DENY" 
    }, 
    { 
     "accessType": "READ", 
     "principalType": "ROLE", 
     "principalId": "$authenticated", 
     "permission": "ALLOW" 
    }, 
    { 
     "accessType": "EXECUTE", 
     "principalType": "ROLE", 
     "principalId": "$authenticated", 
     "permission": "ALLOW", 
     "property": "create" 
    }, 
    { 
     "accessType": "WRITE", 
     "principalType": "ROLE", 
     "principalId": "$owner", 
     "permission": "ALLOW" 
    } 
    ], 
    "methods": {} 
} 

응용 프로그램/일반/modles/customer.json :

{ 
    "name": "Customer", 
    "base": "User", 
    "idInjection": true, 
    "options": { 
    "validateUpsert": true 
    }, 
    "properties": {}, 
    "validations": [], 
    "relations": { 
    "comments": { 
     "type": "hasMany", 
     "model": "Comments", 
     "foreignKey": "customerId" 
    } 
    }, 
    "acls": [ 
    { 
     "accessType": "*", 
     "principalType": "ROLE", 
     "principalId": "$everyone", 
     "permission": "DENY" 
    } 
    ], 
    "methods": {} 
} 

및 응용 프로그램/서버/부팅/script.js :

module.exports = function(app) { 
var MongoDB = app.dataSources.MongoDB; 

MongoDB.automigrate('Customer', function(err) { 
    if (err) throw (err); 
    var Customer = app.models.Customer; 

    Customer.create([ 
    {username: 'Admin', email: '[email protected]', password: 'abcdef'}, 
    {username: 'muppala', email: '[email protected]', password: 'abcdef'} 
    ], function(err, users) { 
     if (err) throw (err); 
     var Role = app.models.Role; 
     var RoleMapping = app.models.RoleMapping; 

     Role.find({ name: 'admin' }, function(err, results) { 
      if (err) { throw err; } 

      if (results.length < 1) { 
       // now we know the DB doesn't have it already, so do the Role creation... 
       //create the admin role 
       Role.create({ 
        name: 'admin' 
       }, function(err, role) { 
        if (err) throw (err); 
        //make admin 
        role.principals.create({ 
        principalType: RoleMapping.USER, 
        principalId: users[0].id 
        }, function(err, principal) { 
        if (err) throw (err); 
        }); 
       }); 
      } 
     }); 
    }); 
}); 

}; 

답변

0

보는 당신의 last question 무슨 일이 있었는지 상상한다.

아무튼 컬렉션 Role이 생성되었지만 User으로 매핑되지 않았습니다.

나는 변경하는 것이 좋습니다 :

Role.find({ name: 'admin' }, function(err, results) { 
      if (err) { throw err; } 

      if (results.length < 1) { 
       // now we know the DB doesn't have it already, so do the Role creation... 
       //create the admin role 
       Role.create({ 
        name: 'admin' 
       }, function(err, role) { 
        if (err) throw (err); 
        //make admin 
        role.principals.create({ 
        principalType: RoleMapping.USER, 
        principalId: users[0].id 
        }, function(err, principal) { 
        if (err) throw (err); 
        }); 
       }); 
      } 
     }); 

작성자 :

Role.create({ 
     name: 'admin' 
    }, function(err, role) { 
     if (err) throw (err); 
     //make admin 
     role.principals.create({ 
     principalType: RoleMapping.USER, 
     principalId: users[0].id 
     }, function(err, principal) { 
     if (err) throw (err); 
     }); 
    }); 

이 역할 모음 드롭 : db.Role.drop() 을 다시 루프백을 실행합니다.

참고 : 동일한 부탁을하고 저를 위해 일했습니다.

0

동일한 과제를 수행 할 때도 동일한 문제가 발생합니다. 키케 씨의 대답이 제게 도움이됩니다. cmd를에서 첫째,

>mongo 
>use conFusion (Note: conFusion is the name of database of this assignment) 
>show collections (Note: to see all collections in database collections) 
>db.Role.drop()  

그리고 노드와 루프백을 실행 타입

. 다시