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.NetworkServiceDescriptorManagement.java

/**
 * Add or Update the PhysicalNetworkFunctionDescriptor into NSD
 *
 * @param pDescriptor/* w  ww . ja  v  a  2  s  .  co  m*/
 * @param idNsd
 * @param projectId
 * @return PhysicalNetworkFunctionDescriptor
 */
@Override
public PhysicalNetworkFunctionDescriptor addPnfDescriptor(PhysicalNetworkFunctionDescriptor pDescriptor,
        String idNsd, String projectId) {
    if (nsdRepository.findFirstById(idNsd).getProjectId().equals(projectId)) {
        return nsdRepository.addPnfDescriptor(pDescriptor, idNsd);
    }
    throw new UnauthorizedUserException(
            "NSD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
}

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

/**
 * Adds or Updates the Security into NSD
 *
 * @param id//from  ww w  .  j a  va  2s.  c  om
 * @param security
 * @param projectId
 * @return Security
 */
@Override
public Security addSecurity(String id, Security security, String projectId) {
    if (nsdRepository.findFirstById(id).getProjectId().equals(projectId)) {
        return nsdRepository.addSecurity(id, security);
    }
    throw new UnauthorizedUserException(
            "NSD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
}

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

/**
 * Removes the Secuty with idS from NSD with id
 *
 * @param idNsd//ww  w .  ja v  a  2  s  . co  m
 * @param idS
 * @param projectId
 */
@Override
public void deleteSecurty(String idNsd, String idS, String projectId) {
    if (nsdRepository.findFirstById(idNsd).getProjectId().equals(projectId)) {
        nsdRepository.deleteSecurity(idNsd, idS);
    }
    throw new UnauthorizedUserException(
            "NSD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
}

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

/**
 * This operation is used to query the information of the Network Service Descriptor (NSD),
 * including any related VNFFGD and VLD.
 *//*from  w w w .j a  v  a  2  s .  c o m*/
@Override
public NetworkServiceDescriptor query(String id, String projectId) throws NoResultException {
    NetworkServiceDescriptor networkServiceDescriptor = nsdRepository.findFirstById(id);
    if (networkServiceDescriptor.getProjectId().equals(projectId))
        return networkServiceDescriptor;
    throw new UnauthorizedUserException(
            "NSD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
}

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

@Override
public void deleteVNFCInstance(String id, String idVnf, String projectId) throws NotFoundException,
        WrongStatusException, InterruptedException, ExecutionException, VimException, PluginException {
    log.info("Removing VNFCInstance from VNFR with id: " + idVnf);
    NetworkServiceRecord networkServiceRecord = getNetworkServiceRecordInActiveState(id);
    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 :)");
    }/*  w w  w  . j av a  2 s .  c  o m*/
    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 = null;

    for (VirtualDeploymentUnit vdu : virtualNetworkFunctionRecord.getVdu()) {
        if (vdu.getProjectId() != null && vdu.getProjectId().equals(projectId)) {
            virtualDeploymentUnit = vdu;
            break;
        }
    }

    if (virtualDeploymentUnit == null) {
        throw new NotFoundException("No VirtualDeploymentUnit found");
    }

    if (virtualDeploymentUnit.getVnfc_instance().size() == 1) {
        throw new WrongStatusException(
                "The VirtualDeploymentUnit chosen has reached the minimum number of VNFCInstance");
    }

    VNFCInstance vnfcInstance = virtualDeploymentUnit.getVnfc_instance().iterator().next();
    if (vnfcInstance == null) {
        throw new NotFoundException("No VNFCInstance was found");
    }

    networkServiceRecord.setStatus(Status.SCALING);
    networkServiceRecord = nsrRepository.save(networkServiceRecord);
    scaleIn(networkServiceRecord, virtualNetworkFunctionRecord, virtualDeploymentUnit, vnfcInstance);
}

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

/**
 * This operation is used to remove a disabled Network Service Descriptor.
 *
 * @param id//from w  w w.ja v  a2s  . co m
 */
@Override
public void delete(String id, String projectId) throws WrongStatusException {
    log.info("Removing NetworkServiceDescriptor with id " + id);
    NetworkServiceDescriptor networkServiceDescriptor = nsdRepository.findFirstById(id);
    if (!networkServiceDescriptor.getProjectId().equals(projectId))
        throw new UnauthorizedUserException(
                "NSD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");

    for (NetworkServiceRecord nsr : nsrRepository.findAll()) {
        if (nsr.getDescriptor_reference().equals(id)) {
            if (nsr.getStatus().ordinal() != Status.ACTIVE.ordinal()) {
                throw new WrongStatusException("The NetworkServiceRecord " + nsr.getName()
                        + " created from the NetworkServiceDescriptor " + networkServiceDescriptor.getName()
                        + " is not yet in ACTIVE");
            }
        }
    }

    nsdRepository.delete(networkServiceDescriptor);
    if (cascadeDelete) {
        for (VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor : networkServiceDescriptor
                .getVnfd()) {
            virtualNetworkFunctionManagement.delete(virtualNetworkFunctionDescriptor.getId(), projectId);
        }
    }
}

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

@Override
public void deleteVNFCInstance(String id, String idVnf, String idVdu, String projectId)
        throws NotFoundException, WrongStatusException, InterruptedException, ExecutionException, VimException,
        PluginException {// ww w  .jav  a  2 s .com
    log.info("Removing VNFCInstance from VNFR with id: " + idVnf + " in vdu: " + idVdu);
    NetworkServiceRecord networkServiceRecord = getNetworkServiceRecordInActiveState(id);
    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 :)");
    }
    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 = null;

    for (VirtualDeploymentUnit vdu : virtualNetworkFunctionRecord.getVdu()) {
        if (vdu.getId().equals(idVdu) && vdu.getProjectId() != null && vdu.getProjectId().equals(projectId)) {
            virtualDeploymentUnit = vdu;
        }
    }

    if (virtualDeploymentUnit == null) {
        throw new NotFoundException("No VirtualDeploymentUnit found");
    }

    if (virtualDeploymentUnit.getVnfc_instance().size() == 1) {
        throw new WrongStatusException(
                "The VirtualDeploymentUnit chosen has reached the minimum number of VNFCInstance");
    }

    VNFCInstance vnfcInstance = virtualDeploymentUnit.getVnfc_instance().iterator().next();
    if (vnfcInstance == null) {
        throw new NotFoundException("No VNFCInstance was not found");
    }

    networkServiceRecord.setStatus(Status.SCALING);
    networkServiceRecord = nsrRepository.save(networkServiceRecord);
    scaleIn(networkServiceRecord, virtualNetworkFunctionRecord, virtualDeploymentUnit, vnfcInstance);
}

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

