Search in sources :

Example 61 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class RuntimeObjectFactoryTest method testGetObjectReferences.

@Test
public void testGetObjectReferences() throws Exception {
    IPentahoSession session = new StandaloneSession("joe");
    RuntimeObjectFactory factory = new RuntimeObjectFactory();
    final SingletonPentahoObjectReference<String> something1 = new SingletonPentahoObjectReference<String>(String.class, "Something1", Collections.<String, Object>emptyMap(), 0);
    final SingletonPentahoObjectReference<String> something2 = new SingletonPentahoObjectReference<String>(String.class, "Something2", Collections.<String, Object>emptyMap(), 1);
    factory.registerReference(something1);
    factory.registerReference(something2);
    List<String> out = factory.getAll(String.class, PentahoSessionHolder.getSession());
    assertEquals(2, out.size());
    List<IPentahoObjectReference<String>> refs = factory.getObjectReferences(String.class, session);
    assertSame(something1, refs.get(1));
    assertSame(something2, refs.get(0));
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) SingletonPentahoObjectReference(org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference) Test(org.junit.Test)

Example 62 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class PrototypePentahoObjectReferenceTest method testReference.

@Test
public void testReference() throws Exception {
    PrototypePentahoObjectReference<UUID> sessionRef = new PrototypePentahoObjectReference.Builder<UUID>(UUID.class).creator(new IObjectCreator<UUID>() {

        @Override
        public UUID create(IPentahoSession session) {
            return UUID.randomUUID();
        }
    }).build();
    IPentahoSession s1 = new StandaloneSession("joe");
    IPentahoSession s2 = new StandaloneSession("admin");
    PentahoSessionHolder.setSession(s1);
    UUID s1Uuid = sessionRef.getObject();
    PentahoSessionHolder.setSession(s2);
    UUID s2Uuid = sessionRef.getObject();
    assertNotSame(s1Uuid, s2Uuid);
    PentahoSessionHolder.setSession(s1);
    UUID s1UuidAgain = sessionRef.getObject();
    assertNotSame(s1Uuid, s1UuidAgain);
}
Also used : IObjectCreator(org.pentaho.platform.api.engine.IObjectCreator) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) UUID(java.util.UUID) Test(org.junit.Test)

Example 63 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class SessionBoundPentahoObjectReferenceTest method testReference.

@Test
public void testReference() throws Exception {
    SessionBoundPentahoObjectReference<UUID> sessionRef = new SessionBoundPentahoObjectReference.Builder<UUID>(UUID.class).creator(new IObjectCreator<UUID>() {

        @Override
        public UUID create(IPentahoSession session) {
            return UUID.randomUUID();
        }
    }).build();
    IPentahoSession s1 = new StandaloneSession("joe");
    IPentahoSession s2 = new StandaloneSession("admin");
    PentahoSessionHolder.setSession(s1);
    UUID s1Uuid = sessionRef.getObject();
    PentahoSessionHolder.setSession(s2);
    UUID s2Uuid = sessionRef.getObject();
    assertNotSame(s1Uuid, s2Uuid);
    PentahoSessionHolder.setSession(s1);
    UUID s1UuidAgain = sessionRef.getObject();
    assertSame(s1Uuid, s1UuidAgain);
}
Also used : IObjectCreator(org.pentaho.platform.api.engine.IObjectCreator) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) UUID(java.util.UUID) Test(org.junit.Test)

Example 64 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class UserRoleDaoService method updatePassword.

