Search in sources :

Example 1 with ModuleDescriptor

use of eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor in project CzechIdMng by bcvsolutions.

the class DefaultModuleServiceUnitTest method init.

@Before
public void init() {
    PluginRegistry<ModuleDescriptor, String> registry = SimplePluginRegistry.create(Lists.newArrayList(new ModuleDescriptorOne(), new ModuleDescriptorTwo()));
    defaultModuleService = new DefaultModuleService(registry, configurationService);
}
Also used : ModuleDescriptor(eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor) AbstractModuleDescriptor(eu.bcvsolutions.idm.core.api.domain.AbstractModuleDescriptor) DefaultModuleService(eu.bcvsolutions.idm.core.model.service.impl.DefaultModuleService) Before(org.junit.Before)

Example 2 with ModuleDescriptor

use of eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor in project CzechIdMng by bcvsolutions.

the class DefaultModuleService method setEnabled.

@Override
public void setEnabled(String moduleId, boolean enabled) {
    ModuleDescriptor moduleDescriptor = moduleDescriptorRegistry.getPluginFor(moduleId);
    ModuleDescriptorDto moduleDescriptorDto = null;
    if (moduleDescriptor == null) {
        LOG.info("Frontend module [{}] will be enabled [{}].", moduleId, enabled);
        // FE module - create basic descriptor
        moduleDescriptorDto = new ModuleDescriptorDto(moduleId);
        moduleDescriptorDto.setDisableable(true);
        moduleDescriptorDto.setDisabled(!configurationService.getBooleanValue(getModuleConfigurationProperty(moduleId, ConfigurationService.PROPERTY_ENABLED), false));
    } else {
        LOG.info("Backend module [{}] will be enabled [{}].", moduleId, enabled);
        // 
        moduleDescriptorDto = toDto(moduleDescriptor);
    }
    // 
    ModuleDescriptorEvent event = new ModuleDescriptorEvent(enabled ? ModuleDescriptorEventType.ENABLE : ModuleDescriptorEventType.DISABLE, moduleDescriptorDto);
    entityEventManager.process(event);
}
Also used : ModuleDescriptor(eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor) ModuleDescriptorEvent(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto)

Example 3 with ModuleDescriptor

use of eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor in project CzechIdMng by bcvsolutions.

the class ModuleController method put.

/**
 * Supports enable / disable only
 *
 * @param moduleId
 * @param nativeRequest
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{moduleId}", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.MODULE_UPDATE + "')")
@ApiOperation(value = "Update module properties", nickname = "putModule", tags = { ModuleController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_UPDATE, description = "") }) }, notes = "Supports enable / disable only")
public ModuleDescriptorDto put(@ApiParam(value = "Module's identifier.", required = true) @PathVariable @NotNull String moduleId, HttpServletRequest nativeRequest) {
    ModuleDescriptor updatedModuleDescriptor = moduleService.getModule(moduleId);
    if (updatedModuleDescriptor == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", moduleId));
    }
    ModuleDescriptorDto md = (ModuleDescriptorDto) requestResourceResolver.resolve(nativeRequest, ModuleDescriptorDto.class, null);
    moduleService.setEnabled(moduleId, !md.isDisabled());
    return get(moduleId);
}
Also used : ModuleDescriptor(eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ModuleDescriptor

use of eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor in project CzechIdMng by bcvsolutions.

the class ModuleController method put.

/**
 * Supports enable / disable only
 *
 * @param moduleId
 * @param nativeRequest
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{moduleId}", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.MODULE_UPDATE + "')")
@ApiOperation(value = "Update module properties", nickname = "putModule", tags = { ModuleController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_UPDATE, description = "") }) }, notes = "Supports enable / disable only")
public ModuleDescriptorDto put(@ApiParam(value = "Module's identifier.", required = true) @PathVariable @NotNull String moduleId, @Valid @RequestBody ModuleDescriptorDto dto) {
    ModuleDescriptor updatedModuleDescriptor = moduleService.getModule(moduleId);
    if (updatedModuleDescriptor == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", moduleId));
    }
    // 
    moduleService.setEnabled(moduleId, !dto.isDisabled());
    return get(moduleId);
}
Also used : ModuleDescriptor(eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ModuleDescriptor

use of eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor in project CzechIdMng by bcvsolutions.

the class ModuleController method patch.

/**
 * Supports enable / disable only
 *
 * @param moduleId
 * @param nativeRequest
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{moduleId}", method = RequestMethod.PATCH)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.MODULE_UPDATE + "')")
@ApiOperation(value = "Update module properties", nickname = "patchModule", tags = { ModuleController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_UPDATE, description = "") }) }, notes = "Supports enable / disable only")
public ModuleDescriptorDto patch(@ApiParam(value = "Module's identifier.", required = true) @PathVariable @NotNull String moduleId, HttpServletRequest nativeRequest) {
    ModuleDescriptor updatedModuleDescriptor = moduleService.getModule(moduleId);
    if (updatedModuleDescriptor == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", moduleId));
    }
    // 
    ServletServerHttpRequest request = new ServletServerHttpRequest(nativeRequest);
    try {
        ModuleDescriptorDto dto = objectMapper.readValue(request.getBody(), ModuleDescriptorDto.class);
        moduleService.setEnabled(moduleId, !dto.isDisabled());
    } catch (IOException ex) {
        throw new ResultCodeException(CoreResultCode.BAD_REQUEST, ex);
    }
    // 
    return get(moduleId);
}
Also used : ModuleDescriptor(eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) IOException(java.io.IOException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ModuleDescriptor (eu.bcvsolutions.idm.core.api.domain.ModuleDescriptor)5 ModuleDescriptorDto (eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 AbstractModuleDescriptor (eu.bcvsolutions.idm.core.api.domain.AbstractModuleDescriptor)1 ModuleDescriptorEvent (eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent)1 DefaultModuleService (eu.bcvsolutions.idm.core.model.service.impl.DefaultModuleService)1 IOException (java.io.IOException)1 Before (org.junit.Before)1 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)1