ci.chanDef.setJavaClass(type.getJavaClass());
}
crs.saveChannelDefinition(ci.chanDef);
// Permission for everyone to subscribe to channel
AuthorizationService authService = AuthorizationService.instance();
String target = "CHAN_ID." + ci.chanDef.getId();
IUpdatingPermissionManager upm = authService.newUpdatingPermissionManager(FRAMEWORK_OWNER);
// Remove old permissions
IPermission[] oldPermissions = upm.getPermissions(SUBSCRIBER_ACTIVITY, target);
upm.removePermissions(oldPermissions);
// Add new permissions for this channel based on both groups and users
if (ci.groups != null) {
IPermission[] newGroupPermissions = new IPermission[ci.groups.length];
for (int j = 0; j < ci.groups.length; j++) {
IAuthorizationPrincipal authPrincipal = authService.newPrincipal(ci.groups[j]);
newGroupPermissions[j] = upm.newPermission(authPrincipal);
newGroupPermissions[j].setType(GRANT_PERMISSION_TYPE);
newGroupPermissions[j].setActivity(SUBSCRIBER_ACTIVITY);
newGroupPermissions[j].setTarget(target);
}
upm.addPermissions(newGroupPermissions);
}
if (ci.users != null) {
IPermission[] newUserPermissions = new IPermission[ci.users.length];
for (int j=0; j < ci.users.length; j++) {
IAuthorizationPrincipal authPrincipal = authService.newPrincipal(ci.users[j]);
newUserPermissions[j] = upm.newPermission(authPrincipal);
newUserPermissions[j].setType(GRANT_PERMISSION_TYPE);
newUserPermissions[j].setActivity(SUBSCRIBER_ACTIVITY);
newUserPermissions[j].setTarget(target);
}