@Override
public void deleteVNFCInstance(String id, String idVnf, String idVdu, String idVNFCI, String projectId)
        throws NotFoundException, WrongStatusException, InterruptedException, ExecutionException, VimException,
        PluginException {/*from  w w w.  j  a va  2 s  .  c o m*/
    log.info(
            "Removing VNFCInstance with id: " + idVNFCI + " from VNFR with id: " + idVnf + " in vdu: " + idVdu);
    NetworkServiceRecord networkServiceRecord = getNetworkServiceRecordInActiveState(id);
    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 :)");
    }
    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 :)");
    }
    if (virtualDeploymentUnit.getVnfc_instance().size() == 1) {

        throw new WrongStatusException(
                "The VirtualDeploymentUnit chosen has reached the minimum number of VNFCInstance");
    }

    networkServiceRecord.setStatus(Status.SCALING);
    networkServiceRecord = nsrRepository.save(networkServiceRecord);
    scaleIn(networkServiceRecord, virtualNetworkFunctionRecord, virtualDeploymentUnit,
            getVNFCI(virtualDeploymentUnit, idVNFCI));
}

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

@Override
public void switchToRedundantVNFCInstance(String id, String idVnf, String idVdu, String idVNFC, String mode,
        VNFCInstance failedVnfcInstance, String projectId) throws NotFoundException, WrongStatusException {
    NetworkServiceRecord networkServiceRecord = getNetworkServiceRecordInActiveState(id);
    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 :)");
    }/*from w ww . ja  v a 2s .  com*/
    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 standByVNFCInstance = null;
    for (VNFCInstance vnfcInstance : virtualDeploymentUnit.getVnfc_instance()) {
        log.debug("current vnfcinstance " + vnfcInstance + " in state" + vnfcInstance.getState());
        if (vnfcInstance.getState() != null && vnfcInstance.getState().equals(mode)) {
            standByVNFCInstance = vnfcInstance;
            log.debug("VNFComponentInstance in " + mode + " mode FOUND :" + standByVNFCInstance);
        }
        if (vnfcInstance.getId().equals(failedVnfcInstance.getId())) {
            vnfcInstance.setState("failed");
            log.debug("The vnfcInstance: " + vnfcInstance.getHostname() + " is set to '"
                    + vnfcInstance.getState() + "' state");
        }
    }
    if (standByVNFCInstance == null) {
        throw new NotFoundException("No VNFCInstance in " + mode
                + " mode found, so switch to redundant VNFC is not " + "possibile");
    }

    //save the new state of the failedVnfcInstance
    nsrRepository.save(networkServiceRecord);

    OrVnfmHealVNFRequestMessage healMessage = new OrVnfmHealVNFRequestMessage();
    healMessage.setAction(Action.HEAL);
    healMessage.setVirtualNetworkFunctionRecord(virtualNetworkFunctionRecord);
    healMessage.setVnfcInstance(standByVNFCInstance);
    healMessage.setCause("switchToStandby");

    vnfmManager.sendMessageToVNFR(virtualNetworkFunctionRecord, healMessage);
}