public void updatePassword(User user, String administratorPassword) throws SecurityException {
    final IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
    AuthenticationProvider authenticator = PentahoSystem.get(AuthenticationProvider.class, pentahoSession);
    if (authenticator == null) {
        throw new SecurityException("Authentication Provider not found, can not re-authenticate logged-in user");
    }
    try {
        Authentication authentication = authenticator.authenticate(new UsernamePasswordAuthenticationToken(pentahoSession.getName(), administratorPassword));
        if (authentication.isAuthenticated()) {
            updatePassword(user);
        } else {
            throw new SecurityException("Logged-in user re-authentication failed");
        }
    } catch (AuthenticationException e) {
        throw new SecurityException("Logged-in user re-authentication failed", e);
    }
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Authentication(org.springframework.security.core.Authentication) AuthenticationProvider(org.springframework.security.authentication.AuthenticationProvider) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 65 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class HttpWebService method doGetFixMe.

public void doGetFixMe(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    try {
        // $NON-NLS-1$
        String actionPath = request.getParameter("path");
        String solutionName = actionPath.substring(0, actionPath.indexOf('/', 1));
        String actionName = actionPath.substring(actionPath.lastIndexOf('/'));
        String actionSeqPath = ActionInfo.buildSolutionPath(solutionName, actionPath, actionName);
        // $NON-NLS-1$
        String component = request.getParameter("component");
        String content = getPayloadAsString(request);
        IParameterProvider parameterProvider = null;
        HashMap parameters = new HashMap();
        if ((content != null) && (content.length() > 0)) {
            Document doc = XmlDom4JHelper.getDocFromString(content, new PentahoEntityResolver());
            // $NON-NLS-1$
            List parameterNodes = doc.selectNodes("//SOAP-ENV:Body/*/*");
            for (int i = 0; i < parameterNodes.size(); i++) {
                Node parameterNode = (Node) parameterNodes.get(i);
                String parameterName = parameterNode.getName();
                String parameterValue = parameterNode.getText();
                // if( "xml-data".equalsIgnoreCase( ) )
                if ("action".equals(parameterName)) {
                    // $NON-NLS-1$
                    ActionInfo info = ActionInfo.parseActionString(parameterValue);
                    solutionName = info.getSolutionName();
                    actionPath = info.getPath();
                    actionName = info.getActionName();
                } else if ("component".equals(parameterName)) {
                    // $NON-NLS-1$
                    component = parameterValue;
                } else {
                    parameters.put(parameterName, parameterValue);
                }
            }
            parameterProvider = new SimpleParameterProvider(parameters);
        } else {
            parameterProvider = new HttpRequestParameterProvider(request);
        }
        // $NON-NLS-1$
        response.setContentType("text/xml");
        response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
        // PentahoHttpSession userSession = new PentahoHttpSession(
        // request.getRemoteUser(), request.getSession(),
        // request.getLocale() );
        IPentahoSession userSession = getPentahoSession(request);
        // $NON-NLS-1$
        String instanceId = request.getParameter("instance-id");
        String processId = this.getClass().getName();
        OutputStream contentStream = new ByteArrayOutputStream();
        SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false);
        // send the header of the message to prevent time-outs while we are
        // working
        OutputStream outputStream = response.getOutputStream();
        if ((component == null) || "action".equals(component)) {
            // $NON-NLS-1$
            // assume this is an action sequence execute
            HttpWebServiceRequestHandler requestHandler = new HttpWebServiceRequestHandler(userSession, null, outputHandler, parameterProvider, null);
            requestHandler.setParameterProvider(IParameterProvider.SCOPE_SESSION, new HttpSessionParameterProvider(userSession));
            requestHandler.setInstanceId(instanceId);
            requestHandler.setProcessId(processId);
            requestHandler.setActionPath(actionSeqPath);
            if (ServletBase.debug) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_START"));
            }
            IRuntimeContext runtime = null;
            try {
                runtime = requestHandler.handleActionRequest(0, 0);
                Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, requestHandler.getMessages());
                XmlDom4JHelper.saveDom(responseDoc, outputStream, PentahoSystem.getSystemSetting("web-service-encoding", "utf-8"), true);
            } finally {
                if (runtime != null) {
                    runtime.dispose();
                }
            }
        } else if ("dial".equals(component)) {
            // $NON-NLS-1$
            doDial(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession);
        } else if ("chart".equals(component)) {
            // $NON-NLS-1$
            doChart(actionPath, parameterProvider, outputStream, userSession);
        } else if ("xaction-parameter".equals(component)) {
            // $NON-NLS-1$
            doParameter(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession, response);
        }
    } catch (Throwable t) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"), t);
    }
    if (ServletBase.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_END"));
    }
}
Also used : HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Node(org.dom4j.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ActionInfo(org.pentaho.platform.engine.core.solution.ActionInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpWebServiceRequestHandler(org.pentaho.platform.web.http.request.HttpWebServiceRequestHandler) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpSessionParameterProvider(org.pentaho.platform.web.http.session.HttpSessionParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) ArrayList(java.util.ArrayList) List(java.util.List) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Aggregations

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10