Skip to content

Commit

Permalink
Fix/role permission registration (#3)
Browse files Browse the repository at this point in the history
* Use property create by default so that people do not complain if database doesn't create the schema by default

* Fix bug: User getting admin permission even when roleAdmin is set to false
  • Loading branch information
isopropylcyanide authored Mar 23, 2019
1 parent 414eb9f commit ea01356
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/accolite/pru/health/AuthApp/model/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public Role() {

}

public boolean isAdminRole(){
return null != this && this.role.equals(RoleName.ROLE_ADMIN);
}

public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,13 @@ public User createUser(RegistrationRequest registerRequest) {
}

/**
* Performs a quick check to see what roles the new user could benefit from
* Performs a quick check to see what roles the new user could be assigned to.
* @return list of roles for the new user
*/
private Set<Role> getRolesForNewUser(Boolean isAdmin) {
private Set<Role> getRolesForNewUser(Boolean isToBeMadeAdmin) {
Set<Role> newUserRoles = new HashSet<>(roleService.findAll());
Role adminRole = new Role(RoleName.ROLE_ADMIN);
if (!isAdmin) {
newUserRoles.remove(adminRole);
if (!isToBeMadeAdmin){
newUserRoles.removeIf(Role::isAdminRole);
}
logger.info("Setting user roles: " + newUserRoles);
return newUserRoles;
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ spring.datasource.password=
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1

#JPA properties
spring.jpa.hibernate.ddl-auto=none
#JPA properties. Using ddl-auto = create will drop schema every-time.
#Choose the correct property based on development / production role.
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.initialization-mode=always
spring.jpa.properties.hibernate.format_sql=true
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/mail.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#Mail properties
spring.mail.default-encoding=UTF-8
spring.mail.host=smtp.gmail.com
spring.mail.username=accolite.pru.cep@gmail.com
spring.mail.password=accolitecep
spring.mail.username=your@email.com
spring.mail.password=your-email-password
spring.mail.port=587
spring.mail.protocol=smtp
spring.mail.debug=true
Expand Down

0 comments on commit ea01356

Please sign in to comment.