-
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 #9 from ONAV-KEA/7-create-edit-delete-employees
#7 create edit delete employees
- Loading branch information
Showing
8 changed files
with
129 additions
and
50 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
5 changes: 1 addition & 4 deletions
5
src/main/java/dk/kea/onav2ndproject_rest/repository/UserRepository.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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
package dk.kea.onav2ndproject_rest.repository; | ||
|
||
import dk.kea.onav2ndproject_rest.dto.UserDTO; | ||
import dk.kea.onav2ndproject_rest.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface UserRepository extends JpaRepository<User,Long> { | ||
public interface UserRepository extends JpaRepository<User,Integer> { | ||
List<User> findByUsername(String name); | ||
//List<User> findUserByPasswordContains(String passwordPart); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/dk/kea/onav2ndproject_rest/service/AuthenticationService.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,42 @@ | ||
package dk.kea.onav2ndproject_rest.service; | ||
|
||
import dk.kea.onav2ndproject_rest.entity.User; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class AuthenticationService { | ||
@Autowired | ||
private UserService userService; | ||
|
||
public int getCurrentUserId() { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails) { | ||
UserDetails userDetails = (UserDetails) authentication.getPrincipal(); | ||
String username = userDetails.getUsername(); | ||
List<User> users = userService.findByName(username); | ||
if (!users.isEmpty()) { | ||
return users.get(0).getId(); | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
public User getCurrentUser() { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails) { | ||
UserDetails userDetails = (UserDetails) authentication.getPrincipal(); | ||
String username = userDetails.getUsername(); | ||
List<User> users = userService.findByName(username); | ||
if (!users.isEmpty()) { | ||
return users.get(0); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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