use of org.pentaho.platform.api.engine.ISystemSettings in project pentaho-platform by pentaho.
the class PentahoSystem method runAsSystem.
/**
* Runs code as system with full privileges.
* <p/>
* <p>
* Unfortunate copy and paste from SecurityHelper due to dependencies.
* </p>
*/
private static <T> T runAsSystem(final Callable<T> callable) throws Exception {
final String name = StringUtils.defaultIfEmpty(PentahoSystem.get(String.class, "singleTenantAdminUserName", null), "admin");
IPentahoSession origSession = PentahoSessionHolder.getSession();
SecurityContext originalContext = SecurityContextHolder.getContext();
try {
// create pentaho session
StandaloneSession session = new StandaloneSession(name);
session.setAuthenticated(name);
// create authentication
List<GrantedAuthority> roles;
ISystemSettings settings = PentahoSystem.getSystemSettings();
String roleName = (settings != null) ? settings.getSystemSetting("acl-voter/admin-role", "Admin") : "Admin";
roles = new ArrayList<GrantedAuthority>();
roles.add(new SimpleGrantedAuthority(roleName));
User user = new User(name, "", true, true, true, true, roles);
// $NON-NLS-1$
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(user, "", roles);
// set holders
PentahoSessionHolder.setSession(session);
// Clearing the SecurityContext to force the subsequent call to getContext() to generate a new SecurityContext.
// This prevents us from modifying the Authentication on a SecurityContext isntance which may be shared between
// threads.
SecurityContextHolder.clearContext();
SecurityContextHolder.getContext().setAuthentication(auth);
return callable.call();
} finally {
IPentahoSession sessionToDestroy = PentahoSessionHolder.getSession();
if (sessionToDestroy != null && sessionToDestroy != origSession) {
try {
sessionToDestroy.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
PentahoSessionHolder.setSession(origSession);
SecurityContextHolder.setContext(originalContext);
}
}
use of org.pentaho.platform.api.engine.ISystemSettings in project pentaho-platform by pentaho.
the class AbstractPentahoAclVoter method init.
public void init(final IPentahoSession session) {
ISystemSettings settings = PentahoSystem.getSystemSettings();
// $NON-NLS-1$ //$NON-NLS-2$
String roleName = settings.getSystemSetting("acl-voter/admin-role", "Administrator");
adminRole = new SimpleGrantedAuthority(roleName);
}
use of org.pentaho.platform.api.engine.ISystemSettings in project pentaho-platform by pentaho.
the class XActionUtilTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() throws ObjectFactoryException {
MockitoAnnotations.initMocks(this);
Map<String, String[]> map = mock(Map.class);
when(httpServletRequest.getParameterMap()).thenReturn(map);
when(httpServletRequest.getParameter(anyString())).thenReturn(null);
when(repository.getFile(anyString())).thenReturn(generatedFile);
List<IContentItem> items = Arrays.asList(mock(RepositoryFileContentItem.class));
IRuntimeContext context = mock(IRuntimeContext.class);
when(context.getOutputContentItems()).thenReturn(items);
when(engine.execute(anyString(), anyString(), anyBoolean(), anyBoolean(), anyString(), anyBoolean(), anyMap(), any(IOutputHandler.class), any(IActionCompleteListener.class), any(IPentahoUrlFactory.class), anyList())).thenReturn(context);
pentahoObjectFactoryUnified = mock(IPentahoObjectFactory.class);
when(pentahoObjectFactoryUnified.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactoryUnified.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (IUnifiedRepository.class.toString().equals(invocation.getArguments()[0].toString())) {
return repository;
} else if (ISolutionEngine.class.toString().equals(invocation.getArguments()[0].toString())) {
return engine;
} else if (IMessageFormatter.class.toString().equals(invocation.getArguments()[0].toString())) {
return formatter;
} else if (IAuthorizationPolicy.class.toString().equals(invocation.getArguments()[0].toString())) {
return authPolicy;
} else {
return null;
}
}
});
PentahoSystem.registerObjectFactory(pentahoObjectFactoryUnified);
ISystemSettings systemSettingsService = mock(ISystemSettings.class);
when(systemSettingsService.getSystemSetting(anyString(), anyString())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0].toString();
}
});
PentahoSystem.setSystemSettingsService(systemSettingsService);
PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_INHERITABLETHREADLOCAL);
PentahoSessionHolder.setSession(userSession);
}
use of org.pentaho.platform.api.engine.ISystemSettings in project pentaho-platform by pentaho.
the class ChartBeansSystemListenerIT method setUp.
/**
* @throws java.lang.Exception
*/
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
String solutionsRelativePath = TestResourceLocation.TEST_RESOURCES + "/org/pentaho/test/platform/plugin/chartbeans/solutions";
MicroPlatform mp = new MicroPlatform(solutionsRelativePath);
mp.define(ISolutionEngine.class, Object.class);
ISystemSettings settings = new XmlSimpleSystemSettings();
mp.setSettingsProvider(settings);
mp.init();
}
use of org.pentaho.platform.api.engine.ISystemSettings in project pentaho-platform by pentaho.
the class HttpSessionPentahoSessionIntegrationFilterTest method testSessionCookieDisabledInSettings.
@Test
public void testSessionCookieDisabledInSettings() {
final ISystemSettings systemSettings = PentahoSystem.getSystemSettings();
try {
final ISystemSettings mockSettings = Mockito.mock(ISystemSettings.class);
Mockito.when(mockSettings.getSystemSetting("session-expired-dialog", "true")).thenReturn("false");
PentahoSystem.setSystemSettingsService(mockSettings);
new HttpSessionPentahoSessionIntegrationFilter().setSessionExpirationCookies(httpSession, pentahoSession, servletResponse);
Mockito.verify(servletResponse, Mockito.never()).addCookie(Mockito.any());
} finally {
PentahoSystem.setSystemSettingsService(systemSettings);
}
}
Aggregations