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