Search in sources :

Example 1 with VpnUser

use of com.cloud.legacymodel.network.VpnUser in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElementTest method testApplyVpnUsers.

@Test
public void testApplyVpnUsers() {
    vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr;
    final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class);
    final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class);
    networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology);
    networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology);
    networkTopologyContext.init();
    final Vpc vpc = Mockito.mock(Vpc.class);
    final Zone zone = Mockito.mock(Zone.class);
    final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class);
    final DomainRouterVO domainRouterVO1 = Mockito.mock(DomainRouterVO.class);
    final DomainRouterVO domainRouterVO2 = Mockito.mock(DomainRouterVO.class);
    final VpnUser vpnUser1 = Mockito.mock(VpnUser.class);
    final VpnUser vpnUser2 = Mockito.mock(VpnUser.class);
    final List<VpnUser> users = new ArrayList<>();
    users.add(vpnUser1);
    users.add(vpnUser2);
    final List<DomainRouterVO> routers = new ArrayList<>();
    routers.add(domainRouterVO1);
    routers.add(domainRouterVO2);
    final Long vpcId = new Long(1l);
    final Long zoneId = new Long(1l);
    when(remoteAccessVpn.getVpcId()).thenReturn(vpcId);
    when(_vpcRouterMgr.getVpcRouters(vpcId)).thenReturn(routers);
    when(_entityMgr.findById(Vpc.class, vpcId)).thenReturn(vpc);
    when(vpc.getZoneId()).thenReturn(zoneId);
    when(zoneRepository.findById(zoneId)).thenReturn(Optional.of(zone));
    when(networkTopologyContext.retrieveNetworkTopology(zone)).thenReturn(advancedNetworkTopology);
    try {
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO1)).thenReturn(new String[] { "user1", "user2" });
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO2)).thenReturn(new String[] { "user3", "user4" });
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    try {
        final String[] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn, users);
        assertNotNull(results);
        assertEquals(results[0], "user1");
        assertEquals(results[1], "user2");
        assertEquals(results[2], "user3");
        assertEquals(results[3], "user4");
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    verify(remoteAccessVpn, times(1)).getVpcId();
    verify(vpc, times(1)).getZoneId();
    verify(zoneRepository, times(1)).findById(zoneId);
    verify(networkTopologyContext, times(1)).retrieveNetworkTopology(zone);
}
Also used : BasicNetworkTopology(com.cloud.network.topology.BasicNetworkTopology) Zone(com.cloud.db.model.Zone) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ArrayList(java.util.ArrayList) AdvancedNetworkTopology(com.cloud.network.topology.AdvancedNetworkTopology) VpnUser(com.cloud.legacymodel.network.VpnUser) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 2 with VpnUser

use of com.cloud.legacymodel.network.VpnUser in project cosmic by MissionCriticalCloud.

the class AddVpnUserCmd method create.

@Override
public void create() {
    final Account owner = _accountService.getAccount(getEntityOwnerId());
    final VpnUser vpnUser = _ravService.addVpnUser(owner.getId(), userName, password);
    if (vpnUser == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user");
    }
    setEntityId(vpnUser.getId());
    setEntityUuid(vpnUser.getUuid());
}
Also used : Account(com.cloud.legacymodel.user.Account) VpnUser(com.cloud.legacymodel.network.VpnUser) ServerApiException(com.cloud.api.ServerApiException)

Example 3 with VpnUser

use of com.cloud.legacymodel.network.VpnUser in project cosmic by MissionCriticalCloud.

the class AddVpnUserCmd method execute.

@Override
public void execute() {
    final VpnUser vpnUser = _entityMgr.findById(VpnUser.class, getEntityId());
    final Account account = _entityMgr.findById(Account.class, vpnUser.getAccountId());
    if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user");
    }
    final VpnUsersResponse vpnResponse = new VpnUsersResponse();
    vpnResponse.setId(vpnUser.getUuid());
    vpnResponse.setUserName(vpnUser.getUsername());
    vpnResponse.setAccountName(account.getAccountName());
    final Domain domain = _entityMgr.findById(Domain.class, account.getDomainId());
    if (domain != null) {
        vpnResponse.setDomainId(domain.getUuid());
        vpnResponse.setDomainName(domain.getName());
    }
    vpnResponse.setResponseName(getCommandName());
    vpnResponse.setObjectName("vpnuser");
    setResponseObject(vpnResponse);
}
Also used : Account(com.cloud.legacymodel.user.Account) VpnUser(com.cloud.legacymodel.network.VpnUser) ServerApiException(com.cloud.api.ServerApiException) Domain(com.cloud.legacymodel.domain.Domain) VpnUsersResponse(com.cloud.api.response.VpnUsersResponse)

Example 4 with VpnUser

use of com.cloud.legacymodel.network.VpnUser in project cosmic by MissionCriticalCloud.

