-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from JimTheCat/CU-8696y76jy_EPIC---API-v3_King…
…a-Traczyk Cu 8696y76jy epic api v3 kinga traczyk
- Loading branch information
Showing
29 changed files
with
368 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,8 @@ | ||
package meowhub.backend.security; | ||
|
||
import meowhub.backend.constants.Genders; | ||
import meowhub.backend.constants.PrivacySettings; | ||
import meowhub.backend.constants.Roles; | ||
import meowhub.backend.users.models.Gender; | ||
import meowhub.backend.users.models.PrivacySetting; | ||
import meowhub.backend.users.models.Role; | ||
import meowhub.backend.users.models.User; | ||
import meowhub.backend.users.repositories.PrivacySettingRepository; | ||
import meowhub.backend.users.repositories.GenderRepository; | ||
import meowhub.backend.users.repositories.RoleRepository; | ||
import meowhub.backend.users.repositories.UserRepository; | ||
import meowhub.backend.users.facades.UserAuthServiceFacade; | ||
import meowhub.backend.security.jwt.AuthEntryPointJwt; | ||
import meowhub.backend.security.jwt.AuthTokenFilter; | ||
import org.springframework.boot.CommandLineRunner; | ||
|
@@ -28,7 +20,6 @@ | |
import org.springframework.security.web.csrf.CookieCsrfTokenRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
|
@@ -60,59 +51,16 @@ SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http, AuthEntryPoint | |
} | ||
|
||
@Bean | ||
public CommandLineRunner initData(RoleRepository roleRepository, UserRepository userRepository, PasswordEncoder passwordEncoder, PrivacySettingRepository privacySettingRepository, GenderRepository genderRepository) { | ||
public CommandLineRunner initData(UserAuthServiceFacade userAuthServiceFacade) { | ||
return args -> { | ||
Role userRole = roleRepository.findByCode(Roles.ROLE_USER.name()) | ||
.orElseGet(() -> roleRepository.save(new Role(Roles.ROLE_USER))); | ||
Role adminRole = roleRepository.findByCode(Roles.ROLE_ADMIN.name()) | ||
.orElseGet(() -> roleRepository.save(new Role(Roles.ROLE_ADMIN))); | ||
|
||
PrivacySetting publicSetting = privacySettingRepository.findByCode(PrivacySettings.PUBLIC.name()) | ||
.orElseGet(() -> privacySettingRepository.save(new PrivacySetting(PrivacySettings.PUBLIC))); | ||
|
||
Gender female = genderRepository.findByCode(Genders.FEMALE.name()) | ||
.orElseGet(() -> genderRepository.save(new Gender(Genders.FEMALE))); | ||
|
||
if (!userRepository.existsByLogin("user1")) { | ||
User user1 = new User(); | ||
user1.setLogin("user1"); | ||
user1.setPassword(passwordEncoder.encode("password1")); | ||
user1.setEmail("[email protected]"); | ||
user1.setName("Jan"); | ||
user1.setSurname("Kos"); | ||
user1.setSalt("salt"); | ||
user1.setAccountNonLocked(false); | ||
user1.setBirthdate(LocalDate.of(1990, 1, 1)); | ||
user1.setCredentialsNonExpired(true); | ||
user1.setCredentialsExpiryDate(LocalDateTime.now().plusYears(1)); | ||
user1.setRole(userRole); | ||
user1.setPostsPrivacy(publicSetting); | ||
user1.setFriendsPrivacy(publicSetting); | ||
user1.setProfilePrivacy(publicSetting); | ||
user1.setGender(female); | ||
userRepository.save(user1); | ||
if (!userAuthServiceFacade.existsByLogin("user1")) { | ||
userAuthServiceFacade.createUser("user1", "Gustaw", "Jeleń", "[email protected]", "userPass", LocalDate.of(1970, 10, 14), Roles.ROLE_USER, Genders.MALE); | ||
} | ||
|
||
if (!userRepository.existsByLogin("admin")) { | ||
User admin = new User(); | ||
admin.setLogin("admin"); | ||
admin.setPassword(passwordEncoder.encode("adminPass")); | ||
admin.setEmail("[email protected]"); | ||
admin.setName("Gustaw"); | ||
admin.setSurname("Jeleń"); | ||
admin.setSalt("salt"); | ||
admin.setAccountNonLocked(false); | ||
admin.setBirthdate(LocalDate.of(1980, 1, 1)); | ||
admin.setCredentialsNonExpired(true); | ||
admin.setCredentialsExpiryDate(LocalDateTime.now().plusYears(1)); | ||
admin.setRole(adminRole); | ||
admin.setPostsPrivacy(publicSetting); | ||
admin.setFriendsPrivacy(publicSetting); | ||
admin.setProfilePrivacy(publicSetting); | ||
admin.setGender(female); | ||
userRepository.save(admin); | ||
} | ||
if (!userAuthServiceFacade.existsByLogin("admin")) { | ||
userAuthServiceFacade.createUser("admin", "Jan", "Kos", "[email protected]", "adminPass", LocalDate.of(1979, 12, 11), Roles.ROLE_ADMIN, Genders.MALE); | ||
|
||
} | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/meowhub/backend/users/facades/UserAdminServiceFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package meowhub.backend.users.facades; | ||
|
||
import meowhub.backend.dtos.UserDto; | ||
|
||
import java.util.List; | ||
|
||
public interface UserAdminServiceFacade { | ||
void changeUserRole(String userId, String roleName); | ||
|
||
List<UserDto> getAllUsers(); | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/meowhub/backend/users/facades/UserAuthServiceFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package meowhub.backend.users.facades; | ||
|
||
import meowhub.backend.constants.Genders; | ||
import meowhub.backend.constants.Roles; | ||
import meowhub.backend.users.models.User; | ||
|
||
import java.time.LocalDate; | ||
|
||
public interface UserAuthServiceFacade { | ||
User createUser(String login, String name, String surname, String email, String password, LocalDate birthdate, Roles role, Genders gender); | ||
|
||
boolean existsByLogin(String login); | ||
|
||
boolean existsByEmail(String email); | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/meowhub/backend/users/facades/UserPostServiceFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package meowhub.backend.users.facades; | ||
|
||
import meowhub.backend.users.dtos.BasicUserInfoDto; | ||
import meowhub.backend.users.models.User; | ||
|
||
public interface UserPostServiceFacade { | ||
void validateIfUserExists(String login); | ||
|
||
User findUserByLogin(String login); | ||
|
||
BasicUserInfoDto getBasicUserInfo(String login); | ||
} |
Oops, something went wrong.