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;
}
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);
}
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");
}
}
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());
}
}
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;
}
Aggregations