diff --git a/MySQL_conf_pbx/test1/mariadb_data/ib_logfile0 b/MySQL_conf_pbx/test1/mariadb_data/ib_logfile0 index e6ee136..1f39461 100644 Binary files a/MySQL_conf_pbx/test1/mariadb_data/ib_logfile0 and b/MySQL_conf_pbx/test1/mariadb_data/ib_logfile0 differ diff --git a/MySQL_conf_pbx/test1/springCezenPBX/src/main/java/com/example/cezenPBX/DAO/UserOpsDAOImpl.java b/MySQL_conf_pbx/test1/springCezenPBX/src/main/java/com/example/cezenPBX/DAO/UserOpsDAOImpl.java index f234c99..0e47754 100644 --- a/MySQL_conf_pbx/test1/springCezenPBX/src/main/java/com/example/cezenPBX/DAO/UserOpsDAOImpl.java +++ b/MySQL_conf_pbx/test1/springCezenPBX/src/main/java/com/example/cezenPBX/DAO/UserOpsDAOImpl.java @@ -30,28 +30,20 @@ public class UserOpsDAOImpl implements UserOpsDAO{ // get roles from the database // Admin sets a username and password for the first time - // TODO make sure you Hash the password - // TODO prepend {bcrypt} before commiting the password - // TODO admin can only set the password once @Override @Transactional public ReturnStatus adminSetPasswordToDb(UserEntity userEntity) { - System.out.println("Entity manager Entered"); try { if (checkIfAdminExists(userEntity)) { return new ReturnStatus(false, "Admin already exists", ""); } - // Fetch existing ROLE_Admin from DB Role adminRole = (Role) entityManager.createQuery("FROM Role r WHERE r.role = :roleName") .setParameter("roleName", "ROLE_Admin") .getSingleResult(); userEntity.setARole(adminRole); - - System.out.println("ADMIN_role id = "+adminRole.getId()); - // Persist the user entityManager.persist(userEntity); return new ReturnStatus(true, "Admin created", ""); diff --git a/MySQL_conf_pbx/test1/springCezenPBX/src/main/java/com/example/cezenPBX/service/PbxUserService.java b/MySQL_conf_pbx/test1/springCezenPBX/src/main/java/com/example/cezenPBX/service/PbxUserService.java index 255420a..ee4a5de 100644 --- a/MySQL_conf_pbx/test1/springCezenPBX/src/main/java/com/example/cezenPBX/service/PbxUserService.java +++ b/MySQL_conf_pbx/test1/springCezenPBX/src/main/java/com/example/cezenPBX/service/PbxUserService.java @@ -5,6 +5,7 @@ import com.example.cezenPBX.DTO.ReturnStatus; import com.example.cezenPBX.entity.user.Role; import com.example.cezenPBX.entity.user.UserEntity; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import java.util.List; @@ -15,20 +16,19 @@ public class PbxUserService { @Autowired private UserOpsDAO userOpsDAO; + @Autowired + private PasswordEncoder passwordEncoder; + // must perform the sanity checks before being set to the database // method will return a faulty return status if the damin exists public ReturnStatus adminSetUserNamePasswordSet(String userName, String password, String confirmPassword){ - // password will be checked here if(!password.equals(confirmPassword)){ return new ReturnStatus(false, "Passwords do not match", "Passwords do not match"); } - - UserEntity userEntity = new UserEntity(userName, password); - //userEntity.setARole(new Role("ROLE_Admin")); - - //System.out.println("Reached here already service layer"); + // password encryption + UserEntity userEntity = new UserEntity(userName, "{bcrypt}"+passwordEncoder.encode(password)); // commit the username and password to the database return userOpsDAO.adminSetPasswordToDb(userEntity);