现在,您收到的错误是因为没有定义为Principal的模型.并且在引导应用程序时,它没有在Loopback核心模型或为我们的应用程序生成的模型中找到Principal模型,因此引发了错误throw new Error('Model not found: ' + modelName); ^Error: Model not found: PrincipalI'm reading Access control concepts of Loopback (https://docs.strongloop.com/display/public/LB/Authentication%2C+authorization%2C+and+permissions) and I don't understand how happened that Principal is not a model, but Role, RoleMapping, ACL are models with a full set of REST API methods and are listed in model-config.json? When I tried to include Principal in model-config.json along with Role, RoleMapping and ACL I got error:"ACL": { "dataSource": "db", "public": false},"RoleMapping": { "dataSource": "db", "public": false},"Role": { "dataSource": "db", "public": false},"Principal": { "dataSource": "db", "public": true},Error:throw new Error('Model not found: ' + modelName); ^Error: Model not found: PrincipalWhere is logic here? Principal is in one line with others but isn't a model. Why? 解决方案 Let's first make it clear, what a principal is?As per the documentation, Principal is an entity that can be identified or authenticated. It represents identities of a request to protected resources. For example: an user instance can be authenticated to execute a create request. Therefore, that user instance can be a principal.If we can use user, application or role in place of principal, it doesn't make sense to make another model in core loopback.But if you see Class Principal as per the documentation,This class represents the abstract notion of a principal, which can be used to represent any entity, such as an individual, a corporation, and a login id. This class have three attributes: type, id and name. This type field specifies which model is being used for principal. principal class instance can be created in many ways. For example, for role model instance as in role.principals.create({ principalType: app.models.RoleMapping.USER, principalId: admin.id}, function(err, principal) { if (err) { throw err; } else { next(); }});Here, we created new principal instance for a role instance. Now this principal can be used to authenticate a request. Also, notice principalType is used to define which model is being used to create a principal.Note:I hope, now, it make sense that principal uses other model instances that can be uniquely identified and thus, can be used to authenticate requests to protected resources like a create rest endpoint.Now the error you received is because there is no model defined as Principal. And while bootstrapping the app, it didn't found the Principal model in either Loopback core models or generated model for our app so it threw the errorthrow new Error('Model not found: ' + modelName); ^Error: Model not found: Principal 这篇关于为什么Principal不是模型,而是Role,RoleMapping,ACL突然成为模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-15 02:58