Search in sources :

Example 16 with WormholeRequestException

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

the class SDDCSoftwareController method getVROServerConfigsByUser.

// get servers by user
// Confuse, if we only filter out vrops why not set the type field?
@RequestMapping(value = "/user/vrops", method = RequestMethod.GET)
public List<SDDCSoftwareConfig> getVROServerConfigsByUser(HttpServletRequest request) {
    SDDCSoftwareConfig example = new SDDCSoftwareConfig();
    example.setUserId(getCurrentUserID(request));
    List<SDDCSoftwareConfig> datas = sddcRepository.findAllByUserId(getCurrentUserID(request));
    if (datas.isEmpty()) {
        throw new WormholeRequestException("The result is empty");
    }
    decryptServerListPassword(datas);
    return datas;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with WormholeRequestException

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

the class AssetController method updateServerMapping.

// Update serverMapping
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/mapping", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateServerMapping(@RequestBody ServerMapping serverMaping) {
    Optional<ServerMapping> mappingOptional = serverMappingRepository.findById(serverMaping.getId());
    if (!mappingOptional.isPresent()) {
        throw WormholeRequestException.NotFound("ServerMapping", "id", serverMaping.getId());
    }
    ServerMapping mapping = mappingOptional.get();
    try {
        mapping.setAsset(serverMaping.getAsset());
        serverMappingRepository.save(mapping);
    } catch (Exception e) {
        throw new WormholeRequestException("Failed to update the ServerMapping", e);
    }
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) IOException(java.io.IOException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with WormholeRequestException

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

the class AssetController method update.

// Update
@ResponseStatus(HttpStatus.OK)
@RequestMapping(method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void update(@RequestBody Asset asset) {
    Optional<Asset> oldAssetOptional = assetRepository.findById(asset.getId());
    if (!oldAssetOptional.isPresent()) {
        throw WormholeRequestException.NotFound("Asset", "id", asset.getId());
    }
    Asset oldAsset = oldAssetOptional.get();
    try {
        BaseDocumentUtil.applyChanges(oldAsset, asset);
    } catch (Exception e) {
        throw new WormholeRequestException("Failed to update the Asset", e);
    }
    oldAsset.setLastupdate(System.currentTimeMillis());
    assetRepository.save(oldAsset);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) Asset(com.vmware.flowgate.common.model.Asset) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) IOException(java.io.IOException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with WormholeRequestException

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

the class AuthController method updateUser.

// Update a user
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/user", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateUser(@RequestBody WormholeUser user, HttpServletRequest request) {
    WormholeUserDetails userDetail = accessTokenService.getCurrentUser(request);
    Optional<WormholeUser> currentUserOptional = userRepository.findById(userDetail.getUserId());
    WormholeUser currentUser = currentUserOptional.get();
    WormholeUser old = null;
    if (currentUser.getUserName().equals(user.getUserName())) {
        old = currentUser;
    } else if (currentUser.getRoleNames().contains(FlowgateConstant.Role_admin)) {
        Optional<WormholeUser> oldUserOptional = userRepository.findById(user.getId());
        old = oldUserOptional.get();
    } else {
        throw new WormholeRequestException(HttpStatus.FORBIDDEN, "Forbidden", null);
    }
    if (old == null) {
        throw new WormholeRequestException(HttpStatus.NOT_FOUND, "User not found", null);
    }
    if (user.getPassword() != null && !"".equals(user.getPassword().trim())) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        old.setPassword(encoder.encode(user.getPassword()));
        old.setLastPasswordResetDate(new Date().getTime());
    }
    if (user.getEmailAddress() != null && !"".equals(user.getEmailAddress().trim())) {
        old.setEmailAddress(user.getEmailAddress());
    }
    if (user.getRoleNames() != null) {
        old.setRoleNames(user.getRoleNames());
    }
    userRepository.save(old);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) Optional(java.util.Optional) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Date(java.util.Date) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with WormholeRequestException

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

the class AuthController method createUser.

// Create a new user
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/user", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void createUser(@RequestBody WormholeUser user, HttpServletResponse response) {
    if (userRepository.findOneByUserName(user.getUserName()) != null) {
        String message = user.getUserName() + "is already exsit";
        throw new WormholeRequestException(message);
    }
    user.setCreateTime(new Date());
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    user.setPassword(encoder.encode(user.getPassword().trim()));
    user.setLastPasswordResetDate(new Date().getTime());
    BaseDocumentUtil.generateID(user);
    userRepository.save(user);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) Date(java.util.Date) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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