Search in sources :

Example 21 with WormholeRequestException

use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.

the class AuthController method readUserByName.

// Read a user by user name
@RequestMapping(value = "/user/username/{name}", method = RequestMethod.GET)
public WormholeUser readUserByName(@PathVariable(required = false) String name, HttpServletRequest request) {
    WormholeUserDetails userDetail = accessTokenService.getCurrentUser(request);
    Optional<WormholeUser> currentUserOptional = userRepository.findById(userDetail.getUserId());
    WormholeUser user = null;
    WormholeUser currentUser = currentUserOptional.get();
    if (currentUser.getRoleNames().contains(FlowgateConstant.Role_admin)) {
        user = userRepository.findOneByUserName(name);
    } else if (currentUser.getUserName().equals(name)) {
        user = currentUser;
    } else {
        throw new WormholeRequestException(HttpStatus.FORBIDDEN, "Forbidden", null);
    }
    if (user != null) {
        return DesensitizationUserData.desensitizationUser(user);
    }
    return user;
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with WormholeRequestException

use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.

the class FacilitySoftwareController method createServer.

// create a new facilitySoftwareConfig
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void createServer(@RequestBody FacilitySoftwareConfig config, HttpServletRequest request) {
    HandleURL handleURL = new HandleURL();
    config.setServerURL(handleURL.formatURL(config.getServerURL()));
    if (repository.findOneByServerURL(config.getServerURL()) != null) {
        String message = String.format("The server %s is already exsit.", config.getServerURL());
        throw new WormholeRequestException(message);
    }
    serverValidationService.validateFacilityServer(config);
    IntegrationStatus integrationStatus = new IntegrationStatus();
    integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
    integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
    config.setIntegrationStatus(integrationStatus);
    WormholeUserDetails user = accessTokenService.getCurrentUser(request);
    config.setUserId(user.getUserId());
    encryptServerPassword(config);
    BaseDocumentUtil.generateID(config);
    repository.save(config);
    decryptServerPassword(config);
    notifyFacilityWorker(config);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) HandleURL(com.vmware.flowgate.util.HandleURL) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with WormholeRequestException

use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.

the class JobsController method startFullMappingAggregation.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/mergeservermapping", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void startFullMappingAggregation() {
    try {
        EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.FullMappingCommand, "");
        String message = EventMessageUtil.convertEventMessageAsString(eventMessage);
        publisher.publish(EventMessageUtil.AggregatorTopic, message);
    } catch (IOException e) {
        log.error("Failed to create event message", e);
        throw new WormholeRequestException("Failed to create event message");
    }
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with WormholeRequestException

use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.

the class SDDCSoftwareController method queryServer.

@RequestMapping(value = "/page/{pageNumber}/pagesize/{pageSize}", method = RequestMethod.GET)
public Page<SDDCSoftwareConfig> queryServer(@PathVariable("pageNumber") int currentPage, @PathVariable("pageSize") int pageSize, HttpServletRequest request) {
    if (currentPage < FlowgateConstant.defaultPageNumber) {
        currentPage = FlowgateConstant.defaultPageNumber;
    } else if (pageSize <= 0) {
        pageSize = FlowgateConstant.defaultPageSize;
    } else if (pageSize > FlowgateConstant.maxPageSize) {
        pageSize = FlowgateConstant.maxPageSize;
    }
    PageRequest pageRequest = PageRequest.of(currentPage - 1, pageSize);
    WormholeUserDetails user = accessTokenService.getCurrentUser(request);
    try {
        Page<SDDCSoftwareConfig> result = sddcRepository.findAllByUserId(user.getUserId(), pageRequest);
        for (SDDCSoftwareConfig sddcSoftwareConfig : result.getContent()) {
            sddcSoftwareConfig.setPassword(null);
        }
        return result;
    } catch (Exception e) {
        throw new WormholeRequestException(e.getMessage());
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) PageRequest(org.springframework.data.domain.PageRequest) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchElementException(java.util.NoSuchElementException) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) IOException(java.io.IOException) WormholeException(com.vmware.flowgate.common.exception.WormholeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with WormholeRequestException

use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.

the class AccessTokenService method getCurrentUser.

public WormholeUserDetails getCurrentUser(HttpServletRequest request) {
    String token = getToken(request);
    if (token == null && !InitializeConfigureData.unauthirzedURLs.containsKey(request.getRequestURI())) {
        logger.error("Get current user failed,please check the token." + request.getRequestURI());
        return null;
    }
    String userJson = null;
    try {
        userJson = getUserJsonString(token);
    } catch (WormholeRequestException e) {
        return null;
    }
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
    WormholeUserDetails user = null;
    try {
        user = mapper.readValue(userJson, WormholeUserDetails.class);
    } catch (IOException e) {
        logger.error("Get current user failed," + e.getMessage());
    }
    return user;
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)14 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)9 IOException (java.io.IOException)9 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)4 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)4 AuthToken (com.vmware.flowgate.common.model.AuthToken)3 FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)3 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)3 WormholeException (com.vmware.flowgate.common.exception.WormholeException)2 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)2 Asset (com.vmware.flowgate.common.model.Asset)2 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Date (java.util.Date)2 NoSuchElementException (java.util.NoSuchElementException)2 Optional (java.util.Optional)2 Cookie (javax.servlet.http.Cookie)2