Search in sources :

Example 6 with VpnUser

use of com.cloud.network.VpnUser in project cloudstack by apache.

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 DataCenterVO dataCenterVO = Mockito.mock(DataCenterVO.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<VpnUser>();
    users.add(vpnUser1);
    users.add(vpnUser2);
    final List<DomainRouterVO> routers = new ArrayList<DomainRouterVO>();
    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(_dcDao.findById(zoneId)).thenReturn(dataCenterVO);
    when(networkTopologyContext.retrieveNetworkTopology(dataCenterVO)).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(_dcDao, times(1)).findById(zoneId);
    verify(networkTopologyContext, times(1)).retrieveNetworkTopology(dataCenterVO);
}
Also used : BasicNetworkTopology(org.apache.cloudstack.network.topology.BasicNetworkTopology) DataCenterVO(com.cloud.dc.DataCenterVO) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) AdvancedNetworkTopology(org.apache.cloudstack.network.topology.AdvancedNetworkTopology) VpnUser(com.cloud.network.VpnUser) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 7 with VpnUser

use of com.cloud.network.VpnUser in project CloudStack-archive by CloudStack-extras.

the class AddVpnUserCmd method execute.

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

Example 8 with VpnUser

use of com.cloud.network.VpnUser in project CloudStack-archive by CloudStack-extras.

the class ListVpnUsersCmd method execute.

@Override
public void execute() {
    List<? extends VpnUser> vpnUsers = _ravService.searchForVpnUsers(this);
    ListResponse<VpnUsersResponse> response = new ListResponse<VpnUsersResponse>();
    List<VpnUsersResponse> vpnResponses = new ArrayList<VpnUsersResponse>();
    for (VpnUser vpnUser : vpnUsers) {
        vpnResponses.add(_responseGenerator.createVpnUserResponse(vpnUser));
    }
    response.setResponses(vpnResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : VpnUser(com.cloud.network.VpnUser) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) VpnUsersResponse(com.cloud.api.response.VpnUsersResponse)

Example 9 with VpnUser

use of com.cloud.network.VpnUser in project cloudstack by apache.

the class AddVpnUserCmdTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    AccountService accountService = Mockito.mock(AccountService.class);
    Account account = Mockito.mock(Account.class);
    Mockito.when(accountService.getAccount(Matchers.anyLong())).thenReturn(account);
    addVpnUserCmd._accountService = accountService;
    RemoteAccessVpnService ravService = Mockito.mock(RemoteAccessVpnService.class);
    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.user.Account) VpnUser(com.cloud.network.VpnUser) AccountService(com.cloud.user.AccountService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) Test(org.junit.Test)

Example 10 with VpnUser

use of com.cloud.network.VpnUser in project cloudstack by apache.

the class AddVpnUserCmd method create.

@Override
public void create() {
    Account owner = _accountService.getAccount(getEntityOwnerId());
    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.user.Account) VpnUser(com.cloud.network.VpnUser) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

VpnUser (com.cloud.network.VpnUser)11 ArrayList (java.util.ArrayList)6 Account (com.cloud.user.Account)5 Test (org.junit.Test)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)3 RemoteAccessVpn (com.cloud.network.RemoteAccessVpn)3 AdvancedNetworkTopology (org.apache.cloudstack.network.topology.AdvancedNetworkTopology)3 BasicNetworkTopology (org.apache.cloudstack.network.topology.BasicNetworkTopology)3 ServerApiException (com.cloud.api.ServerApiException)2 VpnUsersResponse (com.cloud.api.response.VpnUsersResponse)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 VpnUsersResponse (org.apache.cloudstack.api.response.VpnUsersResponse)2 VpnUsersCfgCommand (com.cloud.agent.api.routing.VpnUsersCfgCommand)1 ListResponse (com.cloud.api.response.ListResponse)1 Domain (com.cloud.domain.Domain)1 Vpc (com.cloud.network.vpc.Vpc)1 RemoteAccessVpnService (com.cloud.network.vpn.RemoteAccessVpnService)1 AccountService (com.cloud.user.AccountService)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1