diff --git a/api/src/main/java/org/eclipse/daanse/xmla/api/XmlaService.java b/api/src/main/java/org/eclipse/daanse/xmla/api/XmlaService.java index c1865aa..b5a9985 100644 --- a/api/src/main/java/org/eclipse/daanse/xmla/api/XmlaService.java +++ b/api/src/main/java/org/eclipse/daanse/xmla/api/XmlaService.java @@ -15,10 +15,13 @@ import org.eclipse.daanse.xmla.api.discover.DiscoverService; import org.eclipse.daanse.xmla.api.execute.ExecuteService; +import org.eclipse.daanse.xmla.api.session.SessionService; public interface XmlaService { DiscoverService discover(); ExecuteService execute(); + + SessionService session(); } diff --git a/api/src/main/java/org/eclipse/daanse/xmla/api/session/SessionService.java b/api/src/main/java/org/eclipse/daanse/xmla/api/session/SessionService.java new file mode 100644 index 0000000..3907c52 --- /dev/null +++ b/api/src/main/java/org/eclipse/daanse/xmla/api/session/SessionService.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * SmartCity Jena - initial + * Stefan Bischof (bipolis.org) - initial + */ +package org.eclipse.daanse.xmla.api.session; + +import java.util.Optional; + +import org.eclipse.daanse.xmla.api.UserPrincipal; +import org.eclipse.daanse.xmla.api.xmla.BeginSession; +import org.eclipse.daanse.xmla.api.xmla.EndSession; +import org.eclipse.daanse.xmla.api.xmla.Session; + +public interface SessionService { + + Optional beginSession(BeginSession beginSession, UserPrincipal userPrincipal); + + boolean checkSession(Session session, UserPrincipal userPrincipal); + + void endSession(EndSession endSession, UserPrincipal userPrincipal); + +} diff --git a/api/src/main/java/org/eclipse/daanse/xmla/api/session/package-info.java b/api/src/main/java/org/eclipse/daanse/xmla/api/session/package-info.java new file mode 100644 index 0000000..0ff8998 --- /dev/null +++ b/api/src/main/java/org/eclipse/daanse/xmla/api/session/package-info.java @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2025 Contributors to the Eclipse Foundation. +* +* This program and the accompanying materials are made +* available under the terms of the Eclipse Public License 2.0 +* which is available at https://www.eclipse.org/legal/epl-2.0/ +* +* SPDX-License-Identifier: EPL-2.0 +* +* Contributors: +* SmartCity Jena - initial +* Stefan Bischof (bipolis.org) - initial +*/ + +@org.osgi.annotation.bundle.Export +@org.osgi.annotation.versioning.Version("0.0.1") +package org.eclipse.daanse.xmla.api.session; diff --git a/client/soapmessage/src/main/java/org/eclipse/daanse/xmla/client/soapmessage/SessionServiceImpl.java b/client/soapmessage/src/main/java/org/eclipse/daanse/xmla/client/soapmessage/SessionServiceImpl.java new file mode 100644 index 0000000..9a0229b --- /dev/null +++ b/client/soapmessage/src/main/java/org/eclipse/daanse/xmla/client/soapmessage/SessionServiceImpl.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * SmartCity Jena - initial + * Stefan Bischof (bipolis.org) - initial + */ +package org.eclipse.daanse.xmla.client.soapmessage; + +import java.util.Optional; + +import org.eclipse.daanse.xmla.api.UserPrincipal; +import org.eclipse.daanse.xmla.api.session.SessionService; +import org.eclipse.daanse.xmla.api.xmla.BeginSession; +import org.eclipse.daanse.xmla.api.xmla.EndSession; +import org.eclipse.daanse.xmla.api.xmla.Session; + +public class SessionServiceImpl implements SessionService { + + @Override + public Optional beginSession(BeginSession beginSession, UserPrincipal userPrincipal) { + return Optional.empty(); + } + + @Override + public boolean checkSession(Session session, UserPrincipal userPrincipal) { + return true; + } + + @Override + public void endSession(EndSession endSession, UserPrincipal userPrincipal) { + + } + +} diff --git a/client/soapmessage/src/main/java/org/eclipse/daanse/xmla/client/soapmessage/XmlaServiceClientImpl.java b/client/soapmessage/src/main/java/org/eclipse/daanse/xmla/client/soapmessage/XmlaServiceClientImpl.java index c12e6ae..7bc004b 100644 --- a/client/soapmessage/src/main/java/org/eclipse/daanse/xmla/client/soapmessage/XmlaServiceClientImpl.java +++ b/client/soapmessage/src/main/java/org/eclipse/daanse/xmla/client/soapmessage/XmlaServiceClientImpl.java @@ -16,6 +16,7 @@ import org.eclipse.daanse.xmla.api.XmlaService; import org.eclipse.daanse.xmla.api.discover.DiscoverService; import org.eclipse.daanse.xmla.api.execute.ExecuteService; +import org.eclipse.daanse.xmla.api.session.SessionService; public class XmlaServiceClientImpl implements XmlaService { @@ -38,4 +39,9 @@ public ExecuteService execute() { return es; } + @Override + public SessionService session() { + return null; + } + } diff --git a/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/RequestMetaDataUtils.java b/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/RequestMetaDataUtils.java index 25c395c..76244a1 100644 --- a/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/RequestMetaDataUtils.java +++ b/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/RequestMetaDataUtils.java @@ -25,14 +25,13 @@ public class RequestMetaDataUtils { public static final String USER_AGENT = "User-agent"; - public static RequestMetaData getRequestMetaData( - Map headers, - Optional ses) { - Optional oUserAgent = get(headers.get(USER_AGENT)); - return new RequestMetaDataR(oUserAgent, ses.isPresent() ? Optional.of(ses.get().sessionId()) : Optional.empty()); + public static RequestMetaData getRequestMetaData(Map headers, Optional oSession) { + Optional oUserAgent = getUserAgent(headers.get(USER_AGENT)); + return new RequestMetaDataR(oUserAgent, + oSession.isPresent() ? Optional.of(oSession.get().sessionId()) : Optional.empty()); } - private static Optional get(Object o) { + private static Optional getUserAgent(Object o) { if (o instanceof List list) { if (list.isEmpty()) { return Optional.of((String) list.get(0)); diff --git a/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/SessionUtil.java b/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/SessionUtil.java deleted file mode 100644 index 5de2c84..0000000 --- a/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/SessionUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation. - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * SmartCity Jena - initial - * Stefan Bischof (bipolis.org) - initial - */ -package org.eclipse.daanse.xmla.server.adapter.soapmessage; - -import jakarta.xml.soap.SOAPHeader; -import org.eclipse.daanse.xmla.api.xmla.BeginSession; -import org.eclipse.daanse.xmla.api.xmla.EndSession; -import org.eclipse.daanse.xmla.api.xmla.Session; -import org.eclipse.daanse.xmla.model.record.xmla.SessionR; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Optional; -import java.util.Set; -import java.util.UUID; - -public class SessionUtil { - - private static final Logger LOGGER = LoggerFactory.getLogger(SessionUtil.class); - - public static Optional getSession(SOAPHeader soapHeader, Set sessions) { - Optional oSession = Convert.getSession(soapHeader); - Optional oEndSession = Convert.getEndSession(soapHeader); - Optional beginSession = Convert.getBeginSession(soapHeader); - if (beginSession.isPresent()) { - String ses = UUID.randomUUID().toString(); - sessions.add(ses); - return Optional.of(new SessionR(ses, null)); - - } - if (oSession.isPresent()) { - checkSession(oSession.get().sessionId(), sessions); - return oSession; - - - } - if (oEndSession.isPresent()) { - removeSession(oEndSession.get().sessionId(), sessions); - } - return Optional.empty(); - } - - private static void removeSession(String s, Set sessions) { - sessions.remove(s); - } - - private static void checkSession(String session, Set sessions) { - if (!sessions.contains(session)) { - LOGGER.error("Session expired " + session); - throw new RuntimeException("Session expired"); - } - } - -} diff --git a/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/XmlaApiAdapter.java b/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/XmlaApiAdapter.java index cc3fa18..a28df3b 100644 --- a/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/XmlaApiAdapter.java +++ b/server/adapter.soapmessage/src/main/java/org/eclipse/daanse/xmla/server/adapter/soapmessage/XmlaApiAdapter.java @@ -13,16 +13,14 @@ */ package org.eclipse.daanse.xmla.server.adapter.soapmessage; -import jakarta.xml.soap.MessageFactory; -import jakarta.xml.soap.Node; -import jakarta.xml.soap.SOAPBody; -import jakarta.xml.soap.SOAPElement; -import jakarta.xml.soap.SOAPEnvelope; -import jakarta.xml.soap.SOAPException; -import jakarta.xml.soap.SOAPHeader; -import jakarta.xml.soap.SOAPHeaderElement; -import jakarta.xml.soap.SOAPMessage; -import jakarta.xml.soap.SOAPPart; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import javax.xml.namespace.QName; + import org.eclipse.daanse.xmla.api.RequestMetaData; import org.eclipse.daanse.xmla.api.UserPrincipal; import org.eclipse.daanse.xmla.api.XmlaService; @@ -89,7 +87,9 @@ import org.eclipse.daanse.xmla.api.execute.clearcache.ClearCacheResponse; import org.eclipse.daanse.xmla.api.execute.statement.StatementRequest; import org.eclipse.daanse.xmla.api.execute.statement.StatementResponse; +import org.eclipse.daanse.xmla.api.xmla.BeginSession; import org.eclipse.daanse.xmla.api.xmla.Command; +import org.eclipse.daanse.xmla.api.xmla.EndSession; import org.eclipse.daanse.xmla.api.xmla.Session; import org.eclipse.daanse.xmla.model.record.UserPrincipalR; import org.eclipse.daanse.xmla.model.record.discover.PropertiesR; @@ -158,14 +158,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.xml.namespace.QName; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import jakarta.xml.soap.MessageFactory; +import jakarta.xml.soap.Node; +import jakarta.xml.soap.SOAPBody; +import jakarta.xml.soap.SOAPElement; +import jakarta.xml.soap.SOAPEnvelope; +import jakarta.xml.soap.SOAPException; +import jakarta.xml.soap.SOAPHeader; +import jakarta.xml.soap.SOAPHeaderElement; +import jakarta.xml.soap.SOAPMessage; +import jakarta.xml.soap.SOAPPart; public class XmlaApiAdapter { private static final Logger LOGGER = LoggerFactory.getLogger(XmlaApiAdapter.class); @@ -203,7 +205,7 @@ public XmlaApiAdapter(XmlaService xmlaService) { private static final String MDSCHEMA_SETS = "MDSCHEMA_SETS"; private static final String MDSCHEMA_KPIS = "MDSCHEMA_KPIS"; private static final String MDSCHEMA_MEASUREGROUPS = "MDSCHEMA_MEASUREGROUPS"; - private Set sessions = new HashSet<>(); + private static final QName QN_SESSION = new QName("urn:schemas-microsoft-com:xml-analysis", "Session"); public SOAPMessage handleRequest(SOAPMessage messageRequest, Map headers) { try { @@ -219,18 +221,17 @@ public SOAPMessage handleRequest(SOAPMessage messageRequest, Map envelopeResponse.addNamespaceDeclaration(Constants.EMPTY.PREFIX, Constants.EMPTY.NS_URN); envelopeResponse.addNamespaceDeclaration(Constants.XSI.PREFIX, Constants.XSI.NS_URN); - SOAPBody bodyResponse = envelopeResponse.getBody(); Object role = headers.get("ROLE"); Object user = headers.get("USER"); - UserPrincipal userPrincipal = new UserPrincipalR(getStringOrNull(user), getRiles(role)); - Optional ses = SessionUtil.getSession(messageRequest.getSOAPHeader(), sessions); - if (ses.isPresent()) { + UserPrincipal userPrincipal = new UserPrincipalR(getStringOrNull(user), getRoles(role)); + Optional oSession =session(messageRequest.getSOAPHeader(),userPrincipal); + if (oSession.isPresent()) { SOAPHeader header = envelopeResponse.getHeader(); - QName session = new QName("urn:schemas-microsoft-com:xml-analysis", "Session"); - SOAPHeaderElement sessionElement = header.addHeaderElement(session); - sessionElement.addAttribute(new QName("SessionId"), ses.get().sessionId()); + SOAPHeaderElement sessionElement = header.addHeaderElement(QN_SESSION); + sessionElement.addAttribute(new QName("SessionId"), oSession.get().sessionId()); } - RequestMetaData metaData = RequestMetaDataUtils.getRequestMetaData(headers, ses); + RequestMetaData metaData = RequestMetaDataUtils.getRequestMetaData(headers, oSession); + SOAPBody bodyResponse = envelopeResponse.getBody(); handleBody(messageRequest.getSOAPBody(), bodyResponse, metaData, userPrincipal); return messageResponse; } catch (SOAPException e) { @@ -239,7 +240,7 @@ public SOAPMessage handleRequest(SOAPMessage messageRequest, Map return null; } - private List getRiles(Object ob) { + private List getRoles(Object ob) { if (ob != null && ob instanceof String str) { return Arrays.asList(str.split(",")); } @@ -253,6 +254,31 @@ private String getStringOrNull(Object ob) { return null; } + private Optional session(SOAPHeader soapRequestHeader, UserPrincipal userPrincipal) throws SOAPException { + Optional oSession = Convert.getSession(soapRequestHeader); + if (oSession.isPresent()) { + boolean checked = xmlaService.session().checkSession(oSession.get(), userPrincipal); + if (checked) { + return oSession; + } else { + Optional.empty(); + } + } + + Optional beginSession = Convert.getBeginSession(soapRequestHeader); + if (beginSession.isPresent()) { + return xmlaService.session().beginSession(beginSession.get(), userPrincipal); + } + + Optional oEndSession = Convert.getEndSession(soapRequestHeader); + if (oEndSession.isPresent()) { + xmlaService.session().endSession(oEndSession.get(), userPrincipal); + return Optional.empty(); + } + + return Optional.empty(); + } + private void handleBody(SOAPBody body, SOAPBody responseBody, RequestMetaData metaData, UserPrincipal userPrincipal) throws SOAPException { SOAPElement node = null; @@ -280,6 +306,7 @@ private void handleBody(SOAPBody body, SOAPBody responseBody, RequestMetaData me } + private void discover(SOAPElement discover, SOAPBody responseBody, RequestMetaData metaData, UserPrincipal userPrincipal) throws SOAPException {