Skip to content
This repository has been archived by the owner on Mar 25, 2018. It is now read-only.

Transfered Abdulwahaab710 commit #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import org.apache.commons.lang3.ArrayUtils;

import javax.servlet.http.HttpSession;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand All @@ -34,8 +36,11 @@ public class MessageController {

@RequestMapping(value = "/sendMessage", method = RequestMethod.POST)
public Message sendMessage(@RequestBody Message message, @CookieValue("SESSION") String cookie) {
checkAccess(new ActionDto(message.getRecipient()), cookie);
return messageRepository.save(message);
if (check_rank(authentication.getName(), message.getRecipient()) {
checkAccess(new ActionDto(message.getRecipient()), cookie);
return messageRepository.save(message);
}
return null;
}

@RequestMapping(value = "/messages", method = RequestMethod.GET)
Expand Down Expand Up @@ -63,4 +68,10 @@ private void checkAccess(ActionDto actionDto, String session) {
restTemplate.postForObject(url, entity, String.class);
}

private boolean check_rank(String send_rank, String recipient_rank) {
String[] ranks = {"crewman", "ensign", "lieutenant", "commander", "captain", "vice_admiral", "admiral"};
int rank = ArrayUtils.indexOf(ranks, send_rank.toLowerCase());
return ArrayUtils.indexOf(ranks, send_rank) <= ArrayUtils.indexOf(ranks, recipient_rank.toLowerCase());
}

}
2 changes: 1 addition & 1 deletion config-server/config/zuul-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spring:
application.name: zuul-server

server:
port: ${PORT:9090}
port: ${PORT:3000}

eureka.client.region: default
eureka.client.registryFetchIntervalSeconds: 5
Expand Down