Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ef6860f
added shallow test cases
Feb 3, 2018
ec9199c
test impl
Feb 5, 2018
873afd9
secure imple, need to revert it later
Feb 5, 2018
9663676
Merge branch 'master' into restcomm-1645
Feb 7, 2018
a0088e8
Merge branch 'master' into restcomm-1645
Feb 7, 2018
07c728f
removed checkAuthenticatedAccount and replaced with filter
Feb 7, 2018
f06aa48
getProfileWithoutAuthentication
Feb 7, 2018
fae917e
apply filter to all APIs
Feb 7, 2018
ac3a7e1
removed stupid impl
Feb 7, 2018
3014be8
added explicit token checking
Feb 8, 2018
593b48d
added security test
Feb 8, 2018
255de32
filterClosedAccounts
Feb 8, 2018
2b55b54
filterClosedAccounts
Feb 8, 2018
3ca8b4e
access api with close account tests
Feb 8, 2018
2b8d3dc
cs fix
Feb 8, 2018
ce7b50b
aplied super admin as part of contraint
Feb 8, 2018
62edcef
removed extra class
Feb 8, 2018
f9eebd1
we dont need this test anymore, covered under new integartion test
Feb 8, 2018
3791bc1
ignore cors test with comment
Feb 9, 2018
d738d8d
Merge branch 'master' into restcomm-1645
Feb 9, 2018
bd79f5e
added WWW-Authenticate header for unauth requests
Feb 9, 2018
a9708ad
cs fix
Feb 9, 2018
a2596f5
cs fix
Feb 9, 2018
149f955
exclude recording file https://telestax.atlassian.net/browse/RESTCOMM…
Feb 9, 2018
78191a6
corrected pattern
Feb 9, 2018
7cf267b
updated filter
Feb 9, 2018
4e1a8ac
added test for access by simple http url connection
Feb 9, 2018
41af029
moved test to bottome
Feb 9, 2018
d0786c4
updated pattern and test
Feb 10, 2018
bd67af2
corrected pattern
Feb 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<security-constraint>
<web-resource-collection>
<web-resource-name>restAPI</web-resource-name>
<url-pattern>/2012-04-24/Profiles/*</url-pattern>
<url-pattern>/2012-04-24/*</url-pattern>
</web-resource-collection>
</security-constraint>
<login-config>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public LinkHeader composeLink(Sid targetSid, UriInfo info) {
}

protected Response getAccount(final String accountSid, final MediaType responseType, UriInfo info) {
checkAuthenticatedAccount();
//First check if the account has the required permissions in general, this way we can fail fast and avoid expensive DAO operations
Account account = null;
checkPermission("RestComm:Read:Accounts");
Expand Down Expand Up @@ -347,7 +346,6 @@ private void removeIncomingPhoneNumbers(Sid accountSid, IncomingPhoneNumbersDao


protected Response getAccounts(final UriInfo info, final MediaType responseType) {
checkAuthenticatedAccount();
//First check if the account has the required permissions in general, this way we can fail fast and avoid expensive DAO operations
checkPermission("RestComm:Read:Accounts");
final Account account = userIdentityContext.getEffectiveAccount();
Expand Down Expand Up @@ -389,7 +387,6 @@ protected Response getAccounts(final UriInfo info, final MediaType responseType)
}

protected Response putAccount(final MultivaluedMap<String, String> data, final MediaType responseType) {
checkAuthenticatedAccount();
//First check if the account has the required permissions in general, this way we can fail fast and avoid expensive DAO operations
checkPermission("RestComm:Create:Accounts");
// check account level depth. If we're already at third level no sub-accounts are allowed to be created
Expand Down Expand Up @@ -561,7 +558,6 @@ private Account prepareAccountForUpdate(final Account account, final Multivalued

protected Response updateAccount(final String identifier, final MultivaluedMap<String, String> data,
final MediaType responseType) {
checkAuthenticatedAccount();
// First check if the account has the required permissions in general, this way we can fail fast and avoid expensive DAO
// operations
checkPermission("RestComm:Modify:Accounts");
Expand Down Expand Up @@ -666,11 +662,6 @@ private Organization getOrganization(final MultivaluedMap<String, String> data)
protected Response migrateAccountOrganization(final String identifier, final MultivaluedMap<String, String> data,
final MediaType responseType) {

//Validation 1 - Only SuperAdmin is allowed to migrate organization for an Account
if (!isSuperAdmin()) {
throw new InsufficientPermission();
}

Organization organization = getOrganization(data);
//Validation 2 - Check if data contains Organization (either SID or domain name)
if (organization == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static org.restcomm.connect.http.security.AccountPrincipal.SUPER_ADMIN_ROLE;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.OPTIONS;
Expand Down Expand Up @@ -101,6 +103,7 @@ public Response updateAccountAsJsonPut(@PathParam("accountSid") final String acc
@Path("/migrate/{accountSid}")
@Consumes(APPLICATION_FORM_URLENCODED)
@POST
@RolesAllowed(SUPER_ADMIN_ROLE)
public Response migrateAccount(@PathParam("accountSid") final String accountSid, final MultivaluedMap<String, String> data) {
return migrateAccountOrganization(accountSid, data, APPLICATION_JSON_TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE;
import static org.restcomm.connect.http.security.AccountPrincipal.SUPER_ADMIN_ROLE;

import javax.annotation.security.RolesAllowed;

/**
* @author quintana.thomas@gmail.com (Thomas Quintana)
Expand Down Expand Up @@ -92,6 +95,7 @@ public Response updateAccountAsXmlPut(@PathParam("accountSid") final String acco
@Path("/migrate/{accountSid}")
@Consumes(APPLICATION_FORM_URLENCODED)
@POST
@RolesAllowed(SUPER_ADMIN_ROLE)
public Response migrateAccount(@PathParam("accoutSid") final String accountSid, final MultivaluedMap<String, String> data) {
return migrateAccountOrganization(accountSid, data, APPLICATION_XML_TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.restcomm.connect.extension.api.ExtensionConfiguration;
import org.restcomm.connect.http.converter.ExtensionConfigurationConverter;
import org.restcomm.connect.http.converter.RestCommResponseConverter;
import org.restcomm.connect.http.exceptions.InsufficientPermission;

import javax.annotation.PostConstruct;
import javax.ws.rs.core.MediaType;
Expand Down Expand Up @@ -78,8 +77,6 @@ void init() {
xstream.registerConverter(converter);
xstream.registerConverter(new ExtensionConfigurationConverter(configuration));
xstream.registerConverter(new RestCommResponseConverter(configuration));
// Make sure there is an authenticated account present when this endpoint is used
checkAuthenticatedAccount();
}

/**
Expand All @@ -90,9 +87,6 @@ void init() {
*/
protected Response getConfiguration(final String extensionId, final Sid accountSid, final MediaType responseType) {
//Parameter "extensionId" could be the extension Sid or extension name.
if (!isSuperAdmin()) {
throw new InsufficientPermission();
}

ExtensionConfiguration extensionConfiguration = null;
ExtensionConfiguration extensionAccountConfiguration = null;
Expand Down Expand Up @@ -173,9 +167,6 @@ private ExtensionConfiguration createFrom(final MultivaluedMap<String, String> d
}

protected Response postConfiguration(final MultivaluedMap<String, String> data, final MediaType responseType) {
if (!isSuperAdmin()) {
throw new InsufficientPermission();
}

Sid accountSid = null;

Expand Down Expand Up @@ -221,9 +212,6 @@ protected Response postConfiguration(final MultivaluedMap<String, String> data,
}

protected Response updateConfiguration(String extensionSid, MultivaluedMap<String, String> data, MediaType responseType) {
if (!isSuperAdmin()) {
throw new InsufficientPermission();
}

if (!Sid.pattern.matcher(extensionSid).matches()) {
return status(BAD_REQUEST).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@
import org.restcomm.connect.commons.dao.Sid;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static org.restcomm.connect.http.security.AccountPrincipal.SUPER_ADMIN_ROLE;

import javax.annotation.security.RolesAllowed;

/**
* Created by gvagenas on 12/10/2016.
*/
@Path("/ExtensionsConfiguration.json")
@RolesAllowed(SUPER_ADMIN_ROLE)
public class ExtensionsConfigurationJsonEndpoint extends ExtensionsConfigurationEndpoint {

@Path("/{extensionId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
import org.restcomm.connect.commons.dao.Sid;

import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE;
import static org.restcomm.connect.http.security.AccountPrincipal.SUPER_ADMIN_ROLE;

import javax.annotation.security.RolesAllowed;

@Path("/ExtensionsConfiguration")
@RolesAllowed(SUPER_ADMIN_ROLE)
public class ExtensionsConfigurationXmlEndpoint extends ExtensionsConfigurationEndpoint {

@Path("/{extensionId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ private Gateway createFrom(final MultivaluedMap<String, String> data) {
}

protected Response getGateway(final String accountSid, final String sid, final MediaType responseType) {
//following 2 things are enough to grant access: 1. a valid authentication token is present. 2 it is a super admin.
checkAuthenticatedAccount();
allowOnlySuperAdmin();
// secure(accountsDao.getAccount(accountSid), "RestComm:Read:Gateways");
final Gateway gateway = dao.getGateway(new Sid(sid));
if (gateway == null) {
return status(NOT_FOUND).build();
Expand All @@ -112,10 +108,6 @@ protected Response getGateway(final String accountSid, final String sid, final M
}

protected Response getGateways(final String accountSid, final MediaType responseType) {
//following 2 things are enough to grant access: 1. a valid authentication token is present. 2 it is a super admin.
checkAuthenticatedAccount();
allowOnlySuperAdmin();
// secure(accountsDao.getAccount(accountSid), "RestComm:Read:Gateways");
final List<Gateway> gateways = dao.getGateways();
if (APPLICATION_XML_TYPE == responseType) {
final RestCommResponse response = new RestCommResponse(new GatewayList(gateways));
Expand All @@ -128,10 +120,7 @@ protected Response getGateways(final String accountSid, final MediaType response
}

protected Response putGateway(final String accountSid, final MultivaluedMap<String, String> data, final MediaType responseType) {
//following 2 things are enough to grant access: 1. a valid authentication token is present. 2 it is a super admin.
checkAuthenticatedAccount();
allowOnlySuperAdmin();
// secure(accountsDao.getAccount(accountSid), "RestComm:Create:Gateways");

try {
validate(data);
} catch (final RuntimeException exception) {
Expand All @@ -154,10 +143,7 @@ protected Response putGateway(final String accountSid, final MultivaluedMap<Stri
}

protected Response updateGateway(final String accountSid, final String sid, final MultivaluedMap<String, String> data, final MediaType responseType) {
//following 2 things are enough to grant access: 1. a valid authentication token is present. 2 it is a super admin.
checkAuthenticatedAccount();
allowOnlySuperAdmin();
// secure(accountsDao.getAccount(accountSid), "RestComm:Modify:Gateways");

Gateway gateway = dao.getGateway(new Sid(sid));
if (gateway == null) {
return status(NOT_FOUND).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
package org.restcomm.connect.http;

import static javax.ws.rs.core.MediaType.*;
import static org.restcomm.connect.http.security.AccountPrincipal.SUPER_ADMIN_ROLE;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand All @@ -35,6 +37,7 @@
*/
@Path("/Accounts/{accountSid}/Management/Gateways.json")
@ThreadSafe
@RolesAllowed(SUPER_ADMIN_ROLE)
public class GatewaysJsonEndpoint extends GatewaysEndpoint {
public GatewaysJsonEndpoint() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import static javax.ws.rs.core.MediaType.*;
import static javax.ws.rs.core.Response.*;
import static org.restcomm.connect.http.security.AccountPrincipal.SUPER_ADMIN_ROLE;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
Expand All @@ -39,6 +41,7 @@
*/
@Path("/Accounts/{accountSid}/Management/Gateways")
@ThreadSafe
@RolesAllowed(SUPER_ADMIN_ROLE)
public final class GatewaysXmlEndpoint extends GatewaysEndpoint {
public GatewaysXmlEndpoint() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ public static org.restcomm.connect.provisioning.number.api.PhoneNumber convertIn
protected Response migrateIncomingPhoneNumbers(String targetAccountSid, MultivaluedMap<String, String> data, MediaType responseType) {
Account effectiveAccount = userIdentityContext.getEffectiveAccount();
secure(effectiveAccount, "RestComm:Modify:IncomingPhoneNumbers");
allowOnlySuperAdmin();
try{
Account targetAccount = accountsDao.getAccount(targetAccountSid);
// this is to avoid if mistakenly provided super admin account as targetAccountSid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE;
import static org.restcomm.connect.http.security.AccountPrincipal.SUPER_ADMIN_ROLE;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
Expand Down Expand Up @@ -212,13 +214,15 @@ public Response putIncomingMobilePhoneNumberAsJSon(@PathParam("accountSid") fina

@Path("/migrate")
@POST
@RolesAllowed(SUPER_ADMIN_ROLE)
public Response migrateIncomingPhoneNumbersAsXml(@PathParam("accountSid") final String accountSid,
final MultivaluedMap<String, String> data) {
return migrateIncomingPhoneNumbers(accountSid, data, APPLICATION_XML_TYPE);
}

@Path("/migrate.json")
@POST
@RolesAllowed(SUPER_ADMIN_ROLE)
public Response migrateIncomingPhoneNumbersAsJson(@PathParam("accountSid") final String accountSid,
final MultivaluedMap<String, String> data) {
return migrateIncomingPhoneNumbers(accountSid, data, APPLICATION_JSON_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public LinkHeader composeLink(Sid targetSid, UriInfo info) {
*/
protected Response getOrganization(final String organizationSid, final MediaType responseType,
UriInfo info) {
checkAuthenticatedAccount();
//First check if the account has the required permissions in general, this way we can fail fast and avoid expensive DAO operations
checkPermission("RestComm:Read:Organizations");
Organization organization = null;
Expand Down Expand Up @@ -191,9 +190,6 @@ protected Response getOrganization(final String organizationSid, final MediaType
* @return
*/
protected Response getOrganizations(UriInfo info, final MediaType responseType) {
checkAuthenticatedAccount();
allowOnlySuperAdmin();

List<Organization> organizations = null;

String status = info.getQueryParameters().getFirst("Status");
Expand Down Expand Up @@ -228,8 +224,6 @@ protected Response putOrganization(String domainName, final UriInfo info,
if(domainName == null){
return status(BAD_REQUEST).entity(MSG_EMPTY_DOMAIN_NAME ).build();
}else{
checkAuthenticatedAccount();
allowOnlySuperAdmin();

//Character verification
if(!pattern.matcher(domainName).matches()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
package org.restcomm.connect.http;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static org.restcomm.connect.http.security.AccountPrincipal.SUPER_ADMIN_ROLE;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -49,12 +51,14 @@ public Response getOrganizationAsJson(@PathParam("organizationSid") final String
}

@GET
@RolesAllowed(SUPER_ADMIN_ROLE)
public Response getOrganizations(@Context UriInfo info) {
return getOrganizations(info, APPLICATION_JSON_TYPE);
}

@Path("/{domainName}")
@PUT
@RolesAllowed(SUPER_ADMIN_ROLE)
public Response putOrganizationPut(@PathParam("domainName") final String domainName, @Context UriInfo info) {
return putOrganization(domainName, info, APPLICATION_JSON_TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
package org.restcomm.connect.http;

import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE;
import static org.restcomm.connect.http.security.AccountPrincipal.SUPER_ADMIN_ROLE;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
Expand All @@ -36,6 +38,7 @@
*/
@Path("/Organizations")
@ThreadSafe
@RolesAllowed(SUPER_ADMIN_ROLE)
public final class OrganizationsXmlEndpoint extends OrganizationsEndpoint {
public OrganizationsXmlEndpoint() {
super();
Expand All @@ -49,12 +52,14 @@ public Response getOrganizationAsXml(@PathParam("organizationSid") final String
}

@GET
@RolesAllowed(SUPER_ADMIN_ROLE)
public Response getOrganizations(@Context UriInfo info) {
return getOrganizations(info, APPLICATION_XML_TYPE);
}

@Path("/{domainName}")
@PUT
@RolesAllowed(SUPER_ADMIN_ROLE)
public Response putOrganizationPut(@PathParam("domainName") final String domainName, @Context UriInfo info) {
return putOrganization(domainName, info, APPLICATION_XML_TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ public void init() {
}

protected Response getProxies(final String accountSid, final MediaType responseType) {
//following 2 things are enough to grant access: 1. a valid authentication token is present. 2 it is a super admin.
checkAuthenticatedAccount();
allowOnlySuperAdmin();
// secure(accountsDao.getAccount(accountSid), "RestComm:Read:OutboundProxies");

Map<String, String> proxies;

Expand All @@ -115,10 +111,6 @@ protected Response getProxies(final String accountSid, final MediaType responseT
}

protected Response switchProxy(final String accountSid, final MediaType responseType) {
//following 2 things are enough to grant access: 1. a valid authentication token is present. 2 it is a super admin.
checkAuthenticatedAccount();
allowOnlySuperAdmin();
// secure(accountsDao.getAccount(accountSid), "RestComm:Read:OutboundProxies");

Map<String, String> proxyAfterSwitch;

Expand All @@ -141,10 +133,6 @@ protected Response switchProxy(final String accountSid, final MediaType response
}

protected Response getActiveProxy(final String accountSid, final MediaType responseType) {
//following 2 things are enough to grant access: 1. a valid authentication token is present. 2 it is a super admin.
checkAuthenticatedAccount();
allowOnlySuperAdmin();
// secure(accountsDao.getAccount(accountSid), "RestComm:Read:OutboundProxies");

Map<String, String> activeProxy;

Expand Down
Loading