Skip to content

Commit

Permalink
https://jira.fingo.info/browse/IJ-318 Prepare frontend for no-auth (#201
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DaDudek authored Jan 9, 2023
1 parent 149fd74 commit 1283092
Show file tree
Hide file tree
Showing 86 changed files with 713 additions and 286 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ out
clone_guide
/urlopia.log
application-developer.properties
.env
.env-local
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:16-jdk
FROM openjdk:17-jdk
ENV TZ=Europe/Warsaw

COPY build/libs/urlopia-*.jar /urlopia.jar
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ spring.flyway.enabled= (boolean flag - self explaining)
urlopia.flyway.baseline-version= (version of the last script that was run on db)

# active directory
ad.configuration.enabled=true (if false ad won't be used as data provider)
ldap.initial.context.factory=com.sun.jndi.ldap.LdapCtxFactory
ldap.security.authentication=Simple (Authentication with username and password)
ldap.security.principal= (Active directory username)
Expand Down Expand Up @@ -233,6 +234,14 @@ where
Example script name: `V2_7_6_1__add_count_for_next_year_column.sql`.
## Application without Active Directory
Urlopia has option to be run without AD. You can configure it by setting `ad.configuration.enabled = false` properties.
If this option is choose synchronization won't be run and all data will be got from database.
In this mode there is no need to define any of Active Directory properties.
If there is need to use frontend in this configuration, frontend should be build in no-auth mode [check details](view.react/README.md#no-auth-mode)


#### Slack bot configuration

To create a slack app:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.fingo.urlopia.acceptance;

import info.fingo.urlopia.config.authentication.UserIdInterceptor;
import info.fingo.urlopia.config.authentication.oauth.OAuthUserIdInterceptor;
import info.fingo.urlopia.config.persistance.filter.Filter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -37,7 +37,7 @@ public ResponseEntity<Page<AcceptanceExcerptProjection>> getForLeader(@PathVaria
@PostMapping(path = "/acceptances/{acceptanceId}/accept", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> accept(@PathVariable Long acceptanceId,
HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
acceptanceService.accept(acceptanceId, authenticatedId);
return ResponseEntity.ok().build();
}
Expand All @@ -46,7 +46,7 @@ public ResponseEntity<Void> accept(@PathVariable Long acceptanceId,
@PostMapping(path = "/acceptances/{acceptanceId}/reject", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> reject(@PathVariable Long acceptanceId,
HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
acceptanceService.reject(acceptanceId, authenticatedId);
return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import info.fingo.urlopia.acceptance.AcceptanceExcerptProjection;
import info.fingo.urlopia.acceptance.AcceptanceService;
import info.fingo.urlopia.api.v2.exceptions.InvalidActionException;
import info.fingo.urlopia.config.authentication.UserIdInterceptor;
import info.fingo.urlopia.config.authentication.oauth.OAuthUserIdInterceptor;
import info.fingo.urlopia.config.persistance.filter.Filter;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -36,7 +36,7 @@ public AbsenceRequestAcceptanceControllerV2(AcceptanceService acceptanceService)
public Page<AcceptancesOutput> getAcceptances(@RequestParam(name = "filter", defaultValue = "") String[] filters,
Pageable pageable,
HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var filter = Filter.from(filters);
var acceptances = acceptanceService.get(authenticatedId, filter, pageable);

Expand All @@ -48,7 +48,7 @@ public Page<AcceptancesOutput> getAcceptances(@RequestParam(name = "filter", def
public Page<AcceptanceHistoryOutput> getAcceptancesHistory(@RequestParam(name = "filter", defaultValue = "") String[] filters,
Pageable pageable,
HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var filter = Filter.from(filters);
return acceptanceService.getHistory(authenticatedId, filter, pageable);
}
Expand All @@ -58,7 +58,7 @@ public Page<AcceptanceHistoryOutput> getAcceptancesHistory(@RequestParam(name =
public AcceptanceStatus updateAcceptanceStatus(@PathVariable Long acceptanceId,
@RequestBody AcceptanceStatus status,
HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);

switch (status.status()) {
case ACCEPTED -> acceptanceService.accept(acceptanceId, authenticatedId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package info.fingo.urlopia.api.v2.authentication.noauth;

import info.fingo.urlopia.api.v2.authentication.oauth.OAuthRedirectService;
import info.fingo.urlopia.api.v2.user.UserOutput;
import info.fingo.urlopia.config.authentication.UserData;
import info.fingo.urlopia.config.persistance.filter.Filter;
import info.fingo.urlopia.history.HistoryLogService;
import info.fingo.urlopia.user.UserExcerptProjection;
import info.fingo.urlopia.user.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

import javax.annotation.security.RolesAllowed;
import java.util.List;

@RestController
@RequestMapping(value = "/api/v2/noauth/session")
Expand All @@ -25,8 +19,6 @@ public class NoAuthSessionController {

private final OAuthRedirectService oAuthRedirectService;
private final HistoryLogService historyLogService;
private final UserService userService;

@RolesAllowed({"ROLES_ADMIN", "ROLES_LEADER", "ROLES_WORKER"})
@GetMapping()
public UserData getUserData(Long userId) {
Expand All @@ -35,15 +27,4 @@ public UserData getUserData(Long userId) {
userData.setEmploymentYear(userEmploymentYear);
return userData;
}

public List<UserOutput> getAll(Sort sort) {
var users = userService.get(Filter.empty(), sort);
return mapUserProjectionListToUserOutputList(users);
}

private List<UserOutput> mapUserProjectionListToUserOutputList(List<UserExcerptProjection> users){
return users.stream()
.map(UserOutput::fromUserExcerptProjection)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.fingo.urlopia.api.v2.authentication.oauth;

import info.fingo.urlopia.config.authentication.UserData;
import info.fingo.urlopia.config.authentication.UserIdInterceptor;
import info.fingo.urlopia.config.authentication.oauth.OAuthUserIdInterceptor;
import info.fingo.urlopia.history.HistoryLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -22,7 +22,7 @@ public class OAuthRedirectController {
@RolesAllowed({"ROLES_ADMIN", "ROLES_LEADER", "ROLES_WORKER"})
@GetMapping()
public UserData getAuthenticatedUserData(HttpServletRequest httpRequest){
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var userData = oAuthRedirectService.getUserData(authenticatedId);

var userEmploymentYear = historyLogService.getEmploymentYear(authenticatedId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import info.fingo.urlopia.api.v2.calendar.unspecifiedabsence.UnspecifiedAbsenceOutput;
import info.fingo.urlopia.api.v2.calendar.unspecifiedabsence.UnspecifiedAbsenceService;
import info.fingo.urlopia.config.authentication.UserIdInterceptor;
import info.fingo.urlopia.config.authentication.oauth.OAuthUserIdInterceptor;
import info.fingo.urlopia.config.persistance.filter.Filter;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
Expand All @@ -26,7 +26,7 @@ public CalendarOutput getCalendarInformation(@RequestParam("startDate") @DateTim
@RequestParam("endDate") @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate endDate,
@RequestParam(name = "filter", defaultValue = "") String[] filters,
HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var filter = Filter.from(filters);
return calendarService.getCalendarInfo(authenticatedId, startDate, endDate, filter);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.fingo.urlopia.api.v2.history;

import info.fingo.urlopia.config.authentication.UserIdInterceptor;
import info.fingo.urlopia.config.authentication.oauth.OAuthUserIdInterceptor;
import info.fingo.urlopia.config.persistance.filter.Filter;
import info.fingo.urlopia.history.HistoryLogService;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -30,7 +30,7 @@ public Page<HistoryLogOutput> getHistoryLogs(
@RequestParam(name = "filter", defaultValue = "") String[] filters,
Pageable pageable) {

var authenticatedUserId = (Long) request.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedUserId = (Long) request.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var filter = Filter.from(filters);
var historyLogsPage = historyLogService.get(authenticatedUserId, year, filter, pageable);
return historyLogsPage.map(HistoryLogOutput::from);
Expand Down Expand Up @@ -71,4 +71,10 @@ public HistoryLogOutput addNewDetailsChangeEvent(@RequestBody DetailsChangeEvent
return HistoryLogOutput.from(historyLog);
}

@RolesAllowed({"ROLES_WORKER", "ROLES_LEADER", "ROLES_ADMIN"})
@GetMapping(value = "/employment-year/{userId}",produces = MediaType.APPLICATION_JSON_VALUE)
public Integer getEmploymentYear(@PathVariable Long userId) {
return historyLogService.getEmploymentYear(userId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import info.fingo.urlopia.api.v2.preferences.working.hours.UserWorkingHoursPreference;
import info.fingo.urlopia.api.v2.preferences.working.hours.UserWorkingHoursPreferenceDTO;
import info.fingo.urlopia.config.authentication.UserIdInterceptor;
import info.fingo.urlopia.config.authentication.oauth.OAuthUserIdInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -22,7 +22,7 @@ public class UserPreferencesControllerV2 {
@RolesAllowed({"ROLES_WORKER", "ROLES_ADMIN"})
@GetMapping(path = "/working-hours", produces = MediaType.APPLICATION_JSON_VALUE)
public Map<Long, UserWorkingHoursPreferenceDTO> getUserWorkingHoursPreference(HttpServletRequest httpRequest) {
var authenticatedUserId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedUserId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var preferences = userPreferencesService.getWorkingHoursPreference(authenticatedUserId);
return mapPreferencesToOutput(preferences);
}
Expand All @@ -38,7 +38,7 @@ private Map<Long, UserWorkingHoursPreferenceDTO> mapPreferencesToOutput(Map<Long
@ResponseStatus(HttpStatus.CREATED)
public UserWorkingHoursPreferenceDTO changeUserWorkingHoursPreference(@RequestBody UserWorkingHoursPreferenceDTO dto,
HttpServletRequest httpRequest) {
var authenticatedUserId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedUserId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
return userPreferencesService.changeWorkingHoursPreference(authenticatedUserId, dto);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.fingo.urlopia.api.v2.presence;

import info.fingo.urlopia.config.authentication.UserIdInterceptor;
import info.fingo.urlopia.config.authentication.oauth.OAuthUserIdInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -20,7 +20,7 @@ public class PresenceConfirmationControllerV2 {
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public List<PresenceConfirmationInputOutput> getPresenceConfirmations(
@RequestParam(name = "filter", defaultValue = "") String[] filters, HttpServletRequest httpRequest) {
var authenticatedUserId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedUserId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var presenceConfirmations = presenceConfirmationService.getPresenceConfirmations(authenticatedUserId, filters);
return PresenceConfirmationInputOutput.listFrom(presenceConfirmations);
}
Expand All @@ -30,7 +30,7 @@ public List<PresenceConfirmationInputOutput> getPresenceConfirmations(
@ResponseStatus(HttpStatus.CREATED)
public PresenceConfirmationInputOutput savePresenceConfirmation(
@RequestBody PresenceConfirmationInputOutput inputDto, HttpServletRequest httpRequest) {
var authenticatedUserId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedUserId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var addedPresenceConfirmation = presenceConfirmationService.confirmPresence(authenticatedUserId, inputDto);
return PresenceConfirmationInputOutput.from(addedPresenceConfirmation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import info.fingo.urlopia.acceptance.AcceptanceService;
import info.fingo.urlopia.api.v2.exceptions.InvalidActionException;
import info.fingo.urlopia.config.authentication.UserIdInterceptor;
import info.fingo.urlopia.config.authentication.oauth.OAuthUserIdInterceptor;
import info.fingo.urlopia.config.persistance.filter.Filter;
import info.fingo.urlopia.request.RequestInput;
import info.fingo.urlopia.request.RequestService;
Expand Down Expand Up @@ -42,7 +42,7 @@ public RequestsOutput createSpecialAbsence(@RequestBody SpecialAbsence specialAb
@ResponseStatus(HttpStatus.CREATED)
public RequestsOutput create(@RequestBody RequestInput input,
HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var request = requestService.create(authenticatedId, input);
request = requestService.getById(request.getId());
var acceptances = acceptanceService.getAcceptancesByRequestId(request.getId());
Expand All @@ -54,7 +54,7 @@ public RequestsOutput create(@RequestBody RequestInput input,
public Page<RequestsOutput> getMyRequests(@RequestParam(name = "filter", defaultValue = "") String[] filters,
Pageable pageable,
HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var filter = Filter.from(filters);
var requestsPage = requestService.getFromUser(authenticatedId, filter, pageable);
return requestsPage.map(RequestsOutput::fromRequestExcerptProjection);
Expand All @@ -74,7 +74,7 @@ public Page<RequestsOutput> getAllRequests(@RequestParam(name = "filter", defaul
public RequestStatus updateAbsenceRequestStatus(@PathVariable Long requestId,
@RequestBody RequestStatus status,
HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);

switch (status.status()) {
case CANCELED -> requestService.cancel(requestId, authenticatedId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.fingo.urlopia.api.v2.user;

import info.fingo.urlopia.config.authentication.UserIdInterceptor;
import info.fingo.urlopia.config.authentication.oauth.OAuthUserIdInterceptor;
import info.fingo.urlopia.config.persistance.filter.Filter;
import info.fingo.urlopia.history.HistoryLogInput;
import info.fingo.urlopia.history.HistoryLogService;
Expand Down Expand Up @@ -40,14 +40,14 @@ public List<UserOutput> getAll(
@RolesAllowed("ROLES_WORKER")
@GetMapping(path = "/me/pending-days", produces = MediaType.APPLICATION_JSON_VALUE)
public PendingDaysOutput getPendingDays(HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
return normalRequestService.getPendingRequestsTimeV2(authenticatedId);
}

@RolesAllowed("ROLES_WORKER")
@GetMapping(value = "/me/vacation-days", produces = MediaType.APPLICATION_JSON_VALUE)
public VacationDaysOutput getRemainingDays(HttpServletRequest httpRequest) {
var authenticatedId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
var remainingDaysInfo = historyLogService.countRemainingDays(authenticatedId);
return VacationDaysOutput.fromWorkTimeResponse(remainingDaysInfo);
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public VacationDaysOutput getVacationDays(@PathVariable Long userId){
public VacationDaysOutput addVacationHours(@PathVariable Long userId,
@RequestBody HistoryLogInput historyLog,
HttpServletRequest httpRequest) {
var authenticatedUserId = (Long) httpRequest.getAttribute(UserIdInterceptor.USER_ID_ATTRIBUTE);
var authenticatedUserId = (Long) httpRequest.getAttribute(OAuthUserIdInterceptor.USER_ID_ATTRIBUTE);
historyLogService.create(historyLog, userId, authenticatedUserId);
return getVacationDays(userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import info.fingo.urlopia.config.authentication.LDAPConnectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty(name = "ad.configuration.enabled", havingValue = "true", matchIfMissing = true)
public class ActiveDirectory {
private final LDAPConnectionService ldapConnectionService;

Expand Down
Loading

0 comments on commit 1283092

Please sign in to comment.