Skip to content

Commit

Permalink
CLOUDOPS-391: Add permissions check in Ussd module
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulazizali77 committed Nov 24, 2017
1 parent 4e23c66 commit bcd9516
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions restcomm/restcomm.ussd/pom.xml
Expand Up @@ -61,6 +61,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.restcomm</groupId>
<artifactId>restcomm-connect.identity</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.restcomm</groupId>
<artifactId>restcomm-connect.dao</artifactId>
Expand Down
Expand Up @@ -60,6 +60,8 @@
import org.restcomm.connect.telephony.api.util.CallControlHelper;
import org.restcomm.connect.ussd.interpreter.UssdInterpreter;
import org.restcomm.connect.ussd.interpreter.UssdInterpreterParams;
import org.restcomm.connect.identity.UserIdentityContext;
import org.restcomm.connect.identity.permissions.PermissionsUtil;

import akka.actor.ActorRef;
import akka.actor.Props;
Expand Down Expand Up @@ -91,6 +93,7 @@ public class UssdCallManager extends RestcommUntypedActor {
private boolean useTo;

private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this);
private PermissionsUtil permissionsUtil;

/**
* @param configuration
Expand All @@ -111,6 +114,7 @@ public UssdCallManager(Configuration configuration, ServletContext context, SipF
this.ussdGatewayUri = ussdGatewayConfig.getString("ussd-gateway-uri");
this.ussdGatewayUsername = ussdGatewayConfig.getString("ussd-gateway-user");
this.ussdGatewayPassword = ussdGatewayConfig.getString("ussd-gateway-password");
permissionsUtil = PermissionsUtil.getInstance(this.context);
}

private ActorRef ussdCall() {
Expand Down Expand Up @@ -142,6 +146,24 @@ public void onReceive(final Object message) throws Exception {
final Class<?> klass = message.getClass();
final ActorRef self = self();
final ActorRef sender = sender();

//FIXME: really kludgy and ugly
//TODO: how to get AccountSid from SipServletRequest??
Account effectiveAccount = null;
AccountsDao accountsDao = storage.getAccountsDao();
if (CreateCall.class.equals(klass)) {
this.createCallRequest = (CreateCall) message;
effectiveAccount = accountsDao.getAccount(this.createCallRequest.accountId());
}

UserIdentityContext uic = new UserIdentityContext(effectiveAccount, accountsDao);
permissionsUtil.setUserIdentityContext(uic);
try {
permissionsUtil.checkPermission("Restcomm:*:Ussd");
} catch (Exception e) {
logger.debug("No permission for USSD feature "+e);
return;
}
if (message instanceof SipServletRequest) {
final SipServletRequest request = (SipServletRequest) message;
final String method = request.getMethod();
Expand Down

0 comments on commit bcd9516

Please sign in to comment.