the class CommandSetupHelper method configureRemoteAccessVpn.

private void configureRemoteAccessVpn(final VirtualRouter router, final RemoteAccessVpn remoteAccessVpnToExclude, final NetworkOverviewTO.VPNTO vpnTO) {
    final RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findByAccountAndVpc(router.getAccountId(), router.getVpcId());
    if (vpn != null && !vpn.equals(remoteAccessVpnToExclude)) {
        final NetworkOverviewTO.VPNTO.RemoteAccessTO remoteAccessTO = new NetworkOverviewTO.VPNTO.RemoteAccessTO();
        final IpAddress serverIp = _networkModel.getIp(vpn.getServerAddressId());
        remoteAccessTO.setVpnServerIp(serverIp.getAddress().addr());
        remoteAccessTO.setPreSharedKey(vpn.getIpsecPresharedKey());
        remoteAccessTO.setIpRange(vpn.getIpRange());
        remoteAccessTO.setLocalIp(vpn.getLocalIp());
        final Vpc vpc = _vpcDao.findById(vpn.getVpcId());
        remoteAccessTO.setLocalCidr(vpc.getCidr());
        remoteAccessTO.setVpnUsers(_vpnUsersDao.listByAccount(vpn.getAccountId()).stream().filter(vpnUser -> VpnUser.State.Add.equals(vpnUser.getState()) || VpnUser.State.Active.equals(vpnUser.getState())).map(vpnUser -> new NetworkOverviewTO.VPNTO.RemoteAccessTO.VPNUserTO(vpnUser.getUsername(), vpnUser.getPassword())).toArray(NetworkOverviewTO.VPNTO.RemoteAccessTO.VPNUserTO[]::new));
        vpnTO.setRemoteAccess(remoteAccessTO);
    }
}
Also used : LbStickinessPolicy(com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy) NetworkModel(com.cloud.network.NetworkModel) VpnUser(com.cloud.legacymodel.network.VpnUser) Nic(com.cloud.legacymodel.network.Nic) StaticRouteProfile(com.cloud.legacymodel.network.vpc.StaticRouteProfile) NetworkACLTO(com.cloud.legacymodel.to.NetworkACLTO) ServiceOfferingDao(com.cloud.service.dao.ServiceOfferingDao) VlanDao(com.cloud.dc.dao.VlanDao) Map(java.util.Map) ZoneRepository(com.cloud.db.repository.ZoneRepository) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) FirewallRule(com.cloud.legacymodel.network.FirewallRule) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) NicTO(com.cloud.legacymodel.to.NicTO) LoadBalancingRule(com.cloud.legacymodel.network.LoadBalancingRule) RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) StaticNatRule(com.cloud.legacymodel.network.StaticNatRule) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) SetPublicIpACLCommand(com.cloud.legacymodel.communication.command.SetPublicIpACLCommand) VpcGateway(com.cloud.legacymodel.network.vpc.VpcGateway) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) SetStaticNatRulesCommand(com.cloud.legacymodel.communication.command.SetStaticNatRulesCommand) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) VpnUserDao(com.cloud.network.dao.VpnUserDao) NumbersUtil(com.cloud.utils.NumbersUtil) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) Ip(com.cloud.legacymodel.network.Ip) Zone(com.cloud.db.model.Zone) UpdateVmOverviewCommand(com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand) NicProfile(com.cloud.vm.NicProfile) ArrayList(java.util.ArrayList) Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) VlanVO(com.cloud.dc.VlanVO) ConfigurationDao(com.cloud.framework.config.dao.ConfigurationDao) DomainRouterVO(com.cloud.vm.DomainRouterVO) UpdateNetworkOverviewCommand(com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) PortForwardingRule(com.cloud.legacymodel.network.PortForwardingRule) DomainRouterDao(com.cloud.vm.dao.DomainRouterDao) SavePasswordCommand(com.cloud.legacymodel.communication.command.SavePasswordCommand) LbDestination(com.cloud.legacymodel.network.LoadBalancingRule.LbDestination) PublicIpACLTO(com.cloud.legacymodel.to.PublicIpACLTO) Site2SiteVpnConnectionDao(com.cloud.network.dao.Site2SiteVpnConnectionDao) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) UserVmDao(com.cloud.vm.dao.UserVmDao) NetworkElementCommand(com.cloud.legacymodel.communication.command.NetworkElementCommand) NicDao(com.cloud.vm.dao.NicDao) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) Site2SiteCustomerGatewayDao(com.cloud.network.dao.Site2SiteCustomerGatewayDao) StaticRouteDao(com.cloud.network.vpc.dao.StaticRouteDao) SetPortForwardingRulesVpcCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand) FirewallRuleTO(com.cloud.legacymodel.to.FirewallRuleTO) PortForwardingRuleTO(com.cloud.legacymodel.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand) Site2SiteVpnGatewayDao(com.cloud.network.dao.Site2SiteVpnGatewayDao) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) StaticNatRuleTO(com.cloud.legacymodel.to.StaticNatRuleTO) URI(java.net.URI) Config(com.cloud.configuration.Config) SetFirewallRulesCommand(com.cloud.legacymodel.communication.command.SetFirewallRulesCommand) StringUtils(com.cloud.utils.StringUtils) SetNetworkACLCommand(com.cloud.legacymodel.communication.command.SetNetworkACLCommand) TrafficType(com.cloud.model.enumeration.TrafficType) LBStickinessPolicyDao(com.cloud.network.dao.LBStickinessPolicyDao) Commands(com.cloud.agent.manager.Commands) IpAddress(com.cloud.network.IpAddress) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) NicVO(com.cloud.vm.NicVO) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Collectors(java.util.stream.Collectors) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) List(java.util.List) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO) NetworkACLItem(com.cloud.legacymodel.network.vpc.NetworkACLItem) RemoteAccessVpnDao(com.cloud.network.dao.RemoteAccessVpnDao) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) Optional(java.util.Optional) NetUtils(com.cloud.utils.net.NetUtils) LoadBalancerConfigCommand(com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) StaticNat(com.cloud.network.rules.StaticNat) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) HashMap(java.util.HashMap) NetworkDao(com.cloud.network.dao.NetworkDao) Inject(javax.inject.Inject) IPAddressVO(com.cloud.network.dao.IPAddressVO) NetworkVO(com.cloud.network.dao.NetworkVO) Qualifier(org.springframework.beans.factory.annotation.Qualifier) IPAddressDao(com.cloud.network.dao.IPAddressDao) VMOverviewTO(com.cloud.legacymodel.to.VMOverviewTO) GuestType(com.cloud.model.enumeration.GuestType) FirewallRulesDao(com.cloud.network.dao.FirewallRulesDao) Network(com.cloud.legacymodel.network.Network) NetworkACLItemDao(com.cloud.network.vpc.NetworkACLItemDao) SetupVRCommand(com.cloud.legacymodel.communication.command.SetupVRCommand) PublicIpAddress(com.cloud.network.PublicIpAddress) NetworkOffering(com.cloud.offering.NetworkOffering) UserVmVO(com.cloud.vm.UserVmVO) VpcDao(com.cloud.network.vpc.dao.VpcDao) NetworkOfferingDao(com.cloud.offerings.dao.NetworkOfferingDao) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) Vpc(com.cloud.legacymodel.network.vpc.Vpc) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) Vpc(com.cloud.legacymodel.network.vpc.Vpc) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress)

