Skip to content
Snippets Groups Projects
Commit 95b9857b authored by kbeyro's avatar kbeyro
Browse files

Merge branch 'release/1.6.5' into 228-prevent-users-from-adding-an-existing-ssh-key

parents 63268e34 bd788d4c
No related branches found
No related tags found
1 merge request!65Resolve "Prevent users from adding an existing SSH key"
Pipeline #91262 failed
Showing
with 244 additions and 41 deletions
...@@ -12,6 +12,18 @@ test: ...@@ -12,6 +12,18 @@ test:
- chmod +x ./gradlew - chmod +x ./gradlew
- ./gradlew -Dorg.gradle.daemon=false test - ./gradlew -Dorg.gradle.daemon=false test
itest:
stage: test
image: openjdk:11-jdk-slim
tags:
- docker
only:
- develop
- /^release/
script:
- chmod +x ./gradlew
- ./gradlew integrationTest jacocoTestCoverageVerification
sonar: sonar:
stage: sonar stage: sonar
image: openjdk:17-jdk-slim image: openjdk:17-jdk-slim
......
...@@ -149,7 +149,7 @@ public class SSOAuthControllerIntTest extends BaseControllerTestSetup { ...@@ -149,7 +149,7 @@ public class SSOAuthControllerIntTest extends BaseControllerTestSetup {
private void addLanguage(){ private void addLanguage(){
if(!intService.getEnabledLanguages().contains("en")) { if(!intService.getEnabledLanguages().contains("en")) {
intService.addNewLanguage(new InternationalizationView("en", true, "{\"content\":\"content\"}")); intService.addNewLanguage(new InternationalizationView("en", true, "{\"content\":\"content\"}"), false);
} }
} }
......
package net.geant.nmaas.portal.api.configuration;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.cache.CacheManager;
import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.context.annotation.Bean;
@TestConfiguration
public class TestCacheConfig {
@Bean
public CacheManager cacheManager() {
return new NoOpCacheManager();
}
}
...@@ -15,6 +15,7 @@ import net.geant.nmaas.orchestration.entities.AppAccessMethod; ...@@ -15,6 +15,7 @@ import net.geant.nmaas.orchestration.entities.AppAccessMethod;
import net.geant.nmaas.orchestration.entities.AppDeploymentSpec; import net.geant.nmaas.orchestration.entities.AppDeploymentSpec;
import net.geant.nmaas.orchestration.entities.AppStorageVolume; import net.geant.nmaas.orchestration.entities.AppStorageVolume;
import net.geant.nmaas.portal.api.BaseControllerTestSetup; import net.geant.nmaas.portal.api.BaseControllerTestSetup;
import net.geant.nmaas.portal.api.configuration.TestCacheConfig;
import net.geant.nmaas.portal.api.domain.AppAccessMethodView; import net.geant.nmaas.portal.api.domain.AppAccessMethodView;
import net.geant.nmaas.portal.api.domain.AppConfigurationSpecView; import net.geant.nmaas.portal.api.domain.AppConfigurationSpecView;
import net.geant.nmaas.portal.api.domain.AppDeploymentSpecView; import net.geant.nmaas.portal.api.domain.AppDeploymentSpecView;
...@@ -44,6 +45,8 @@ import org.junit.jupiter.api.Test; ...@@ -44,6 +45,8 @@ import org.junit.jupiter.api.Test;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
...@@ -65,8 +68,9 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder ...@@ -65,8 +68,9 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest @SpringBootTest(properties = "spring.cache.type=none")
@Log4j2 @Log4j2
@Import(TestCacheConfig.class)
class ApplicationControllerIntTest extends BaseControllerTestSetup { class ApplicationControllerIntTest extends BaseControllerTestSetup {
@Autowired @Autowired
...@@ -130,8 +134,8 @@ class ApplicationControllerIntTest extends BaseControllerTestSetup { ...@@ -130,8 +134,8 @@ class ApplicationControllerIntTest extends BaseControllerTestSetup {
} }
@Test @Test
@CacheEvict(value = "applicationBaseS", allEntries = true)
void shouldGetActiveApplications() throws Exception { void shouldGetActiveApplications() throws Exception {
log.debug("Test = {} {}", this.applicationBaseRepository.findAll().size(), this.applicationBaseRepository.findAllSmall().size());
MvcResult result = mvc.perform(get("/api/apps/base") MvcResult result = mvc.perform(get("/api/apps/base")
.header("Authorization", "Bearer " + getValidTokenForUser(UsersHelper.ADMIN)) .header("Authorization", "Bearer " + getValidTokenForUser(UsersHelper.ADMIN))
.accept(MediaType.APPLICATION_JSON)) .accept(MediaType.APPLICATION_JSON))
......
...@@ -80,7 +80,7 @@ public class BulkDomainServiceIntTest { ...@@ -80,7 +80,7 @@ public class BulkDomainServiceIntTest {
List<BulkDeployment> bulkDeployments = bulkDeploymentRepository.findAll(); List<BulkDeployment> bulkDeployments = bulkDeploymentRepository.findAll();
assertEquals(1, bulkDeployments.size()); assertEquals(1, bulkDeployments.size());
BulkDeployment bulkDeployment = bulkDeployments.get(0); BulkDeployment bulkDeployment = bulkDeployments.get(0);
assertEquals(1, bulkDeployment.getCreatorId()); assertEquals(1, bulkDeployment.getCreator().getId());
assertEquals(BulkType.DOMAIN, bulkDeployment.getType()); assertEquals(BulkType.DOMAIN, bulkDeployment.getType());
assertEquals(6, bulkDeployment.getEntries().size()); assertEquals(6, bulkDeployment.getEntries().size());
assertThat(userRepository.findByEmail("user1@test.com").orElseThrow().getSamlToken()).isEqualTo("user1@test.com"); assertThat(userRepository.findByEmail("user1@test.com").orElseThrow().getSamlToken()).isEqualTo("user1@test.com");
...@@ -105,7 +105,7 @@ public class BulkDomainServiceIntTest { ...@@ -105,7 +105,7 @@ public class BulkDomainServiceIntTest {
List<BulkDeployment> bulkDeployments = bulkDeploymentRepository.findAll(); List<BulkDeployment> bulkDeployments = bulkDeploymentRepository.findAll();
assertEquals(1, bulkDeployments.size()); assertEquals(1, bulkDeployments.size());
BulkDeployment bulkDeployment = bulkDeployments.get(0); BulkDeployment bulkDeployment = bulkDeployments.get(0);
assertEquals(1, bulkDeployment.getCreatorId()); assertEquals(1, bulkDeployment.getCreator().getId());
assertEquals(BulkType.DOMAIN, bulkDeployment.getType()); assertEquals(BulkType.DOMAIN, bulkDeployment.getType());
assertEquals(4, bulkDeployment.getEntries().size()); assertEquals(4, bulkDeployment.getEntries().size());
assertThat(userRepository.findByEmail("user1@test.com").orElseThrow().getSamlToken()).isNull(); assertThat(userRepository.findByEmail("user1@test.com").orElseThrow().getSamlToken()).isNull();
...@@ -128,7 +128,7 @@ public class BulkDomainServiceIntTest { ...@@ -128,7 +128,7 @@ public class BulkDomainServiceIntTest {
List<BulkDeployment> bulkDeployments = bulkDeploymentRepository.findAll(); List<BulkDeployment> bulkDeployments = bulkDeploymentRepository.findAll();
assertEquals(1, bulkDeployments.size()); assertEquals(1, bulkDeployments.size());
BulkDeployment bulkDeployment = bulkDeployments.get(0); BulkDeployment bulkDeployment = bulkDeployments.get(0);
assertEquals(1, bulkDeployment.getCreatorId()); assertEquals(1, bulkDeployment.getCreator().getId());
assertEquals(BulkType.DOMAIN, bulkDeployment.getType()); assertEquals(BulkType.DOMAIN, bulkDeployment.getType());
assertEquals(6, bulkDeployment.getEntries().size()); assertEquals(6, bulkDeployment.getEntries().size());
assertEquals("testdomain10", bulkDeployment.getEntries().get(0).getDetails().get("domainCodename")); assertEquals("testdomain10", bulkDeployment.getEntries().get(0).getDetails().get("domainCodename"));
......
...@@ -161,3 +161,5 @@ portal.config.sendAppInstanceFailureEmails=false ...@@ -161,3 +161,5 @@ portal.config.sendAppInstanceFailureEmails=false
portal.config.showDomainRegistrationSelector=true portal.config.showDomainRegistrationSelector=true
# string - list of emails with ':' as a separator, e.g., admin1@nmaas.eu;admin2@nmaas.eu # string - list of emails with ':' as a separator, e.g., admin1@nmaas.eu;admin2@nmaas.eu
portal.config.appInstanceFailureEmailList=admin@nmaas.eu portal.config.appInstanceFailureEmailList=admin@nmaas.eu
spring.cache.type=none
...@@ -2,6 +2,7 @@ package net.geant.nmaas; ...@@ -2,6 +2,7 @@ package net.geant.nmaas;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.event.ApplicationEventMulticaster; import org.springframework.context.event.ApplicationEventMulticaster;
...@@ -14,6 +15,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; ...@@ -14,6 +15,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@SpringBootApplication @SpringBootApplication
@EnableScheduling @EnableScheduling
@EnableAspectJAutoProxy @EnableAspectJAutoProxy
@EnableCaching
public class MainConfig { public class MainConfig {
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -2,9 +2,12 @@ package net.geant.nmaas.notifications.templates; ...@@ -2,9 +2,12 @@ package net.geant.nmaas.notifications.templates;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.geant.nmaas.notifications.templates.api.MailTemplateView; import net.geant.nmaas.notifications.templates.api.MailTemplateView;
import net.geant.nmaas.portal.exceptions.ConfigurationNotFoundException;
import net.geant.nmaas.portal.exceptions.DataConflictException;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -69,4 +72,10 @@ public class TemplateController { ...@@ -69,4 +72,10 @@ public class TemplateController {
public void updateHtmlTemplate(@RequestBody MultipartFile file){ public void updateHtmlTemplate(@RequestBody MultipartFile file){
this.templateService.updateHTMLTemplate(file); this.templateService.updateHTMLTemplate(file);
} }
@ExceptionHandler(DataConflictException.class)
@ResponseStatus(code = HttpStatus.CONFLICT)
public String handleDataConfigException(DataConflictException e){
return e.getMessage();
}
} }
...@@ -7,6 +7,7 @@ import net.geant.nmaas.notifications.templates.api.MailTemplateView; ...@@ -7,6 +7,7 @@ import net.geant.nmaas.notifications.templates.api.MailTemplateView;
import net.geant.nmaas.notifications.templates.entities.LanguageMailContent; import net.geant.nmaas.notifications.templates.entities.LanguageMailContent;
import net.geant.nmaas.notifications.templates.entities.MailTemplate; import net.geant.nmaas.notifications.templates.entities.MailTemplate;
import net.geant.nmaas.notifications.templates.repository.MailTemplateRepository; import net.geant.nmaas.notifications.templates.repository.MailTemplateRepository;
import net.geant.nmaas.portal.exceptions.DataConflictException;
import net.geant.nmaas.portal.persistent.entity.FileInfo; import net.geant.nmaas.portal.persistent.entity.FileInfo;
import net.geant.nmaas.portal.service.impl.LocalFileStorageService; import net.geant.nmaas.portal.service.impl.LocalFileStorageService;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
...@@ -24,6 +25,7 @@ import java.util.stream.Collectors; ...@@ -24,6 +25,7 @@ import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
@Service @Service
public class TemplateService { public class TemplateService {
...@@ -53,7 +55,7 @@ public class TemplateService { ...@@ -53,7 +55,7 @@ public class TemplateService {
} }
void saveMailTemplate(MailTemplateView mailTemplate) { void saveMailTemplate(MailTemplateView mailTemplate) {
checkArgument(!repository.existsByMailType(mailTemplate.getMailType()),"Mail template already exists"); checkArgumentConflict(!repository.existsByMailType(mailTemplate.getMailType()), String.format("Mail template %s already exists", mailTemplate.getMailType().name()));
checkArgument(mailTemplate.getTemplates() != null && !mailTemplate.getTemplates().isEmpty(), "Mail template cannot be null or empty"); checkArgument(mailTemplate.getTemplates() != null && !mailTemplate.getTemplates().isEmpty(), "Mail template cannot be null or empty");
repository.save(modelMapper.map(mailTemplate, MailTemplate.class)); repository.save(modelMapper.map(mailTemplate, MailTemplate.class));
} }
...@@ -69,7 +71,7 @@ public class TemplateService { ...@@ -69,7 +71,7 @@ public class TemplateService {
void storeHTMLTemplate(MultipartFile file) { void storeHTMLTemplate(MultipartFile file) {
checkArgument(file != null && !file.isEmpty(), "HTML template cannot be null or empty"); checkArgument(file != null && !file.isEmpty(), "HTML template cannot be null or empty");
checkArgument(Objects.equals(file.getContentType(), MailTemplateElements.HTML_TYPE), "HTML template must be in html format"); checkArgument(Objects.equals(file.getContentType(), MailTemplateElements.HTML_TYPE), "HTML template must be in html format");
checkArgument(fileStorageService.getFileInfoByContentType(MailTemplateElements.HTML_TYPE).isEmpty(), "Only one HTML template is supported."); checkArgumentConflict(fileStorageService.getFileInfoByContentType(MailTemplateElements.HTML_TYPE).isEmpty(), "Only one HTML template is supported.");
fileStorageService.store(file); fileStorageService.store(file);
} }
...@@ -93,4 +95,10 @@ public class TemplateService { ...@@ -93,4 +95,10 @@ public class TemplateService {
throw new IllegalArgumentException(String.format("Exactly one html template supported (actually got %d)", template.size())); throw new IllegalArgumentException(String.format("Exactly one html template supported (actually got %d)", template.size()));
} }
private static void checkArgumentConflict(boolean expression, String errorMessage) {
if (!expression) {
throw new DataConflictException(String.valueOf(errorMessage));
}
}
} }
...@@ -4,8 +4,10 @@ import lombok.AllArgsConstructor; ...@@ -4,8 +4,10 @@ import lombok.AllArgsConstructor;
import net.geant.nmaas.notifications.types.model.FormTypeRequest; import net.geant.nmaas.notifications.types.model.FormTypeRequest;
import net.geant.nmaas.notifications.types.model.FormTypeView; import net.geant.nmaas.notifications.types.model.FormTypeView;
import net.geant.nmaas.notifications.types.service.FormTypeService; import net.geant.nmaas.notifications.types.service.FormTypeService;
import net.geant.nmaas.portal.exceptions.DataConflictException;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -35,4 +37,9 @@ public class FormTypeController { ...@@ -35,4 +37,9 @@ public class FormTypeController {
this.service.create(request); this.service.create(request);
} }
@ExceptionHandler(DataConflictException.class)
@ResponseStatus(code = HttpStatus.CONFLICT)
public String handleDataConfigException(DataConflictException e){
return e.getMessage();
}
} }
...@@ -6,6 +6,7 @@ import net.geant.nmaas.notifications.types.model.FormTypeView; ...@@ -6,6 +6,7 @@ import net.geant.nmaas.notifications.types.model.FormTypeView;
import net.geant.nmaas.notifications.types.persistence.entity.FormType; import net.geant.nmaas.notifications.types.persistence.entity.FormType;
import net.geant.nmaas.notifications.types.persistence.repository.FormTypeRepository; import net.geant.nmaas.notifications.types.persistence.repository.FormTypeRepository;
import net.geant.nmaas.portal.api.exception.ProcessingException; import net.geant.nmaas.portal.api.exception.ProcessingException;
import net.geant.nmaas.portal.exceptions.DataConflictException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
...@@ -32,7 +33,7 @@ public class FormTypeService { ...@@ -32,7 +33,7 @@ public class FormTypeService {
if(!this.typeRepository.existsById(ent.getKeyValue())) { if(!this.typeRepository.existsById(ent.getKeyValue())) {
this.typeRepository.save(ent); this.typeRepository.save(ent);
} else { } else {
throw new ProcessingException("Form type already exists"); throw new DataConflictException(String.format("Form type %s already exists", ent.getTemplateName()));
} }
} }
......
...@@ -412,12 +412,17 @@ public enum AppDeploymentState { ...@@ -412,12 +412,17 @@ public enum AppDeploymentState {
@Override @Override
public AppDeploymentState nextState(NmServiceDeploymentState state) { public AppDeploymentState nextState(NmServiceDeploymentState state) {
if (NmServiceDeploymentState.CONFIGURATION_REMOVAL_INITIATED.equals(state)) { switch (state) {
case DEPLOYMENT_FAILED:
return APPLICATION_DEPLOYMENT_FAILED;
case CONFIGURATION_REMOVAL_INITIATED:
return APPLICATION_CONFIGURATION_REMOVAL_IN_PROGRESS; return APPLICATION_CONFIGURATION_REMOVAL_IN_PROGRESS;
} default:
return nextStateForNotMatchingNmServiceDeploymentState(this, state); return nextStateForNotMatchingNmServiceDeploymentState(this, state);
} }
}
@Override @Override
public boolean isInEndState() { public boolean isInEndState() {
return true; return true;
......
...@@ -118,7 +118,7 @@ public class BulkController { ...@@ -118,7 +118,7 @@ public class BulkController {
log.info("Processing bulk application deployment details request"); log.info("Processing bulk application deployment details request");
BulkDeployment bulk = bulkDeploymentRepository.findById(id).orElseThrow(); BulkDeployment bulk = bulkDeploymentRepository.findById(id).orElseThrow();
BulkDeploymentView bulkView = modelMapper.map(bulk, BulkDeploymentView.class); BulkDeploymentView bulkView = modelMapper.map(bulk, BulkDeploymentView.class);
bulkView.setCreator(getUserView(bulk.getCreatorId())); bulkView.setCreator(getUserView(bulk.getCreator().getId()));
mapDetails(bulk, bulkView); mapDetails(bulk, bulkView);
List<BulkAppDetails> details = bulkApplicationService.getAppsBulkDetails(bulkView); List<BulkAppDetails> details = bulkApplicationService.getAppsBulkDetails(bulkView);
InputStreamResource inputStreamResource = bulkApplicationService.getInputStreamAppBulkDetails(details); InputStreamResource inputStreamResource = bulkApplicationService.getInputStreamAppBulkDetails(details);
...@@ -173,7 +173,7 @@ public class BulkController { ...@@ -173,7 +173,7 @@ public class BulkController {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
if(bulk.get().getCreatorId().equals(user.getId()) ) { if(bulk.get().getCreator().getId().equals(user.getId()) ) {
throw new PermissionDeniedDataAccessException("User doesnt have access to this bulk deployment", new Throwable()); throw new PermissionDeniedDataAccessException("User doesnt have access to this bulk deployment", new Throwable());
} }
if (removeApps) { if (removeApps) {
...@@ -204,9 +204,9 @@ public class BulkController { ...@@ -204,9 +204,9 @@ public class BulkController {
private <T extends BulkDeploymentViewS> T mapToView(BulkDeployment bulk, Class<T> viewType) { private <T extends BulkDeploymentViewS> T mapToView(BulkDeployment bulk, Class<T> viewType) {
T bulkView = modelMapper.map(bulk, viewType); T bulkView = modelMapper.map(bulk, viewType);
try { try {
bulkView.setCreator(getUserView(bulk.getCreatorId())); bulkView.setCreator(getUserView(bulk.getCreator().getId()));
} catch (Exception ex) { } catch (Exception ex) {
log.error("Can not find creator for {} - creatorId: {}", bulk.getId(), bulk.getCreatorId()); log.error("Can not find creator for {} - creatorId: {}", bulk.getId(), bulk.getCreator().getId());
return null; return null;
} }
mapDetails(bulk, bulkView); mapDetails(bulk, bulkView);
...@@ -216,14 +216,13 @@ public class BulkController { ...@@ -216,14 +216,13 @@ public class BulkController {
private BulkDeploymentView mapToView(BulkDeployment deployment) { private BulkDeploymentView mapToView(BulkDeployment deployment) {
BulkDeploymentView bulkView = modelMapper.map(deployment, BulkDeploymentView.class); BulkDeploymentView bulkView = modelMapper.map(deployment, BulkDeploymentView.class);
try { try {
bulkView.setCreator(getUserView(deployment.getCreatorId())); bulkView.setCreator(getUserView(deployment.getCreator().getId()));
} catch (Exception ex) {
log.error("Can not find creator for {} - creatorId: {}", deployment.getId(), deployment.getCreatorId());
return null; return null;
} catch (Exception ex) {
log.error("Can not find creator for {} - creatorId: {}", deployment.getId(), deployment.getCreator().getId());
} }
mapDetails(deployment, bulkView); mapDetails(deployment, bulkView);
return bulkView; return bulkView;
} }
private void mapDetails(BulkDeployment deployment, BulkDeploymentViewS view) { private void mapDetails(BulkDeployment deployment, BulkDeploymentViewS view) {
......
package net.geant.nmaas.portal.api.i18n; package net.geant.nmaas.portal.api.i18n;
import java.util.List;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import net.geant.nmaas.portal.api.i18n.api.InternationalizationBriefView; import net.geant.nmaas.portal.api.i18n.api.InternationalizationBriefView;
import net.geant.nmaas.portal.api.i18n.api.InternationalizationView; import net.geant.nmaas.portal.api.i18n.api.InternationalizationView;
import net.geant.nmaas.portal.service.InternationalizationService; import net.geant.nmaas.portal.service.InternationalizationService;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController @RestController
@AllArgsConstructor @AllArgsConstructor
...@@ -19,8 +29,10 @@ public class InternationalizationController { ...@@ -19,8 +29,10 @@ public class InternationalizationController {
@PostMapping("/{language}") @PostMapping("/{language}")
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN')") @PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN')")
@ResponseStatus(HttpStatus.ACCEPTED) @ResponseStatus(HttpStatus.ACCEPTED)
public void saveLanguageContent(@PathVariable("language") String language, @RequestParam(value = "enabled") boolean enabled, @RequestBody String content) { public void saveLanguageContent(@PathVariable("language") String language, @RequestParam(value = "enabled") boolean enabled,
this.internationalizationService.addNewLanguage(new InternationalizationView(language, enabled, content)); @RequestParam(value = "force", required = false, defaultValue = "false") Boolean force, @RequestBody String content) {
boolean isForce = force != null && force;
this.internationalizationService.addNewLanguage(new InternationalizationView(language, enabled, content), isForce);
} }
@PatchMapping("/{language}") @PatchMapping("/{language}")
......
...@@ -16,6 +16,7 @@ import net.geant.nmaas.portal.api.domain.DomainRequest; ...@@ -16,6 +16,7 @@ import net.geant.nmaas.portal.api.domain.DomainRequest;
import net.geant.nmaas.portal.api.domain.DomainView; import net.geant.nmaas.portal.api.domain.DomainView;
import net.geant.nmaas.portal.api.domain.Id; import net.geant.nmaas.portal.api.domain.Id;
import net.geant.nmaas.portal.api.domain.KeyValueView; import net.geant.nmaas.portal.api.domain.KeyValueView;
import net.geant.nmaas.portal.api.domain.UserViewMinimal;
import net.geant.nmaas.portal.api.exception.MissingElementException; import net.geant.nmaas.portal.api.exception.MissingElementException;
import net.geant.nmaas.portal.api.exception.ProcessingException; import net.geant.nmaas.portal.api.exception.ProcessingException;
import net.geant.nmaas.portal.exceptions.ObjectNotFoundException; import net.geant.nmaas.portal.exceptions.ObjectNotFoundException;
...@@ -310,6 +311,19 @@ public class DomainController extends AppBaseController { ...@@ -310,6 +311,19 @@ public class DomainController extends AppBaseController {
} }
} }
@PutMapping("/group/members/{domainGroupId}")
@Transactional
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_VL_MANAGER')")
public DomainGroupView updateDomainGroupMembers(@PathVariable Long domainGroupId, @RequestBody List<UserViewMinimal> members, Principal principal) throws AccessDeniedException {
DomainGroupView domainGroup = domainGroupService.getDomainGroup(domainGroupId);
if (getUser(principal.getName()).getRoles().stream().anyMatch(userRole -> userRole.getRole().equals(Role.ROLE_SYSTEM_ADMIN)) ||
domainGroup.getManagers().stream().anyMatch(user -> user.getUsername().equalsIgnoreCase(principal.getName()))) {
return domainService.updateMembers(members, domainGroup);
} else {
throw new AccessDeniedException("You have no access to this domain group");
}
}
@GetMapping("/annotations") @GetMapping("/annotations")
@Transactional @Transactional
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN')") @PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN')")
......
package net.geant.nmaas.portal.api.security;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import net.geant.nmaas.portal.exceptions.ObjectNotFoundException;
import net.geant.nmaas.portal.persistent.entity.AccessToken;
import net.geant.nmaas.portal.persistent.entity.User;
import net.geant.nmaas.portal.service.CustomAccessTokenService;
import net.geant.nmaas.portal.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.security.Principal;
import java.util.List;
@RestController
@RequestMapping("/api/tokens")
@RequiredArgsConstructor
@Log4j2
public class CustomAccessTokenController {
private final CustomAccessTokenService accessTokenService;
private final UserService userService;
@GetMapping()
public List<AccessToken> getAll(Principal principal) {
User user = getUser(principal);
return accessTokenService.getAll(user.getId());
}
@PostMapping()
public AccessToken createNewToken(Principal principal, @RequestBody String name) {
User user = getUser(principal);
return accessTokenService.createToken(user.getId(), name);
}
@PutMapping("/{id}")
public void invalidateToken(@PathVariable Long id) {
accessTokenService.invalidate(id);
}
private User getUser(Principal principal) {
String principalName = principal.getName();
return userService.findByUsername(principalName)
.orElseThrow(() -> new ObjectNotFoundException("User not found"));
}
}
package net.geant.nmaas.portal.exceptions;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class DataConflictException extends RuntimeException {
public DataConflictException(String message) {
super(message);
}
}
package net.geant.nmaas.portal.persistent.entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "access_tokens")
@NoArgsConstructor
@Getter
@Setter
@AllArgsConstructor
public class AccessToken {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private Long userId;
private String tokenValue;
private boolean valid;
}
...@@ -15,6 +15,8 @@ import javax.persistence.Enumerated; ...@@ -15,6 +15,8 @@ import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -32,7 +34,9 @@ public class BulkDeployment { ...@@ -32,7 +34,9 @@ public class BulkDeployment {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
private Long creatorId; @ManyToOne
@JoinColumn(name = "creator_id")
private User creator;
private OffsetDateTime creationDate; private OffsetDateTime creationDate;
......
package net.geant.nmaas.portal.persistent.repositories;
import net.geant.nmaas.portal.persistent.entity.AccessToken;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface AccessTokenRepository extends JpaRepository<AccessToken, Long> {
List<AccessToken> findAllByUserId(Long userId);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment