Example usage for org.springframework.security.oauth2.common.exceptions UnauthorizedUserException UnauthorizedUserException

List of usage examples for org.springframework.security.oauth2.common.exceptions UnauthorizedUserException UnauthorizedUserException

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.common.exceptions UnauthorizedUserException UnauthorizedUserException.

Prototype

public UnauthorizedUserException(String msg) 

Source Link

Usage

From source file:org.openbaton.nfvo.core.api.NetworkServiceRecordManagement.java

@Override
public NetworkServiceRecord update(NetworkServiceRecord newRsr, String idNsr, String projectId)
        throws NotFoundException {
    NetworkServiceRecord networkServiceRecord = nsrRepository.findFirstById(idNsr);
    if (networkServiceRecord != null) {
        if (!networkServiceRecord.getProjectId().equals(projectId)) {
            throw new UnauthorizedUserException(
                    "NSD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
        }//www. j ava 2s .c o  m
    } else {
        throw new NotFoundException("NetworkServiceRecord with id not found");
    }
    newRsr = nsrRepository.save(newRsr);
    return newRsr;
}

From source file:org.openbaton.nfvo.core.api.NetworkServiceRecordManagement.java

@Override
public void executeAction(NFVMessage nfvMessage, String nsrId, String idVnf, String idVdu, String idVNFCI,
        String projectId) throws NotFoundException {

    log.info("Executing action: " + nfvMessage.getAction() + " on VNF with id: " + idVnf);

    NetworkServiceRecord networkServiceRecord = nsrRepository.findFirstById(nsrId);
    if (!networkServiceRecord.getProjectId().equals(projectId)) {
        throw new UnauthorizedUserException(
                "NSR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
    }/* ww  w.j  a  v a  2 s.  c om*/
    VirtualNetworkFunctionRecord virtualNetworkFunctionRecord = 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 :)");
    }
    VirtualDeploymentUnit virtualDeploymentUnit = getVirtualDeploymentUnit(idVdu, virtualNetworkFunctionRecord);
    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 :)");
    }
    VNFCInstance vnfcInstance = getVNFCInstance(idVNFCI, virtualDeploymentUnit);
    switch (nfvMessage.getAction()) {
    case HEAL:
        // Note: when we get a HEAL message from the API, it contains only the cause (no vnfr or vnfcInstance).
        // Here the vnfr and the vnfcInstance are set into the message, since they are updated.
        VnfmOrHealedMessage VnfmOrHealVNFRequestMessage = (VnfmOrHealedMessage) nfvMessage;
        log.debug("Received Heal message: " + VnfmOrHealVNFRequestMessage);
        VnfmOrHealVNFRequestMessage.setVirtualNetworkFunctionRecord(virtualNetworkFunctionRecord);
        VnfmOrHealVNFRequestMessage.setVnfcInstance(vnfcInstance);
        vnfmManager.sendMessageToVNFR(virtualNetworkFunctionRecord, VnfmOrHealVNFRequestMessage);
        break;
    }
}

From source file:org.openbaton.nfvo.core.api.NetworkServiceRecordManagement.java

@Override
public NetworkServiceRecord query(String id, String projectId) {
    log.debug("Id is: " + id);
    NetworkServiceRecord networkServiceRecord = nsrRepository.findFirstById(id);
    log.trace("found nsr = " + networkServiceRecord);
    log.debug(" project id is: " + projectId);
    if (!networkServiceRecord.getProjectId().equals(projectId)) {
        throw new UnauthorizedUserException(
                "NSD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
    }//from ww w .j a  v  a  2 s. c om
    return networkServiceRecord;
}

From source file:org.openbaton.nfvo.core.api.NetworkServiceRecordManagement.java

@Override
public void delete(String id, String projectId) throws NotFoundException, WrongStatusException {
    log.info("Removing NSR with id: " + id);
    NetworkServiceRecord networkServiceRecord = nsrRepository.findFirstById(id);
    if (!networkServiceRecord.getProjectId().equals(projectId)) {
        throw new UnauthorizedUserException(
                "NSD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
    }//ww  w.  j  av a  2  s  .com
    if (networkServiceRecord == null) {
        throw new NotFoundException("NetworkServiceRecord with id " + id + " was not found");
    }

    if (!deleteInAllStatus) {
        if (networkServiceRecord.getStatus().ordinal() == Status.NULL.ordinal()) {
            throw new WrongStatusException("The NetworkService " + networkServiceRecord.getId()
                    + " is in the wrong state. ( Status= " + networkServiceRecord.getStatus() + " )");
        }
        if (networkServiceRecord.getStatus().ordinal() != Status.ACTIVE.ordinal()
                && networkServiceRecord.getStatus().ordinal() != Status.ERROR.ordinal()) {
            throw new WrongStatusException("The NetworkService " + networkServiceRecord.getId()
                    + " is in the wrong state. ( Status= " + networkServiceRecord.getStatus() + " )");
        }
    }

    if (!networkServiceRecord.getVnfr().isEmpty()) {
        networkServiceRecord.setStatus(Status.TERMINATED); // TODO maybe terminating?
        for (VirtualNetworkFunctionRecord virtualNetworkFunctionRecord : networkServiceRecord.getVnfr()) {
            if (removeAfterTimeout) {
                VNFRTerminator terminator = new VNFRTerminator();
                terminator.setVirtualNetworkFunctionRecord(virtualNetworkFunctionRecord);
                this.asyncExecutor.submit(terminator);
            }
            vnfmManager.release(virtualNetworkFunctionRecord);
        }
    } else {
        nsrRepository.delete(networkServiceRecord.getId());
    }
}

From source file:org.openbaton.nfvo.core.api.VNFPackageManagement.java

@Override
public VNFPackage update(String id, VNFPackage pack_new, String projectId) {
    VNFPackage old = vnfPackageRepository.findFirstById(id);
    if (!old.getProjectId().equals(projectId)) {
        throw new UnauthorizedUserException(
                "VNFPackage not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
    }//w  ww  .  j  a v  a 2 s .  com
    old.setName(pack_new.getName());
    old.setImage(pack_new.getImage());
    return old;
}

From source file:org.openbaton.nfvo.core.api.VNFPackageManagement.java

@Override
public VNFPackage query(String id, String projectId) {
    VNFPackage vnfPackage = vnfPackageRepository.findFirstById(id);
    if (!vnfPackage.getProjectId().equals(projectId)) {
        throw new UnauthorizedUserException(
                "VNFPackage not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
    }/*  w  w w.  j ava2  s.c  o m*/
    return vnfPackage;
}

From source file:org.openbaton.nfvo.core.api.VNFPackageManagement.java

@Override
public void delete(String id, String projectId) throws WrongAction {
    log.info("Removing VNFPackage: " + id);
    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.");
    }//w w  w . j  a  va  2  s .com
    //TODO remove image in the VIM
    Iterable<VirtualNetworkFunctionDescriptor> virtualNetworkFunctionDescriptors = vnfdRepository.findAll();
    for (VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor : virtualNetworkFunctionDescriptors) {
        if (virtualNetworkFunctionDescriptor.getVnfPackageLocation() == null) {
            log.trace("VNFPackageLocation not defined for VNFD " + virtualNetworkFunctionDescriptor.getId());
        } else if (virtualNetworkFunctionDescriptor.getVnfPackageLocation().equals(id)) {
            log.trace("VNFPackageLocation references VNFD " + virtualNetworkFunctionDescriptor.getId());
            if (cascadeDelete) {
                log.debug("VNFD " + virtualNetworkFunctionDescriptor.getId() + " will be removed");
            } else {
                log.debug("VNFD " + virtualNetworkFunctionDescriptor.getId() + " will not be removed");
            }
            //        throw new WrongAction(
            //            "It is not possible to remove the vnfPackage with id "
            //                + id
            //                + ", a VNFD referencing it is still onboarded");
        }
    }
    if (cascadeDelete) {
        for (VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor : virtualNetworkFunctionDescriptors) {
            if (virtualNetworkFunctionDescriptor.getVnfPackageLocation() != null) {
                if (virtualNetworkFunctionDescriptor.getVnfPackageLocation().equals(id)) {
                    if (!vnfdBelongsToNSD(virtualNetworkFunctionDescriptor)) {
                        log.info("Removing VNFDescriptor: " + virtualNetworkFunctionDescriptor.getName());
                        vnfdRepository.delete(virtualNetworkFunctionDescriptor.getId());
                        break;
                    } else {
                        throw new WrongAction(
                                "It is not possible to remove a vnfPackage --> vnfdescriptor if the NSD is still onboarded");
                    }
                }
            }
        }
    }
    vnfPackageRepository.delete(id);
}

From source file:org.opentestsystem.delivery.testreg.service.impl.ExternalStudentServiceImpl.java

private String validateStudent(Student student, StudentSecurity studentSecurity, String stateCode) {
    if (student.getStateAbbreviation().compareTo(stateCode) != 0)
        throw new UnauthorizedUserException("Attempted to modify student in state: "
                + student.getStateAbbreviation() + " endpoint received " + stateCode);
    String error = "";
    List<FieldError> errors = fileUploadSecurityValidator.validateStudent(student, studentSecurity);
    if (errors.size() != 0) {
        for (FieldError fieldError : errors) {
            error += fieldError.getDefaultMessage() + "\n";
        }/*from  ww w  .ja v  a  2s  .  c o  m*/
    }
    return error;
}