Example 5 with VpnUser

use of com.cloud.legacymodel.network.VpnUser in project cosmic by MissionCriticalCloud.

the class AddVpnUserCmdTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    final AccountService accountService = Mockito.mock(AccountService.class);
    final Account account = Mockito.mock(Account.class);
    Mockito.when(accountService.getAccount(Matchers.anyLong())).thenReturn(account);
    addVpnUserCmd._accountService = accountService;
    final RemoteAccessVpnService ravService = Mockito.mock(RemoteAccessVpnService.class);
    final VpnUser vpnUser = Mockito.mock(VpnUser.class);
    Mockito.when(ravService.addVpnUser(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(vpnUser);
    addVpnUserCmd._ravService = ravService;
    addVpnUserCmd.create();
}
Also used : Account(com.cloud.legacymodel.user.Account) VpnUser(com.cloud.legacymodel.network.VpnUser) AccountService(com.cloud.user.AccountService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) Test(org.junit.Test)

Aggregations

VpnUser (com.cloud.legacymodel.network.VpnUser)8 ArrayList (java.util.ArrayList)5 RemoteAccessVpn (com.cloud.network.RemoteAccessVpn)4 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)3 Account (com.cloud.legacymodel.user.Account)3 Test (org.junit.Test)3 ServerApiException (com.cloud.api.ServerApiException)2 VpnUsersResponse (com.cloud.api.response.VpnUsersResponse)2 Zone (com.cloud.db.model.Zone)2 Vpc (com.cloud.legacymodel.network.vpc.Vpc)2 AdvancedNetworkTopology (com.cloud.network.topology.AdvancedNetworkTopology)2 BasicNetworkTopology (com.cloud.network.topology.BasicNetworkTopology)2 DomainRouterVO (com.cloud.vm.DomainRouterVO)2 Commands (com.cloud.agent.manager.Commands)1 ListResponse (com.cloud.api.response.ListResponse)1 Config (com.cloud.configuration.Config)1 ZoneRepository (com.cloud.db.repository.ZoneRepository)1 VlanVO (com.cloud.dc.VlanVO)1 VlanDao (com.cloud.dc.dao.VlanDao)1 ConfigurationDao (com.cloud.framework.config.dao.ConfigurationDao)1