我正在使用JHipster和MongoDb创建应用程序,我正在尝试添加新角色。 我向security / AuthoritiesConstants添加了新常量,但在我的集合中jhi_authorities我没有看到更改。
有人知道如何将我的新角色添加到此集合中吗?
答案 0 :(得分:0)
您还必须将新权限添加到MongoDb,请参阅InitialSetupMigration.java
,在此处添加或创建新迁移。
见doc
答案 1 :(得分:0)
当然我做到了但是在构建过程中我收到了以下消息:
[ restartedMain] com.github.mongobee.Mongobee : [ChangeSet: id=01-addAuthorities, author=initiator, changeLogClass=com.anuglarspring.app.config.dbmigrations.InitialSetupMigration, changeSetMethod=addAuthorities] passed over
答案 2 :(得分:0)
使用@ChangeSet创建新的@ChangeLg和write方法 像这个例子
@ChangeLog(order = "002")
public class AddOthersAuthorities {
@ChangeSet(order = "01", author = "initiator", id = "03-addOthersAuthorities")
public void addAuthorities(DB db) {
DBCollection authorityCollection = db.getCollection("jhi_authority");
// Role for super administration
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_SUPER_ADMIN")
.get());
// Role for company administration
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_COMPANY_ADMIN")
.get());
// Role for branch administration
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_BRANCH_ADMIN")
.get());
// Role for employee
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_EMPLOYEE")
.get());
// Role for registred customer
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_CUSTOMER")
.get());
// Role for non registred customer
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_GUEST")
.get());
}
}