@Override public void changePassword(String oldPassword, String newPassword) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String currentUserName = authentication.getName(); log.debug("Changing password of user: " + currentUserName); User user = userRepository.findFirstByUsername(currentUserName); if (!BCrypt.checkpw(oldPassword, user.getPassword())) { throw new UnauthorizedUserException("Old password is wrong."); } if (!(authentication instanceof AnonymousAuthenticationToken)) { // TODO is this line needed? user.setPassword(BCrypt.hashpw(newPassword, BCrypt.gensalt(12))); userRepository.save(user); log.debug("Password of user " + currentUserName + " has been changed successfully."); } }
/** * Returns the VirtualNetworkFunctionDescriptor with the ID idVnfd from the Network Service * Descriptor with ID idNsd. * * @param idNsd of NSD * @param idVnfd of VirtualNetworkFunctionDescriptor */ @Override public VirtualNetworkFunctionDescriptor getVirtualNetworkFunctionDescriptor( String idNsd, String idVnfd, String projectId) throws NotFoundException { NetworkServiceDescriptor nsd = nsdRepository.findFirstByIdAndProjectId(idNsd, projectId); if (nsd == null) throw new NotFoundException("Did not find a Network Service Descriptor with ID " + idNsd); for (VirtualNetworkFunctionDescriptor vnfd : nsd.getVnfd()) { if (vnfd.getId().equals(idVnfd)) { if (!vnfd.getProjectId().equals(projectId)) throw new UnauthorizedUserException( "VNFD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)"); return vnfd; } } throw new NotFoundException( "The NSD with ID " + idNsd + " does not contain a VNFD with ID " + idVnfd); }
getVirtualNetworkFunctionRecord(idVnf, networkServiceRecord); if (!virtualNetworkFunctionRecord.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VNFR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
getVirtualNetworkFunctionRecord(idVnf, networkServiceRecord); if (!virtualNetworkFunctionRecord.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VNFR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)"); if (virtualDeploymentUnit.getProjectId() != null && !virtualDeploymentUnit.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VDU not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
getVirtualNetworkFunctionRecord(idVnf, networkServiceRecord); if (!virtualNetworkFunctionRecord.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VNFR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
VNFPackage vnfPackage = vnfPackageRepository.findFirstById(id); if (vnfPackage == null || !vnfPackage.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "Not found VNFPackage " + id + ". Either not existing or not under the project chosen.");
getVirtualNetworkFunctionRecord(idVnf, networkServiceRecord); if (!virtualNetworkFunctionRecord.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VNFR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)"); if (virtualDeploymentUnit.getProjectId() != null && !virtualDeploymentUnit.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VDU not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
getVirtualNetworkFunctionRecord(idVnf, networkServiceRecord); if (!virtualNetworkFunctionRecord.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VNFR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
getVirtualNetworkFunctionRecord(idVnf, networkServiceRecord); if (!virtualNetworkFunctionRecord.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VNFR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)"); if (virtualDeploymentUnit.getProjectId() != null && !virtualDeploymentUnit.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VDU not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
getVirtualNetworkFunctionRecord(idVnf, networkServiceRecord); if (!virtualNetworkFunctionRecord.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VNFR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)"); if (virtualDeploymentUnit.getProjectId() != null && !virtualDeploymentUnit.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VDU not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
public void deleteVNFRecord(String idNsr, String idVnf, String projectId) throws NotFoundException { // TODO the logic of this request for the moment deletes only the VNFR from the DB, need to be // removed from the // running NetworkServiceRecord VirtualNetworkFunctionRecord vnfr = vnfrRepository.findOne(idVnf); if (vnfr == null) { throw new NotFoundException("Not found VNFR with ID: " + idVnf); } if (!vnfr.getParent_ns_id().equals(idNsr)) { throw new NotFoundException("Not found VNFR " + idVnf + " in the given NSR " + idNsr); } if (!vnfr.getProjectId().equals(projectId)) { throw new UnauthorizedUserException("VNFR not contained in the chosen project."); } nsrRepository.deleteVNFRecord(idNsr, idVnf); NetworkServiceRecord nsr = query(idNsr, projectId); if (nsr != null) { for (VirtualNetworkFunctionRecord virtualNetworkFunctionRecord : nsr.getVnfr()) { if (nsr.getStatus().ordinal() > virtualNetworkFunctionRecord.getStatus().ordinal()) { nsr.setStatus(vnfr.getStatus()); } } nsrRepository.saveCascade(nsr); } else { log.warn("Parent NS does not exist anymore..."); } }
getVirtualNetworkFunctionRecord(idVnf, networkServiceRecord); if (!virtualNetworkFunctionRecord.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "VNFR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)"); if (virtualDeploymentUnit.getProjectId() != null && !virtualDeploymentUnit.getProjectId().equals(projectId)) { throw new UnauthorizedUserException( "NSD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");