From 34533d78e95d59393a4c4ac8c9b100b9658fc70b Mon Sep 17 00:00:00 2001 From: Benedikt Hauptmann Date: Wed, 3 Mar 2021 13:41:26 +0100 Subject: [PATCH 1/3] added new service 'loginpoints' --- .../connectors/api/ConnectorBase.java | 5 ++ .../specmate/connectors/api/IConnector.java | 23 ++++- .../connectors/api/IProjectService.java | 1 + .../internal/ProjectServiceImpl.java | 23 +++++ .../specmate/emfjson/EMFJsonSerializer.java | 85 ++++++++++++------- .../emfrest/authentication/LoginPoints.java | 50 +++++++++++ .../internal/EmfRestJerseyApplication.java | 5 +- .../internal/auth/AuthenticationFilter.java | 11 ++- .../emfrest/internal/rest/JsonMapWriter.java | 52 ++++++++++++ .../emfrest/internal/rest/JsonWriter.java | 13 ++- .../internal/services/HPConnector.java | 5 ++ .../jira/internal/services/JiraConnector.java | 5 ++ 12 files changed, 234 insertions(+), 44 deletions(-) create mode 100644 bundles/specmate-emfrest/src/com/specmate/emfrest/authentication/LoginPoints.java create mode 100644 bundles/specmate-emfrest/src/com/specmate/emfrest/internal/rest/JsonMapWriter.java diff --git a/bundles/specmate-connectors-api/src/com/specmate/connectors/api/ConnectorBase.java b/bundles/specmate-connectors-api/src/com/specmate/connectors/api/ConnectorBase.java index 78d2bc538..b6223291d 100644 --- a/bundles/specmate-connectors-api/src/com/specmate/connectors/api/ConnectorBase.java +++ b/bundles/specmate-connectors-api/src/com/specmate/connectors/api/ConnectorBase.java @@ -22,6 +22,11 @@ public IProject getProject() { @Override public void setProject(IProject project) { this.project = project; + } + + @Override + public String getLoginPointName() { + return "Project " + project.getID(); } } diff --git a/bundles/specmate-connectors-api/src/com/specmate/connectors/api/IConnector.java b/bundles/specmate-connectors-api/src/com/specmate/connectors/api/IConnector.java index 19b36b284..bfe050aad 100644 --- a/bundles/specmate-connectors-api/src/com/specmate/connectors/api/IConnector.java +++ b/bundles/specmate-connectors-api/src/com/specmate/connectors/api/IConnector.java @@ -60,8 +60,8 @@ public interface IConnector { IContainer getContainerForRequirement(Requirement requirement) throws SpecmateException; /** - * Returns a set of projects given credentials have access to. Returns an empty set if - * credentials are invalid. + * Returns a set of projects given credentials have access to. Returns an empty + * set if credentials are invalid. * * @return Returns a set of projects the credentials can access. If successful, * this set must contain at least the current project which the user @@ -71,7 +71,22 @@ public interface IConnector { * credentials do not match (for any project) an empty set must be * returned. */ - Set authenticate(String username, String password) - throws SpecmateException; + Set authenticate(String username, String password) throws SpecmateException; + /** + * Generates a readable ID of this login point name. This feature is helpful for + * connectors which supports multi-project logins. + * + * For example, a jira connector (which supports multi-project logins) may + * generate a string like 'JIRA Server https://jira.company.com'. Therefore, all + * other connectors which connect to the same server can be identified folded + * toghether. + * + * Connector with identical login point names will listed as just one entry in + * the login dialog. + * + * If your connector does not support multi-project logins, just generate a + * unique name, for example, embedding your project name. 'Project ABC'. + */ + String getLoginPointName(); } diff --git a/bundles/specmate-connectors-api/src/com/specmate/connectors/api/IProjectService.java b/bundles/specmate-connectors-api/src/com/specmate/connectors/api/IProjectService.java index 3ac220097..d02fc198f 100644 --- a/bundles/specmate-connectors-api/src/com/specmate/connectors/api/IProjectService.java +++ b/bundles/specmate-connectors-api/src/com/specmate/connectors/api/IProjectService.java @@ -8,4 +8,5 @@ public interface IProjectService { IProject getProject(String projectName); Set getProjectNames(); Map getProjects(); + Map getLoginPoints(); } diff --git a/bundles/specmate-connectors/src/com/specmate/connectors/internal/ProjectServiceImpl.java b/bundles/specmate-connectors/src/com/specmate/connectors/internal/ProjectServiceImpl.java index 6f741346e..37bd451c1 100644 --- a/bundles/specmate-connectors/src/com/specmate/connectors/internal/ProjectServiceImpl.java +++ b/bundles/specmate-connectors/src/com/specmate/connectors/internal/ProjectServiceImpl.java @@ -10,6 +10,7 @@ import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.component.annotations.ReferencePolicy; +import com.specmate.connectors.api.IConnector; import com.specmate.connectors.api.IProject; import com.specmate.connectors.api.IProjectService; @@ -41,4 +42,26 @@ public void removeProject(IProject project) { public Map getProjects() { return Collections.unmodifiableMap(projects); } + + @Override + public Map getLoginPoints() { + + Map loginPoints = new HashMap<>(); + + for (Map.Entry projectEntries : projects.entrySet()) { + + IConnector connector = projectEntries.getValue().getConnector(); + if (connector == null) { + continue; + } + + String loginPointName = connector.getLoginPointName(); + + if (!loginPoints.containsKey(loginPointName)) { + loginPoints.put(loginPointName, projectEntries.getKey()); + } + } + + return loginPoints; + } } diff --git a/bundles/specmate-emfjson/src/com/specmate/emfjson/EMFJsonSerializer.java b/bundles/specmate-emfjson/src/com/specmate/emfjson/EMFJsonSerializer.java index b8b88213d..e2b0c0136 100644 --- a/bundles/specmate-emfjson/src/com/specmate/emfjson/EMFJsonSerializer.java +++ b/bundles/specmate-emfjson/src/com/specmate/emfjson/EMFJsonSerializer.java @@ -1,6 +1,8 @@ package com.specmate.emfjson; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; @@ -77,10 +79,9 @@ public boolean serializeContainedElements(EObject object) { /** * constructor * - * @param uriFactory - * The IURIFactory that is used for generating URIs from EObjects - * @param stopPredicate - * The stop predicate to indicate where to stop serializing + * @param uriFactory The IURIFactory that is used for generating URIs from + * EObjects + * @param stopPredicate The stop predicate to indicate where to stop serializing */ public EMFJsonSerializer(IURIFactory uriFactory, ISerializationConfiguration config) { this.uriFactory = uriFactory; @@ -90,8 +91,7 @@ public EMFJsonSerializer(IURIFactory uriFactory, ISerializationConfiguration con /** * Serializes an {@link EObject} to JSON * - * @param eObject - * The {@link EObject} to serialize + * @param eObject The {@link EObject} to serialize * @return The JSON representation of object * @throws JSONException * @throws SpecmateException @@ -107,11 +107,9 @@ public JSONObject serialize(EObject eObject) throws JSONException, SpecmateExcep /** * Serializes a list of {@link EObject} to JSON * - * @param list - * The list of {@link EObject}s to serialize + * @param list The list of {@link EObject}s to serialize * @return The JSON representation of list - * @throws SpecmateException - * If the object cannot be serialized + * @throws SpecmateException If the object cannot be serialized */ public JSONArray serialize(List list) throws JSONException, SpecmateException { try { @@ -121,13 +119,27 @@ public JSONArray serialize(List list) throws JSONException, SpecmateException } } + /** + * Serializes a list of {@link EObject} to JSON + * + * @param list The list of {@link EObject}s to serialize + * @return The JSON representation of list + * @throws SpecmateException If the object cannot be serialized + */ + public JSONObject serialize(Map map) throws JSONException, SpecmateException { + try { + return serializeMap(map); + } catch (Exception e) { + throw new SpecmateInternalException(ErrorCode.SERALIZATION, e); + } + } + /** * Serializes an {@link EObject} to JSON at certain serializing depth. Stops * serializing if indicated by {@link ISerializerStopPredicate.stopAtDepth} from * the currently set stop predicate. * - * @param eObject - * The {@link EObject} to serialize + * @param eObject The {@link EObject} to serialize * @return The JSON representation of eObject * @throws SpecmateException */ @@ -144,10 +156,9 @@ private JSONObject serializeObject(EObject eObject) throws SpecmateException { * Serializes the type informations (namespace URI and class name) of eObject to * the given {@link JSONObject}. * - * @param eObject - * The {@link EObject} for which to serialize the type information - * @param jsonObj - * The JSON object where to put the serialized type information. + * @param eObject The {@link EObject} for which to serialize the type + * information + * @param jsonObj The JSON object where to put the serialized type information. * @throws JSONException */ private void serializeType(EObject eObject, JSONObject jsonObj) throws JSONException { @@ -161,10 +172,8 @@ private void serializeType(EObject eObject, JSONObject jsonObj) throws JSONExcep /** * Serializes the URI of eObject into the given {@link JSONObject}. * - * @param eObject - * The {@link EObject} of which to serialize the URI - * @param jsonObj - * The {@link JSONObject} where to put the serialized URI + * @param eObject The {@link EObject} of which to serialize the URI + * @param jsonObj The {@link JSONObject} where to put the serialized URI * @throws SpecmateException */ private void serializeUri(EObject eObject, JSONObject jsonObj) throws SpecmateException { @@ -175,14 +184,15 @@ private void serializeUri(EObject eObject, JSONObject jsonObj) throws SpecmateEx * Serializes a value. EObjects and Lists are handled recursively, any other * type of object is serialized as String. * - * @param value - * The value to serialize + * @param value The value to serialize * @return The JSON representation of value * @throws SpecmateException */ private Object serializeValue(Object value) throws SpecmateException { if (value instanceof EList) { return serializeList((EList) value); + } else if (value instanceof Map) { + return serializeMap((Map) value); } else if (value instanceof EObject) { return serializeObject((EObject) value); } else if (value instanceof Double) { @@ -197,8 +207,7 @@ private Object serializeValue(Object value) throws SpecmateException { /** * Serializes a list of objects * - * @param list - * The list of objects to serialize + * @param list The list of objects to serialize * @return A {@link JSONArray} containing the JSON representation of all members * of list * @throws SpecmateException @@ -211,13 +220,28 @@ private JSONArray serializeList(List list) throws SpecmateException { return array; } + /** + * Serializes a list of objects + * + * @param map The map of objects to serialize + * @return A {@link JSONObject} containing the JSON representation of all + * members of map + * @throws SpecmateException + */ + private JSONObject serializeMap(Map map) throws SpecmateException { + JSONObject jsonobject = new JSONObject(); + for (Entry entry : map.entrySet()) { + jsonobject.put((String) serializeValue(entry.getKey()), serializeValue(entry.getValue())); + } + return jsonobject; + } + /** * Serializes an EObject or a List as proxy JSON structures. That means * valuevalue is not completely serialized but only the URI * inforamtion. * - * @param value - * The value to serialize as proxy + * @param value The value to serialize as proxy * @return A JSON proxy structure * @throws SpecmateException */ @@ -241,8 +265,7 @@ private Object serializeProxy(Object value) throws SpecmateException { * Transforms an {@link EObject} into a JSON proxy structure, i.e. a * {@link JSONObject} that contains the uri of the {@link EObject}. * - * @param eObject - * The {@link EObject} for which to obtain a proxy + * @param eObject The {@link EObject} for which to obtain a proxy * @return The JSON proxy structure * @throws SpecmateException */ @@ -258,10 +281,8 @@ public Object getProxy(EObject eObject) throws SpecmateException { * Serializes all feature of an {@link EObject} into the JSON object * jsonObj. For references the method obtains proxies. * - * @param eObject - * The {@link EObject} for which to serialize all features - * @param jsonObj - * The JSON object where to put all serialization results + * @param eObject The {@link EObject} for which to serialize all features + * @param jsonObj The JSON object where to put all serialization results * @throws JSONException * @throws SpecmateException */ diff --git a/bundles/specmate-emfrest/src/com/specmate/emfrest/authentication/LoginPoints.java b/bundles/specmate-emfrest/src/com/specmate/emfrest/authentication/LoginPoints.java new file mode 100644 index 000000000..fa4e064ff --- /dev/null +++ b/bundles/specmate-emfrest/src/com/specmate/emfrest/authentication/LoginPoints.java @@ -0,0 +1,50 @@ +package com.specmate.emfrest.authentication; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; + +import org.eclipse.emf.ecore.resource.Resource; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +import com.specmate.connectors.api.IProjectService; +import com.specmate.emfrest.api.IRestService; +import com.specmate.emfrest.api.RestServiceBase; +import com.specmate.rest.RestResult; + +@Component(service = IRestService.class) +public class LoginPoints extends RestServiceBase { + public static final String SERVICE_NAME = "loginpoints"; + private IProjectService projectService; + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override + public boolean canGet(Object target) { + return (target instanceof Resource); + } + + @Override + public RestResult get(Object object, MultivaluedMap queryParams, String token) { + + Map loginPoints = projectService.getLoginPoints(); + +// GenericEntity entity = new GenericEntity>(loginPoints){}; +// return new RestResult<>(Response.Status.OK, entity); + + return new RestResult<>(Response.Status.OK, loginPoints ); + } + + @Reference + public void setProjectService(IProjectService projectService) { + this.projectService = projectService; + } +} diff --git a/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/EmfRestJerseyApplication.java b/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/EmfRestJerseyApplication.java index da4151cb7..e7f4eeed6 100644 --- a/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/EmfRestJerseyApplication.java +++ b/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/EmfRestJerseyApplication.java @@ -6,14 +6,15 @@ import com.specmate.emfrest.internal.metrics.MetricsDynamicFeature; import com.specmate.emfrest.internal.rest.JsonEObjectWriter; import com.specmate.emfrest.internal.rest.JsonListWriter; +import com.specmate.emfrest.internal.rest.JsonMapWriter; import com.specmate.emfrest.internal.rest.JsonReader; import com.specmate.emfrest.internal.rest.RootResource; class EmfRestJerseyApplication extends ResourceConfig { public EmfRestJerseyApplication() { - registerClasses(RootResource.class, JsonEObjectWriter.class, JsonListWriter.class, JsonReader.class, - AuthenticationFilter.class, MetricsDynamicFeature.class); + registerClasses(RootResource.class, JsonEObjectWriter.class, JsonListWriter.class, JsonMapWriter.class, + JsonReader.class, AuthenticationFilter.class, MetricsDynamicFeature.class); } } diff --git a/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/auth/AuthenticationFilter.java b/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/auth/AuthenticationFilter.java index f8ed9e5a8..9f95e719e 100644 --- a/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/auth/AuthenticationFilter.java +++ b/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/auth/AuthenticationFilter.java @@ -19,6 +19,7 @@ import com.specmate.auth.api.IAuthenticationService; import com.specmate.common.exception.SpecmateException; import com.specmate.emfrest.authentication.Login; +import com.specmate.emfrest.authentication.LoginPoints; import com.specmate.emfrest.authentication.Logout; import com.specmate.emfrest.authentication.ProjectNames; import com.specmate.model.administration.AdministrationFactory; @@ -32,6 +33,7 @@ public class AuthenticationFilter implements ContainerRequestFilter { private final String HEARTBEAT_PARAMETER = "heartbeat"; private final String REST_URL = ".+services/rest/"; private Pattern loginPattern = Pattern.compile(REST_URL + Login.SERVICE_NAME); + private Pattern loginPointsPattern = Pattern.compile(REST_URL + LoginPoints.SERVICE_NAME); private Pattern logoutPattern = Pattern.compile(REST_URL + Logout.SERVICE_NAME); private Pattern projectNamesPattern = Pattern.compile(REST_URL + ProjectNames.SERVICE_NAME); private Pattern reindexPattern = Pattern.compile(REST_URL + REINDEX_SERVICE_NAME); @@ -54,8 +56,8 @@ public void filter(ContainerRequestContext requestContext) throws IOException { // Validate the Authorization header if (!AuthorizationHeader.isAuthenticationSet(requestContext)) { - logService.log(LogService.LOG_INFO, "No credentials set: on path " - + requestContext.getUriInfo().getAbsolutePath().toString()); + logService.log(LogService.LOG_INFO, + "No credentials set: on path " + requestContext.getUriInfo().getAbsolutePath().toString()); abortWithUnauthorized(requestContext); return; } @@ -104,10 +106,11 @@ private void abortWithUnauthorized(ContainerRequestContext requestContext) { private boolean isNotSecured(ContainerRequestContext requestContext) { String path = requestContext.getUriInfo().getAbsolutePath().toString(); Matcher matcherLogin = loginPattern.matcher(path); + Matcher matcherLoginPoints = loginPointsPattern.matcher(path); Matcher matcherLogout = logoutPattern.matcher(path); Matcher matcherProjectNames = projectNamesPattern.matcher(path); Matcher matcherReindex = reindexPattern.matcher(path); - return matcherLogin.matches() || matcherLogout.matches() || matcherProjectNames.matches() - || matcherReindex.matches(); + return matcherLogin.matches() || matcherLoginPoints.matches() || matcherLogout.matches() + || matcherProjectNames.matches() || matcherReindex.matches(); } } diff --git a/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/rest/JsonMapWriter.java b/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/rest/JsonMapWriter.java new file mode 100644 index 000000000..987cb3b46 --- /dev/null +++ b/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/rest/JsonMapWriter.java @@ -0,0 +1,52 @@ +package com.specmate.emfrest.internal.rest; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.Map; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; + +import org.osgi.service.log.LogService; + +import com.specmate.common.ISerializationConfiguration; +import com.specmate.urihandler.IURIFactory; + +/** MessageBodyWriter for Maps */ +@Provider +public class JsonMapWriter implements MessageBodyWriter> { + + /** The wrapped JsonWriter */ + private JsonWriter writer; + + /** constructor */ + public JsonMapWriter(@Context LogService logService, @Context IURIFactory factory, + @Context ISerializationConfiguration serializationConfig) { + this.writer = new JsonWriter(logService, factory, serializationConfig); + } + + /** {@inheritDoc} */ + @Override + public long getSize(Map obj, Class clazz, Type type, Annotation[] annotation, MediaType mediaType) { + return writer.getSize(obj, clazz, type, annotation, mediaType); + } + + /** {@inheritDoc} */ + @Override + public boolean isWriteable(Class clazz, Type type, Annotation[] annotation, MediaType mediaType) { + return writer.isWriteable(clazz, type, annotation, mediaType); + } + + /** {@inheritDoc} */ + @Override + public void writeTo(Map obj, Class clazz, Type type, Annotation[] annotations, MediaType mediaType, + MultivaluedMap headers, OutputStream stream) throws IOException, WebApplicationException { + writer.writeTo(obj, clazz, type, annotations, mediaType, headers, stream); + } +} diff --git a/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/rest/JsonWriter.java b/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/rest/JsonWriter.java index 9d06c1ea8..1cb7dbf0c 100644 --- a/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/rest/JsonWriter.java +++ b/bundles/specmate-emfrest/src/com/specmate/emfrest/internal/rest/JsonWriter.java @@ -6,6 +6,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.List; +import java.util.Map; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; @@ -45,7 +46,8 @@ public long getSize(Object obj, Class clazz, Type type, Annotation[] annotati /** {@inheritDoc} */ public boolean isWriteable(Class clazz, Type type, Annotation[] annotation, MediaType mediaType) { return mediaType.toString().equals(MEDIA_TYPE) - && (EObject.class.isAssignableFrom(clazz) || List.class.isAssignableFrom(clazz)); + && (EObject.class.isAssignableFrom(clazz) || List.class.isAssignableFrom(clazz) + || Map.class.isAssignableFrom(clazz)); } /** @@ -71,7 +73,14 @@ public void writeTo(Object obj, Class clazz, Type type, Annotation[] annotati logService.log(LogService.LOG_ERROR, "Could not serialize object.", e); throw new WebApplicationException(e); } - } else { + } else if (obj instanceof Map) { + try { + result = serializer.serialize((Map) obj).toString(); + } catch (Exception e) { + logService.log(LogService.LOG_ERROR, "Could not serialize object.", e); + throw new WebApplicationException(e); + } + }else { throw new WebApplicationException("Cannot serialize " + clazz); } diff --git a/bundles/specmate-hp-connector/src/com/specmate/connectors/hpconnector/internal/services/HPConnector.java b/bundles/specmate-hp-connector/src/com/specmate/connectors/hpconnector/internal/services/HPConnector.java index 15592e710..d137ba7b0 100644 --- a/bundles/specmate-hp-connector/src/com/specmate/connectors/hpconnector/internal/services/HPConnector.java +++ b/bundles/specmate-hp-connector/src/com/specmate/connectors/hpconnector/internal/services/HPConnector.java @@ -202,4 +202,9 @@ public void setProject(IProject project) { public void setLogService(LogService logService) { this.logService = logService; } + + @Override + public String getLoginPointName() { + return "Project " + project.getID(); + } } diff --git a/bundles/specmate-jira-connector/src/com/specmate/connectors/jira/internal/services/JiraConnector.java b/bundles/specmate-jira-connector/src/com/specmate/connectors/jira/internal/services/JiraConnector.java index 0b1530d9f..fe9771325 100644 --- a/bundles/specmate-jira-connector/src/com/specmate/connectors/jira/internal/services/JiraConnector.java +++ b/bundles/specmate-jira-connector/src/com/specmate/connectors/jira/internal/services/JiraConnector.java @@ -504,4 +504,9 @@ public IProject getProject() { public void setProject(IProject project) { this.project = project; } + + @Override + public String getLoginPointName() { + return "Jira Server " + this.url; + } } From ab46029efb7870a4f109fcf0ef8e62a5ad92deed Mon Sep 17 00:00:00 2001 From: Sebastian Eder <23170307+sebeder@users.noreply.github.com> Date: Wed, 24 Mar 2021 07:10:04 +0100 Subject: [PATCH 2/3] Fix compile errors after merge --- .../test/integration/support/DummyProjectService.java | 7 +++++++ .../connectors/jira/internal/services/JiraConnector.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bundles/specmate-integration-test/src/com/specmate/test/integration/support/DummyProjectService.java b/bundles/specmate-integration-test/src/com/specmate/test/integration/support/DummyProjectService.java index d60d15fee..e314001b9 100644 --- a/bundles/specmate-integration-test/src/com/specmate/test/integration/support/DummyProjectService.java +++ b/bundles/specmate-integration-test/src/com/specmate/test/integration/support/DummyProjectService.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.osgi.service.component.annotations.Component; @@ -39,4 +40,10 @@ public Map getProjects() { return Collections.unmodifiableMap(projects); } + @Override + public Map getLoginPoints() { + return projects.entrySet().stream() + .collect(Collectors.toMap(k -> k.toString(), v -> v.getValue().getID().toString())); + } + } diff --git a/bundles/specmate-jira-connector/src/com/specmate/connectors/jira/internal/services/JiraConnector.java b/bundles/specmate-jira-connector/src/com/specmate/connectors/jira/internal/services/JiraConnector.java index 43309212f..1c7ea71bd 100644 --- a/bundles/specmate-jira-connector/src/com/specmate/connectors/jira/internal/services/JiraConnector.java +++ b/bundles/specmate-jira-connector/src/com/specmate/connectors/jira/internal/services/JiraConnector.java @@ -517,6 +517,6 @@ public void setProject(IProject project) { @Override public String getLoginPointName() { - return "Jira Server " + this.url; + return "Jira Server " + this.serverUrl; } } From 0927f0842206fd56cfc0603f64fd033b16676618 Mon Sep 17 00:00:00 2001 From: Sebastian Eder <23170307+sebeder@users.noreply.github.com> Date: Wed, 24 Mar 2021 07:10:30 +0100 Subject: [PATCH 3/3] Add loginpoints to UI --- .../data-service/services/service-interface.ts | 5 ++++- .../auth/services/authentication.service.ts | 4 ++++ .../modules/login/components/login.component.html | 4 ++-- .../modules/login/components/login.component.ts | 15 +++++++++++++-- web/src/app/util/url.ts | 4 ++++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/web/src/app/modules/data/modules/data-service/services/service-interface.ts b/web/src/app/modules/data/modules/data-service/services/service-interface.ts index 306fe3f33..b2e598ce6 100644 --- a/web/src/app/modules/data/modules/data-service/services/service-interface.ts +++ b/web/src/app/modules/data/modules/data-service/services/service-interface.ts @@ -29,6 +29,9 @@ export class ServiceInterface { return session; } + public async loginpoints(): Promise<{ [loginpoint: string]: string }> { + return this.http.get<{ [loginpoint: string]: string }>(Url.urlLoginpoints()).toPromise(); + } public async deauthenticate(): Promise { await this.http.get(Url.urlDeauthenticate(), { responseType: 'text' }).toPromise(); @@ -73,7 +76,7 @@ export class ServiceInterface { return await this.http.post(Url.urlCustomService(url, serviceSuffix), payload, { params: urlParams }).toPromise(); } - public async performOperationGET(url: string, serviceSuffix: string, payload: any,parameters: { [key: string]: string }, token: UserToken): Promise { + public async performOperationGET(url: string, serviceSuffix: string, payload: any, parameters: { [key: string]: string }, token: UserToken): Promise { let urlParams = this.toUrlParams(parameters); return await this.http.get(Url.urlCustomService(url, serviceSuffix), { params: urlParams }).toPromise(); } diff --git a/web/src/app/modules/views/main/authentication/modules/auth/services/authentication.service.ts b/web/src/app/modules/views/main/authentication/modules/auth/services/authentication.service.ts index e17de351d..268579deb 100644 --- a/web/src/app/modules/views/main/authentication/modules/auth/services/authentication.service.ts +++ b/web/src/app/modules/views/main/authentication/modules/auth/services/authentication.service.ts @@ -101,6 +101,10 @@ export class AuthenticationService { return this._authChanged; } + public async getLoginpoints(): Promise<{ [loginpoints: string]: string }> { + return this.serviceInterface.loginpoints(); + } + public async authenticate(user: User): Promise { try { const wasAuthenticated: boolean = this.isAuthenticated; diff --git a/web/src/app/modules/views/main/authentication/modules/login/components/login.component.html b/web/src/app/modules/views/main/authentication/modules/login/components/login.component.html index 4b8cf13e6..5f2597436 100644 --- a/web/src/app/modules/views/main/authentication/modules/login/components/login.component.html +++ b/web/src/app/modules/views/main/authentication/modules/login/components/login.component.html @@ -46,8 +46,8 @@

{{'login' | translate}}

{{project ? project : ('project' | translate)}}
- +
diff --git a/web/src/app/modules/views/main/authentication/modules/login/components/login.component.ts b/web/src/app/modules/views/main/authentication/modules/login/components/login.component.ts index bf903f630..f766e0d3d 100644 --- a/web/src/app/modules/views/main/authentication/modules/login/components/login.component.ts +++ b/web/src/app/modules/views/main/authentication/modules/login/components/login.component.ts @@ -13,12 +13,23 @@ export class Login implements OnInit { public username = ''; public password = ''; public _project = ''; - public projectnames: string[]; + public loginpoints: { name: string, defaultProject: string }[]; public isAuthenticating = false; constructor(private auth: AuthenticationService, private navigator: NavigatorService) { - auth.getProjectNames().then(res => this.projectnames = res); + auth.getLoginpoints().then(res => this.loginpoints = this.translateLoginpoints(res)); + } + + private translateLoginpoints(loginpoints: { [loginpoint: string]: string }): { name: string, defaultProject: string }[] { + const result = []; + for (const entry in loginpoints) { + result.push({ + name: entry, + defaultProject: loginpoints[entry] + }); + } + return result; } public get project(): string { diff --git a/web/src/app/util/url.ts b/web/src/app/util/url.ts index 0ef13721c..275b5a93f 100644 --- a/web/src/app/util/url.ts +++ b/web/src/app/util/url.ts @@ -180,4 +180,8 @@ export class Url { public static urlProjectNames(): string { return Url.build([Config.URL_BASE, 'projectnames']); } + + public static urlLoginpoints(): string { + return Url.build([Config.URL_BASE, 'loginpoints']); + } }