use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.
the class EESpoonPluginTest method setUp.
@Before
public void setUp() throws KettleException {
IAbsSecurityProvider provider = mock(IAbsSecurityProvider.class);
doReturn(provider).when(repository).getService(eq(IAbsSecurityProvider.class));
doReturn(repository).when(spoon).getRepository();
doCallRealMethod().when(eeSpoonPlugin).onEvent(any());
}
use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.
the class EESpoonPlugin method doOnSecurityUpdate.
/**
* Override UI elements to reflect the users capabilities as described by their permission levels
*/
private void doOnSecurityUpdate() throws KettleException {
initMainSpoonContainer();
Repository repository = getSpoonInstance().getRepository();
// Repository User
if (repository != null && repository.hasService(IRoleSupportSecurityManager.class)) {
UIObjectRegistry.getInstance().registerUIRepositoryUserClass(UIEERepositoryUser.class);
} else {
UIObjectRegistry.getInstance().registerUIRepositoryUserClass(UIObjectRegistry.DEFAULT_UIREPOSITORYUSER_CLASS);
}
// Repository Directory
if (repository != null && repository.hasService(IAclService.class)) {
UIObjectRegistry.getInstance().registerUIRepositoryDirectoryClass(UIEERepositoryDirectory.class);
UIObjectRegistry.getInstance().registerUIDatabaseConnectionClass(UIEEDatabaseConnection.class);
} else {
UIObjectRegistry.getInstance().registerUIRepositoryDirectoryClass(UIObjectRegistry.DEFAULT_UIDIR_CLASS);
}
// Repository Role
if (repository != null && repository.hasService(IAbsSecurityProvider.class)) {
UIEEObjectRegistery.getInstance().registerUIRepositoryRoleClass(UIAbsRepositoryRole.class);
IAbsSecurityProvider securityProvider = (IAbsSecurityProvider) repository.getService(IAbsSecurityProvider.class);
enablePermission(securityProvider);
}
// Job & Transformation =
if (repository.hasService(ILockService.class)) {
UIObjectRegistry.getInstance().registerUIJobClass(UIEEJob.class);
UIObjectRegistry.getInstance().registerUITransformationClass(UIEETransformation.class);
SpoonDelegateRegistry.getInstance().registerSpoonJobDelegateClass(SpoonEEJobDelegate.class);
SpoonDelegateRegistry.getInstance().registerSpoonTransDelegateClass(SpoonEETransformationDelegate.class);
} else {
UIObjectRegistry.getInstance().registerUIJobClass(UIObjectRegistry.DEFAULT_UIJOB_CLASS);
UIObjectRegistry.getInstance().registerUITransformationClass(UIObjectRegistry.DEFAULT_UITRANS_CLASS);
SpoonDelegateRegistry.getInstance().registerSpoonJobDelegateClass(SpoonDelegateRegistry.DEFAULT_SPOONJOBDELEGATE_CLASS);
SpoonDelegateRegistry.getInstance().registerSpoonTransDelegateClass(SpoonDelegateRegistry.DEFAULT_SPOONTRANSDELEGATE_CLASS);
}
}
use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.
the class EESpoonPlugin method warnClosingOfOpenTabsBasedOnPerms.
private void warnClosingOfOpenTabsBasedOnPerms(Spoon spoon) throws KettleException {
Class<PurRepositoryDialog> PKG = PurRepositoryDialog.class;
// Check to see if there are any open jobs/trans
Repository repository = spoon.getRepository();
if (spoon.getActiveMeta() == null) {
return;
}
String warningTitle = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllForce.Connect.Title");
String warningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOptionAdditional.Connect.Message");
String additionalWarningText = "";
int buttons = SWT.OK;
IAbsSecurityProvider absSecurityProvider = (IAbsSecurityProvider) repository.getService(IAbsSecurityProvider.class);
if (absSecurityProvider != null) {
boolean createPerms = false;
boolean executePerms = false;
boolean readPerms = false;
try {
createPerms = absSecurityProvider.isAllowed(IAbsSecurityProvider.CREATE_CONTENT_ACTION);
executePerms = absSecurityProvider.isAllowed(IAbsSecurityProvider.EXECUTE_CONTENT_ACTION);
readPerms = absSecurityProvider.isAllowed(IAbsSecurityProvider.READ_CONTENT_ACTION);
} catch (KettleException e) {
// No nothing - we are just checking perms
}
// Check to see if display of warning dialog has been disabled
if (readPerms && createPerms && executePerms) {
warningTitle = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOption.Connect.Title");
warningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOption.Connect.Message");
buttons = SWT.YES | SWT.NO | SWT.ICON_INFORMATION;
} else {
warningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllForce.Connect.Message");
if (createPerms) {
additionalWarningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllForceAdditional.Connect.Message");
buttons = SWT.YES | SWT.NO | SWT.ICON_WARNING;
} else {
additionalWarningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOptionAdditional.Connect.Message");
buttons = SWT.OK | SWT.ICON_WARNING;
}
}
}
MessageBox mb = new MessageBox(spoon.getShell(), buttons);
mb.setMessage(additionalWarningText.length() != 0 ? warningText + "\n\n" + additionalWarningText : warningText);
mb.setText(warningTitle);
final int isCloseAllFiles = mb.open();
// Otherwise, we force close the tabs
if ((isCloseAllFiles == SWT.YES) || (isCloseAllFiles == SWT.OK)) {
spoon.closeAllFiles();
}
}
use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.
the class EESpoonPlugin method applyToContainer.
public void applyToContainer(String category, XulDomContainer container) throws XulException {
container.registerClassLoader(getClass().getClassLoader());
if (category.equals("spoon")) {
// $NON-NLS-1$
// register the two controllers, note that the lock controller must come
// after the abs controller so the biz logic between the two hold.
// Register the ABS Menu controller
getSpoonInstance().addSpoonMenuController(new SpoonMenuABSController());
// Register the SpoonMenuLockController to modify the main Spoon Menu structure
getSpoonInstance().addSpoonMenuController(new SpoonMenuLockController());
} else if (category.equals("trans-graph") || category.equals("job-graph")) {
// $NON-NLS-1$ //$NON-NLS-2$
if ((getSpoonInstance() != null) && (getSpoonInstance().getRepository() != null) && (getSpoonInstance().getRepository() instanceof PurRepository)) {
// $NON-NLS-1$
container.getDocumentRoot().addOverlay("org/pentaho/di/ui/repository/pur/xul/spoon-lock-overlay.xul");
container.addEventHandler(new SpoonLockController());
}
try {
Repository repository = getSpoonInstance().getRepository();
if (repository != null) {
IAbsSecurityProvider securityProvider = (IAbsSecurityProvider) repository.getService(IAbsSecurityProvider.class);
if (securityProvider != null) {
enablePermission(securityProvider);
}
}
} catch (KettleException e) {
e.printStackTrace();
}
} else if (category.equals("repository-explorer")) {
// $NON-NLS-1$
try {
Repository repository = getSpoonInstance().getRepository();
IAbsSecurityProvider securityProvider = null;
if (repository != null) {
securityProvider = (IAbsSecurityProvider) repository.getService(IAbsSecurityProvider.class);
}
if (securityProvider != null) {
boolean createPermitted = securityProvider.isAllowed(IAbsSecurityProvider.CREATE_CONTENT_ACTION);
boolean executePermitted = securityProvider.isAllowed(IAbsSecurityProvider.EXECUTE_CONTENT_ACTION);
// Disable export if user can not create or execute content (prevents execution outside of this repo)
container.getDocumentRoot().getElementById("folder-context-export").setDisabled(!createPermitted || !executePermitted);
}
} catch (KettleException e) {
e.printStackTrace();
}
}
}
use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.
the class SpoonLockController method init.
protected void init() {
try {
if ((Spoon.getInstance().getRepository() != null) && (Spoon.getInstance().getRepository().hasService(IAbsSecurityProvider.class))) {
IAbsSecurityProvider securityService = (IAbsSecurityProvider) Spoon.getInstance().getRepository().getService(IAbsSecurityProvider.class);
setCreateAllowed(allowedActionsContains(securityService, IAbsSecurityProvider.CREATE_CONTENT_ACTION));
}
shell = (((Spoon) SpoonFactory.getInstance()).getShell());
XulDomContainer container = getXulDomContainer();
bindingFactory = new DefaultBindingFactory();
bindingFactory.setDocument(container.getDocumentRoot());
bindingFactory.setBindingType(Type.ONE_WAY);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
bindingFactory.createBinding(this, "activeMetaUnlocked", "lock-context-locknotes", "disabled");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
bindingFactory.createBinding(this, "lockingNotAllowed", "lock-context-lock", "disabled");
// Try transformation
if (container.getEventHandlers().containsKey("transgraph")) {
// $NON-NLS-1$
// $NON-NLS-1$
workingMeta = ((TransGraph) container.getEventHandler("transgraph")).getMeta();
} else if (container.getEventHandlers().containsKey("jobgraph")) {
// $NON-NLS-1$
// $NON-NLS-1$
workingMeta = ((JobGraph) container.getEventHandler("jobgraph")).getMeta();
}
RepositoryLock repoLock = fetchRepositoryLock(workingMeta);
if (repoLock != null) {
// $NON-NLS-1$
XulMenuitem lockMenuItem = (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
lockMenuItem.setSelected(true);
// Permit locking/unlocking if the user owns the lock
if (Spoon.getInstance().getRepository() instanceof PurRepository) {
setLockingAllowed(new UnifiedRepositoryLockService(((PurRepository) Spoon.getInstance().getRepository()).getUnderlyingRepository()).canUnlockFileById(workingMeta.getObjectId()));
} else {
setLockingAllowed(repoLock.getLogin().equalsIgnoreCase(Spoon.getInstance().getRepository().getUserInfo().getLogin()));
}
} else {
setLockingAllowed(true);
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
firePropertyChange("activeMetaUnlocked", null, repoLock == null);
} catch (Exception e) {
// $NON-NLS-1$
log.error(BaseMessages.getString(PKG, "LockController.NoLockingSupport"), e);
new ErrorDialog(((Spoon) SpoonFactory.getInstance()).getShell(), BaseMessages.getString(PKG, "Dialog.Error"), e.getMessage(), // $NON-NLS-1$
e);
}
}
Aggregations