diff --git a/li.strolch.rest/.gitignore b/li.strolch.rest/.gitignore new file mode 100644 index 000000000..43054f9b5 --- /dev/null +++ b/li.strolch.rest/.gitignore @@ -0,0 +1,5 @@ +target/ +.project +.settings +.classpath +.DS_Store diff --git a/li.strolch.rest/LICENSE b/li.strolch.rest/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/li.strolch.rest/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/li.strolch.rest/README.md b/li.strolch.rest/README.md new file mode 100644 index 000000000..419787e2a --- /dev/null +++ b/li.strolch.rest/README.md @@ -0,0 +1,6 @@ +li.strolch.rest +================== + +[![Build Status](http://jenkins.eitchnet.ch/buildStatus/icon?job=li.strolch.rest)](http://jenkins.eitchnet.ch/view/strolch/job/li.strolch.rest/) + +Restful Web Service API for Strolch diff --git a/li.strolch.rest/pom.xml b/li.strolch.rest/pom.xml new file mode 100644 index 000000000..6f984614b --- /dev/null +++ b/li.strolch.rest/pom.xml @@ -0,0 +1,166 @@ + + 4.0.0 + + + li.strolch + li.strolch.parent + 1.0.0-SNAPSHOT + ../li.strolch.parent/pom.xml + + + li.strolch.rest + + li.strolch.rest + Restful Web Service API for Strolch + + https://github.com/eitchnet/li.strolch.rest + + 2011 + + + Github Issues + https://github.com/eitchnet/li.strolch.rest/issues + + + + scm:git:https://github.com/eitchnet/li.strolch.rest.git + scm:git:git@github.com:eitch/li.strolch.rest.git + https://github.com/eitchnet/li.strolch.rest + + + + 2.11 + + + + + + + org.glassfish.jersey + jersey-bom + ${jersey.version} + pom + import + + + + + + + + + + + + + + + + + + + li.strolch + li.strolch.model + + + li.strolch + li.strolch.agent + + + li.strolch + li.strolch.service + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + + org.glassfish.jersey.containers + + jersey-container-servlet + + + org.glassfish.jersey.media + jersey-media-moxy + + + + + li.strolch + li.strolch.testbase + test + + + + org.glassfish.jersey.test-framework + jersey-test-framework-core + test + + + org.glassfish.jersey.containers + jersey-container-grizzly2-servlet + test + + + org.glassfish.jersey.containers + jersey-container-grizzly2-http + test + + + org.glassfish.jersey.test-framework.providers + jersey-test-framework-provider-bundle + pom + test + + + + + + + + src/main/resources + true + + **/componentVersion.properties + + + + + + org.codehaus.mojo + buildnumber-maven-plugin + + + org.apache.maven.plugins + maven-eclipse-plugin + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.apache.maven.plugins + maven-source-plugin + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.apache.maven.plugins + maven-site-plugin + + + + \ No newline at end of file diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/DefaultStrolchSessionHandler.java b/li.strolch.rest/src/main/java/li/strolch/rest/DefaultStrolchSessionHandler.java new file mode 100644 index 000000000..bfef478d4 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/DefaultStrolchSessionHandler.java @@ -0,0 +1,129 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest; + +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; + +import li.strolch.agent.api.ComponentContainer; +import li.strolch.agent.api.StrolchComponent; +import li.strolch.exception.StrolchException; +import li.strolch.runtime.configuration.ComponentConfiguration; +import li.strolch.runtime.privilege.PrivilegeHandler; +import ch.eitchnet.privilege.model.Certificate; +import ch.eitchnet.utils.dbc.DBC; + +/** + * @author Robert von Burg + */ +public class DefaultStrolchSessionHandler extends StrolchComponent implements StrolchSessionHandler { + + private static final String PARAM_SESSION_ORIGIN = "session.origin"; //$NON-NLS-1$ + private static final String PARAM_VALIDATE_ORIGIN = "validateOrigin"; //$NON-NLS-1$ + private PrivilegeHandler privilegeHandler; + private Map certificateMap; + private boolean validateOrigin; + + /** + * @param container + * @param componentName + */ + public DefaultStrolchSessionHandler(ComponentContainer container, String componentName) { + super(container, componentName); + } + + @Override + public void initialize(ComponentConfiguration configuration) { + this.validateOrigin = configuration.getBoolean(PARAM_VALIDATE_ORIGIN, false); + super.initialize(configuration); + } + + @Override + public void start() { + this.privilegeHandler = getContainer().getComponent(PrivilegeHandler.class); + this.certificateMap = new HashMap<>(); + super.start(); + } + + @Override + public void stop() { + if (this.certificateMap != null) { + for (Certificate certificate : this.certificateMap.values()) { + this.privilegeHandler.invalidateSession(certificate); + } + this.certificateMap.clear(); + } + this.privilegeHandler = null; + super.stop(); + } + + @Override + public void destroy() { + this.certificateMap = null; + super.destroy(); + } + + @Override + public Certificate authenticate(String origin, String username, byte[] password) { + DBC.PRE.assertNotEmpty("Origin must be set!", username); //$NON-NLS-1$ + DBC.PRE.assertNotEmpty("Username must be set!", username); //$NON-NLS-1$ + DBC.PRE.assertNotNull("Passwort must be set", password); //$NON-NLS-1$ + + Certificate certificate = this.privilegeHandler.authenticate(username, password); + certificate.getSessionDataMap().put(PARAM_SESSION_ORIGIN, origin); + this.certificateMap.put(certificate.getAuthToken(), certificate); + + return certificate; + } + + @Override + public Certificate validate(String origin, String authToken) { + DBC.PRE.assertNotEmpty("Origin must be set!", origin); //$NON-NLS-1$ + DBC.PRE.assertNotEmpty("SessionId must be set!", authToken); //$NON-NLS-1$ + + Certificate certificate = this.certificateMap.get(authToken); + if (certificate == null) + throw new StrolchException(MessageFormat.format("No certificate exists for sessionId {0}", authToken)); //$NON-NLS-1$ + + this.privilegeHandler.isCertificateValid(certificate); + + if (this.validateOrigin && !origin.equals(certificate.getSessionDataMap().get(PARAM_SESSION_ORIGIN))) { + String msg = MessageFormat.format("Illegal request for origin {0} and sessionId {1}", origin, authToken); //$NON-NLS-1$ + throw new StrolchException(msg); + } + + return certificate; + } + + @Override + public void invalidateSession(String origin, Certificate certificate) { + DBC.PRE.assertNotEmpty("Origin must be set!", origin); //$NON-NLS-1$ + DBC.PRE.assertNotNull("Certificate must bet given!", certificate); //$NON-NLS-1$ + + if (this.validateOrigin && !origin.equals(certificate.getSessionDataMap().get(PARAM_SESSION_ORIGIN))) { + String msg = MessageFormat.format("Illegal request for origin {0} and sessionId {1}", origin, //$NON-NLS-1$ + certificate.getAuthToken()); + throw new StrolchException(msg); + } + + Certificate removedCert = this.certificateMap.remove(certificate.getAuthToken()); + if (removedCert == null) + logger.error(MessageFormat.format("No session was registered with token {0}", certificate.getAuthToken())); //$NON-NLS-1$ + + this.privilegeHandler.invalidateSession(certificate); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/RestfulStrolchComponent.java b/li.strolch.rest/src/main/java/li/strolch/rest/RestfulStrolchComponent.java new file mode 100644 index 000000000..a875c7572 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/RestfulStrolchComponent.java @@ -0,0 +1,88 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest; + +import li.strolch.agent.api.ComponentContainer; +import li.strolch.agent.api.StrolchComponent; +import li.strolch.rest.filters.AccessControlResponseFilter; +import li.strolch.runtime.configuration.ComponentConfiguration; +import li.strolch.runtime.privilege.PrivilegeHandler; +import ch.eitchnet.utils.dbc.DBC; + +/** + * @author Robert von Burg + */ +public class RestfulStrolchComponent extends StrolchComponent { + + private static final String PARAM_CORS_ENABLED = "corsEnabled"; //$NON-NLS-1$ + private static final String PARAM_CORS_ORIGIN = "corsOrigin"; //$NON-NLS-1$ + private static RestfulStrolchComponent instance; + + /** + * @param container + * @param componentName + */ + public RestfulStrolchComponent(ComponentContainer container, String componentName) { + super(container, componentName); + } + + @Override + public void initialize(ComponentConfiguration configuration) { + + if (configuration.getBoolean(PARAM_CORS_ENABLED, Boolean.FALSE)) { + String origin = configuration.getString(PARAM_CORS_ORIGIN, null); + logger.info("Enabling CORS for origin: " + origin); //$NON-NLS-1$ + AccessControlResponseFilter.setCorsEnabled(true); + AccessControlResponseFilter.setOrigin(origin); + } + + super.initialize(configuration); + } + + @Override + public void start() { + DBC.PRE.assertNull("Instance is already set! This component is a singleton resource!", instance); //$NON-NLS-1$ + instance = this; + super.start(); + } + + @Override + public void stop() { + instance = null; + super.stop(); + } + + /** + * @return the RestfulStrolchComponent + */ + public static RestfulStrolchComponent getInstance() { + DBC.PRE.assertNotNull("Not yet initialized!", instance); //$NON-NLS-1$ + return instance; + } + + @Override + public ComponentContainer getContainer() { + return super.getContainer(); + } + + public T getComponent(Class clazz) { + return getContainer().getComponent(clazz); + } + + public PrivilegeHandler getPrivilegeHandler() { + return getContainer().getPrivilegeHandler(); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/StrolchRestfulClasses.java b/li.strolch.rest/src/main/java/li/strolch/rest/StrolchRestfulClasses.java new file mode 100644 index 000000000..ec43201f4 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/StrolchRestfulClasses.java @@ -0,0 +1,62 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import li.strolch.rest.endpoint.AuthenticationService; +import li.strolch.rest.endpoint.EnumQuery; +import li.strolch.rest.endpoint.Inspector; +import li.strolch.rest.endpoint.VersionQuery; +import li.strolch.rest.filters.AccessControlResponseFilter; +import li.strolch.rest.filters.AuthenicationRequestFilter; +import li.strolch.rest.filters.AuthenicationResponseFilter; + +/** + * @author Robert von Burg + */ +public class StrolchRestfulClasses { + + public static Set> restfulClasses; + public static Set> providerClasses; + + static { + Set> restfulClasses = new HashSet<>(); + restfulClasses.add(AuthenticationService.class); + restfulClasses.add(Inspector.class); + restfulClasses.add(VersionQuery.class); + restfulClasses.add(EnumQuery.class); + + Set> providerClasses = new HashSet<>(); + providerClasses.add(StrolchRestfulExceptionMapper.class); + providerClasses.add(AccessControlResponseFilter.class); + providerClasses.add(AuthenicationRequestFilter.class); + providerClasses.add(AuthenicationResponseFilter.class); + + StrolchRestfulClasses.restfulClasses = Collections.unmodifiableSet(restfulClasses); + StrolchRestfulClasses.providerClasses = Collections.unmodifiableSet(providerClasses); + } + + public static Set> getRestfulClasses() { + return restfulClasses; + } + + public static Set> getProviderClasses() { + return providerClasses; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/StrolchRestfulConstants.java b/li.strolch.rest/src/main/java/li/strolch/rest/StrolchRestfulConstants.java new file mode 100644 index 000000000..c05b3ac6c --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/StrolchRestfulConstants.java @@ -0,0 +1,24 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest; + +/** + * @author Robert von Burg + */ +public class StrolchRestfulConstants { + + public static final String STROLCH_CERTIFICATE = "strolch.certificate"; //$NON-NLS-1$ +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/StrolchRestfulExceptionMapper.java b/li.strolch.rest/src/main/java/li/strolch/rest/StrolchRestfulExceptionMapper.java new file mode 100644 index 000000000..15d4cedd8 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/StrolchRestfulExceptionMapper.java @@ -0,0 +1,25 @@ +package li.strolch.rest; + +import java.text.MessageFormat; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ch.eitchnet.utils.helper.StringHelper; + +@Provider +public class StrolchRestfulExceptionMapper implements ExceptionMapper { + + private static final Logger logger = LoggerFactory.getLogger(StrolchRestfulExceptionMapper.class); + + @Override + public Response toResponse(Exception ex) { + logger.error(MessageFormat.format("Handling exception {0}", ex.getClass()), ex); //$NON-NLS-1$ + return Response.status(500).entity(StringHelper.formatException(ex)).type(MediaType.TEXT_PLAIN).build(); + } +} \ No newline at end of file diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/StrolchSessionHandler.java b/li.strolch.rest/src/main/java/li/strolch/rest/StrolchSessionHandler.java new file mode 100644 index 000000000..ab228549d --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/StrolchSessionHandler.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest; + +import ch.eitchnet.privilege.model.Certificate; + +/** + * @author Robert von Burg + */ +public interface StrolchSessionHandler { + + public Certificate authenticate(String origin, String username, byte[] password); + + public Certificate validate(String origin, String authToken); + + public void invalidateSession(String origin, Certificate certificate); +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java new file mode 100644 index 000000000..5852eda62 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java @@ -0,0 +1,156 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.endpoint; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import li.strolch.exception.StrolchException; +import li.strolch.rest.RestfulStrolchComponent; +import li.strolch.rest.StrolchSessionHandler; +import li.strolch.rest.helper.RestfulHelper; +import li.strolch.rest.model.Login; +import li.strolch.rest.model.LoginResult; +import li.strolch.rest.model.LogoutResult; +import li.strolch.runtime.privilege.PrivilegeHandler; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ch.eitchnet.privilege.base.PrivilegeException; +import ch.eitchnet.privilege.model.Certificate; +import ch.eitchnet.privilege.model.PrivilegeContext; +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + */ +@Path("strolch/authentication") +public class AuthenticationService { + + private static final Logger logger = LoggerFactory.getLogger(AuthenticationService.class); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response login(Login login, @Context HttpServletRequest request, @Context HttpHeaders headers) { + + LoginResult loginResult = new LoginResult(); + GenericEntity entity = new GenericEntity(loginResult, LoginResult.class) { + // + }; + + try { + + StringBuilder sb = new StringBuilder(); + if (StringHelper.isEmpty(login.getUsername())) { + sb.append("Username was not given. "); //$NON-NLS-1$ + } + if (StringHelper.isEmpty(login.getPassword())) { + sb.append("Password was not given."); //$NON-NLS-1$ + } + + if (sb.length() != 0) { + loginResult.setMsg(MessageFormat.format("Could not log in due to: {0}", sb.toString())); //$NON-NLS-1$ + return Response.status(Status.UNAUTHORIZED).entity(loginResult).build(); + } + + StrolchSessionHandler sessionHandler = RestfulStrolchComponent.getInstance().getComponent( + StrolchSessionHandler.class); + String origin = request == null ? "test" : request.getRemoteAddr(); //$NON-NLS-1$ + Certificate certificate = sessionHandler.authenticate(origin, login.getUsername(), login.getPassword() + .getBytes()); + + Locale locale = RestfulHelper.getLocale(headers); + certificate.setLocale(locale); + + PrivilegeHandler privilegeHandler = RestfulStrolchComponent.getInstance().getPrivilegeHandler(); + PrivilegeContext privilegeContext = privilegeHandler.getPrivilegeContext(certificate); + loginResult.setSessionId(certificate.getAuthToken()); + loginResult.setUsername(certificate.getUsername()); + loginResult.setLocale(locale.toString()); + loginResult.setParameters(certificate.getPropertyMap()); + + List allowList = privilegeContext.getFlatAllowList(); + if (allowList.isEmpty()) + loginResult.setPrivileges(Arrays.asList("*")); //$NON-NLS-1$ + else + loginResult.setPrivileges(allowList); + + return Response.ok().entity(entity).build(); + + } catch (StrolchException e) { + logger.error(e.getMessage(), e); + loginResult.setMsg(MessageFormat.format("Could not log in due to: {0}", e.getMessage())); //$NON-NLS-1$ + return Response.status(Status.UNAUTHORIZED).entity(entity).build(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + String msg = e.getMessage(); + loginResult.setMsg(MessageFormat.format("{0}: {1}", e.getClass().getName(), msg)); //$NON-NLS-1$ + return Response.serverError().entity(entity).build(); + } + } + + @DELETE + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("{authToken}") + public Response logout(@PathParam("authToken") String authToken, @Context HttpServletRequest request) { + + LogoutResult logoutResult = new LogoutResult(); + + GenericEntity entity = new GenericEntity(logoutResult, LogoutResult.class) { + // + }; + try { + + StrolchSessionHandler sessionHandlerHandler = RestfulStrolchComponent.getInstance().getComponent( + StrolchSessionHandler.class); + String origin = request == null ? "test" : request.getRemoteAddr(); //$NON-NLS-1$ + Certificate certificate = sessionHandlerHandler.validate(origin, authToken); + sessionHandlerHandler.invalidateSession(origin, certificate); + + logoutResult.setMsg(MessageFormat.format("{0} has been logged out.", certificate.getUsername())); //$NON-NLS-1$ + return Response.ok().entity(entity).build(); + + } catch (StrolchException | PrivilegeException e) { + logger.error(e.getMessage(), e); + logoutResult.setMsg(MessageFormat.format("Could not logout due to: {0}", e.getMessage())); //$NON-NLS-1$ + return Response.status(Status.UNAUTHORIZED).entity(entity).build(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + String msg = e.getMessage(); + logoutResult.setMsg(MessageFormat.format("{0}: {1}", e.getClass().getName(), msg)); //$NON-NLS-1$ + return Response.serverError().entity(entity).build(); + } + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/EnumQuery.java b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/EnumQuery.java new file mode 100644 index 000000000..1c7f2cfd1 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/EnumQuery.java @@ -0,0 +1,75 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.endpoint; + +import java.util.Locale; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import li.strolch.rest.RestfulStrolchComponent; +import li.strolch.rest.StrolchRestfulConstants; +import li.strolch.rest.helper.RestfulHelper; +import li.strolch.runtime.query.enums.EnumHandler; +import li.strolch.runtime.query.enums.StrolchEnum; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ch.eitchnet.privilege.model.Certificate; + +/** + * @author Robert von Burg + */ +@Path("strolch/enums") +public class EnumQuery { + + private static final Logger logger = LoggerFactory.getLogger(EnumQuery.class); + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{name}") + public Response getEnum(@PathParam("name") String name, @Context HttpServletRequest request, + @Context HttpHeaders headers) { + + try { + + EnumHandler enumHandler = RestfulStrolchComponent.getInstance().getContainer() + .getComponent(EnumHandler.class); + + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + Locale locale = RestfulHelper.getLocale(headers); + StrolchEnum strolchEnum = enumHandler.getEnum(cert, name, locale); + + GenericEntity entity = new GenericEntity(strolchEnum, StrolchEnum.class) { + // + }; + return Response.ok().entity(entity).build(); + + } catch (Exception e) { + logger.error(e.getMessage(), e); + return Response.serverError().entity(e.getMessage()).build(); + } + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/Inspector.java b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/Inspector.java new file mode 100644 index 000000000..99a56c64b --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/Inspector.java @@ -0,0 +1,393 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.endpoint; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import li.strolch.agent.api.ComponentContainer; +import li.strolch.agent.api.OrderMap; +import li.strolch.agent.api.ResourceMap; +import li.strolch.exception.StrolchException; +import li.strolch.model.Order; +import li.strolch.model.Resource; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.rest.RestfulStrolchComponent; +import li.strolch.rest.StrolchRestfulConstants; +import li.strolch.rest.model.AgentOverview; +import li.strolch.rest.model.ElementMapOverview; +import li.strolch.rest.model.ElementMapType; +import li.strolch.rest.model.ElementMapsOverview; +import li.strolch.rest.model.OrderDetail; +import li.strolch.rest.model.OrderOverview; +import li.strolch.rest.model.RealmDetail; +import li.strolch.rest.model.RealmOverview; +import li.strolch.rest.model.ResourceDetail; +import li.strolch.rest.model.ResourceOverview; +import li.strolch.rest.model.StrolchElementOverview; +import li.strolch.rest.model.TypeDetail; +import li.strolch.rest.model.TypeOverview; +import ch.eitchnet.privilege.model.Certificate; + +/** + * @author Robert von Burg + */ +@Path("strolch/inspector") +public class Inspector { + + private StrolchTransaction openTx(Certificate certificate, String realm) { + return RestfulStrolchComponent.getInstance().getContainer().getRealm(realm) + .openTx(certificate, Inspector.class); + } + + /** + *

+ * Root path of the inspector + *

+ * + *

+ * Returns the root element, which is an overview of the configured realms + *

+ * + * @return the root element, which is an overview of the configured realms + * + * @see AgentOverview + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getAgent(@Context HttpServletRequest request) { + try { + ComponentContainer container = RestfulStrolchComponent.getInstance().getContainer(); + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + + Set realmNames = container.getRealmNames(); + List realmOverviews = new ArrayList<>(realmNames.size()); + for (String realmName : realmNames) { + + try (StrolchTransaction tx = openTx(cert, realmName)) { + long size = 0; + size += tx.getResourceMap().querySize(tx); + size += tx.getOrderMap().querySize(tx); + RealmOverview realmOverview = new RealmOverview(realmName, size); + realmOverviews.add(realmOverview); + } + } + + AgentOverview agentOverview = new AgentOverview(realmOverviews); + GenericEntity entity = new GenericEntity(agentOverview, AgentOverview.class) { + // + }; + return Response.ok().entity(entity).build(); + } catch (Exception e) { + //e.printStackTrace(); + throw e; + } + } + + /** + *

+ * Realm inspector + *

+ * + *

+ * Returns the overview of a specific relam + *

+ * + * @param realm + * the realm for which the overview is to be returned + * + * @return the overview of a specific relam + * + * @see RealmDetail + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{realm}") + public Response getRealm(@PathParam("realm") String realm, @Context HttpServletRequest request) { + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + + List elementMapOverviews = new ArrayList<>(2); + try (StrolchTransaction tx = openTx(cert, realm)) { + + ResourceMap resourceMap = tx.getResourceMap(); + ElementMapsOverview resourceOverview = new ElementMapsOverview(ElementMapType.RESOURCE); + resourceOverview.setNrOfElements(resourceMap.querySize(tx)); + resourceOverview.setTypes(resourceMap.getTypes(tx)); + elementMapOverviews.add(resourceOverview); + + OrderMap orderMap = tx.getOrderMap(); + ElementMapsOverview orderOverview = new ElementMapsOverview(ElementMapType.ORDER); + orderOverview.setNrOfElements(orderMap.querySize(tx)); + orderOverview.setTypes(orderMap.getTypes(tx)); + elementMapOverviews.add(orderOverview); + } + + RealmDetail modelOverview = new RealmDetail(elementMapOverviews); + GenericEntity entity = new GenericEntity(modelOverview, RealmDetail.class) { + // + }; + return Response.ok().entity(entity).build(); + } + + /** + *

+ * Resource inspector + *

+ *

+ * Returns an overview of the {@link Resource Resources}. This is a list of all the types and the size each type has + *

+ * + * @param realm + * the realm for which the resource overview is to be returned + * + * @return an overview of the {@link Resource Resources}. This is a list of all the types and the size each type has + * + * @see ElementMapOverview + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{realm}/resource") + public Response getResourcesOverview(@PathParam("realm") String realm, @Context HttpServletRequest request) { + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + + ElementMapOverview resourcesOverview; + try (StrolchTransaction tx = openTx(cert, realm)) { + ResourceMap resourceMap = tx.getResourceMap(); + List types = new ArrayList<>(resourceMap.getTypes(tx)); + Collections.sort(types); + List typeOverviews = new ArrayList<>(types.size()); + for (String type : types) { + long size = resourceMap.querySize(tx, type); + TypeOverview typeOverview = new TypeOverview(type, size); + typeOverviews.add(typeOverview); + } + + resourcesOverview = new ElementMapOverview(ElementMapType.RESOURCE.getName(), typeOverviews); + } + + GenericEntity entity = new GenericEntity(resourcesOverview, + ElementMapOverview.class) { + // + }; + return Response.ok().entity(entity).build(); + } + + /** + *

+ * Order inspector + *

+ *

+ * Returns an overview of the {@link Order Orders}. This is a list of all the types and the size each type has + *

+ * + * @param realm + * the realm for which the order overview is to be returned + * + * @return an overview of the {@link Order Orders}. This is a list of all the types and the size each type has + * + * @see ElementMapOverview + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{realm}/order") + public Response getOrdersOverview(@PathParam("realm") String realm, @Context HttpServletRequest request) { + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + + ElementMapOverview ordersOverview; + try (StrolchTransaction tx = openTx(cert, realm)) { + OrderMap orderMap = tx.getOrderMap(); + List types = new ArrayList<>(orderMap.getTypes(tx)); + Collections.sort(types); + List typeOverviews = new ArrayList<>(types.size()); + for (String type : types) { + long size = orderMap.querySize(tx, type); + TypeOverview typeOverview = new TypeOverview(type, size); + typeOverviews.add(typeOverview); + } + + ordersOverview = new ElementMapOverview(ElementMapType.ORDER.getName(), typeOverviews); + } + + GenericEntity entity = new GenericEntity(ordersOverview, + ElementMapOverview.class) { + // + }; + return Response.ok().entity(entity).build(); + } + + // TODO for the get element type details, we should not simply query all objects, but rather find a solution to query only the id, name, type and date, state for the order + + /** + *

+ * Resource type inspector + *

+ *

+ * Returns an overview of the {@link Resource Resources} with the given type. This is a list of overviews of the + * resources + *

+ * + * @param realm + * the realm for which the resource type overview is to be returned + * @param type + * + * @return an overview of the {@link Resource Resources} with the given type. This is a list of overviews of the + * resources + * + * @see TypeDetail + * @see StrolchElementOverview + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{realm}/resource/{type}") + public Response getResourceTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type, + @Context HttpServletRequest request) { + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + + TypeDetail typeDetail; + try (StrolchTransaction tx = openTx(cert, realm)) { + List byType = tx.getResourceMap().getElementsBy(tx, type); + List elementOverviews = new ArrayList<>(byType.size()); + for (Resource resource : byType) { + ResourceOverview resourceOverview = new ResourceOverview(resource); + elementOverviews.add(resourceOverview); + } + typeDetail = new TypeDetail(type, elementOverviews); + } + + GenericEntity entity = new GenericEntity(typeDetail, TypeDetail.class) { + // + }; + return Response.ok().entity(entity).build(); + } + + /** + *

+ * Order type inspector + *

+ *

+ * Returns an overview of the {@link Order Orders} with the given type. This is a list of overviews of the orders + *

+ * + * @param realm + * the realm for which the order type overview is to be returned + * @param type + * + * @return an overview of the {@link Order Orders} with the given type. This is a list of overviews of the orders + * + * @see TypeDetail + * @see StrolchElementOverview + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{realm}/order/{type}") + public Response getOrderTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type, + @Context HttpServletRequest request) { + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + + TypeDetail typeDetail; + try (StrolchTransaction tx = openTx(cert, realm)) { + List byType = tx.getOrderMap().getElementsBy(tx, type); + List elementOverviews = new ArrayList<>(byType.size()); + for (Order order : byType) { + OrderOverview orderOverview = new OrderOverview(order); + elementOverviews.add(orderOverview); + } + typeDetail = new TypeDetail(type, elementOverviews); + } + + GenericEntity entity = new GenericEntity(typeDetail, TypeDetail.class) { + // + }; + return Response.ok().entity(entity).build(); + } + + /** + *

+ * Resource inspector + *

+ * + *

+ * Returns the resource with the given id + *

+ * + * @param realm + * the realm for which the resource is to be returned + * @param type + * the type of the resource + * @param id + * the id of the resource + * + * @return the resource with the given id + * + * @see ResourceDetail + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{realm}/resource/{type}/{id}") + public Response getResource(@PathParam("realm") String realm, @PathParam("type") String type, + @PathParam("id") String id, @Context HttpServletRequest request) { + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + + Resource resource; + try (StrolchTransaction tx = openTx(cert, realm)) { + resource = tx.getResourceMap().getBy(tx, type, id); + } + if (resource == null) { + throw new StrolchException(MessageFormat.format("No Resource exists for {0}/{1}", type, id)); //$NON-NLS-1$ + } + + ResourceDetail resourceDetail = new ResourceDetail(resource); + GenericEntity entity = new GenericEntity(resourceDetail, ResourceDetail.class) { + // + }; + return Response.ok().entity(entity).build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{realm}/order/{type}/{id}") + public Response getOrder(@PathParam("realm") String realm, @PathParam("type") String type, + @PathParam("id") String id, @Context HttpServletRequest request) { + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + + Order order; + try (StrolchTransaction tx = openTx(cert, realm)) { + order = tx.getOrderMap().getBy(tx, type, id); + } + if (order == null) { + throw new StrolchException(MessageFormat.format("No Order exists for {0}/{1}", type, id)); //$NON-NLS-1$ + } + + OrderDetail orderDetail = new OrderDetail(order); + GenericEntity entity = new GenericEntity(orderDetail, OrderDetail.class) { + // + }; + return Response.ok().entity(entity).build(); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/VersionQuery.java b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/VersionQuery.java new file mode 100644 index 000000000..4779be232 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/VersionQuery.java @@ -0,0 +1,55 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.endpoint; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import li.strolch.agent.api.ComponentContainer; +import li.strolch.agent.api.VersionQueryResult; +import li.strolch.rest.RestfulStrolchComponent; +import li.strolch.rest.StrolchRestfulConstants; +import ch.eitchnet.privilege.model.Certificate; + +/** + * @author Robert von Burg + */ +@Path("strolch/version") +public class VersionQuery { + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getVersions(@Context HttpServletRequest request) { + + ComponentContainer container = RestfulStrolchComponent.getInstance().getContainer(); + + Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE); + container.getPrivilegeHandler().isCertificateValid(cert); + + VersionQueryResult versionQueryResult = container.getAgent().getVersion(); + GenericEntity entity = new GenericEntity(versionQueryResult, + VersionQueryResult.class) { + // + }; + return Response.ok().entity(entity).build(); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/filters/AccessControlResponseFilter.java b/li.strolch.rest/src/main/java/li/strolch/rest/filters/AccessControlResponseFilter.java new file mode 100644 index 000000000..3f3325668 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/filters/AccessControlResponseFilter.java @@ -0,0 +1,70 @@ +package li.strolch.rest.filters; + +import java.io.IOException; +import java.text.MessageFormat; + +import javax.annotation.Priority; +import javax.ws.rs.Priorities; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.Provider; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Provider +@Priority(Priorities.HEADER_DECORATOR) +public class AccessControlResponseFilter implements ContainerResponseFilter { + + private static final String ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods"; //$NON-NLS-1$ + private static final String ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers"; //$NON-NLS-1$ + private static final String ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers"; //$NON-NLS-1$ + private static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; //$NON-NLS-1$ + + private static final Logger logger = LoggerFactory.getLogger(AccessControlResponseFilter.class); + + private static boolean corsEnabled; + private static String origin; + private static boolean logged; + + /** + * @param corsEnabled + * the corsEnabled to set + */ + public static void setCorsEnabled(boolean corsEnabled) { + AccessControlResponseFilter.corsEnabled = corsEnabled; + } + + /** + * @param origin + * the origin to set + */ + public static void setOrigin(String origin) { + AccessControlResponseFilter.origin = origin; + } + + @Override + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) + throws IOException { + + if (!corsEnabled) + return; + + if (!logged) { + logged = true; + logger.info(MessageFormat.format("Enabling CORS for origin: {0}", origin)); //$NON-NLS-1$ + } + + MultivaluedMap headers = responseContext.getHeaders(); + + // allow for the configured origin + headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, origin); + + // and set the allowed HTTP headers and methods + headers.add(ACCESS_CONTROL_ALLOW_HEADERS, "Authorization, Origin, X-Requested-With, Content-Type"); //$NON-NLS-1$ + headers.add(ACCESS_CONTROL_EXPOSE_HEADERS, "Location, Content-Disposition"); //$NON-NLS-1$ + headers.add(ACCESS_CONTROL_ALLOW_METHODS, "POST, PUT, GET, DELETE, HEAD, OPTIONS"); //$NON-NLS-1$ + } +} \ No newline at end of file diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/filters/AuthenicationRequestFilter.java b/li.strolch.rest/src/main/java/li/strolch/rest/filters/AuthenicationRequestFilter.java new file mode 100644 index 000000000..d20b09655 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/filters/AuthenicationRequestFilter.java @@ -0,0 +1,48 @@ +/** + * + */ +package li.strolch.rest.filters; + +import static li.strolch.rest.StrolchRestfulConstants.STROLCH_CERTIFICATE; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; + +import li.strolch.rest.RestfulStrolchComponent; +import li.strolch.rest.StrolchSessionHandler; +import ch.eitchnet.privilege.model.Certificate; + +/** + * @author Reto Breitenmoser + * @author Robert von Burg + */ +@Provider +public class AuthenicationRequestFilter implements ContainerRequestFilter { + + @Context + HttpServletRequest request; + + @Override + public void filter(ContainerRequestContext requestContext) throws IOException { + String sessionId = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION); + if (sessionId != null) { + try { + String origin = this.request == null ? "test" : this.request.getRemoteAddr(); //$NON-NLS-1$ + StrolchSessionHandler sessionHandler = RestfulStrolchComponent.getInstance().getComponent( + StrolchSessionHandler.class); + Certificate certificate = sessionHandler.validate(origin, sessionId); + requestContext.setProperty(STROLCH_CERTIFICATE, certificate); + } catch (Exception e) { + requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED) + .entity("User cannot access the resource.").build()); //$NON-NLS-1$ + } + } + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/filters/AuthenicationResponseFilter.java b/li.strolch.rest/src/main/java/li/strolch/rest/filters/AuthenicationResponseFilter.java new file mode 100644 index 000000000..7aeecc1b9 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/filters/AuthenicationResponseFilter.java @@ -0,0 +1,34 @@ +/** + * + */ +package li.strolch.rest.filters; + +import static li.strolch.rest.StrolchRestfulConstants.STROLCH_CERTIFICATE; + +import java.io.IOException; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.ext.Provider; + +import ch.eitchnet.privilege.model.Certificate; + +/** + * @author Reto Breitenmoser + * @author Robert von Burg + */ +@Provider +public class AuthenicationResponseFilter implements ContainerResponseFilter { + + @Override + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) + throws IOException { + + Certificate cert = (Certificate) requestContext.getProperty(STROLCH_CERTIFICATE); + if (cert != null) { + responseContext.getHeaders().add(HttpHeaders.AUTHORIZATION, cert.getAuthToken()); + } + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/filters/CharsetResponseFilter.java b/li.strolch.rest/src/main/java/li/strolch/rest/filters/CharsetResponseFilter.java new file mode 100644 index 000000000..f190319d2 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/filters/CharsetResponseFilter.java @@ -0,0 +1,36 @@ +package li.strolch.rest.filters; + +import java.io.IOException; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.ext.Provider; + +/** + * The JSON generated is not in the same charset as the rest of the response, thus we override it to UTF-8 with this + * response filter + * + * @author Robert von Burg + */ +@Provider +public class CharsetResponseFilter implements ContainerResponseFilter { + + private static final String UTF_8 = "utf-8"; //$NON-NLS-1$ + + @Override + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) + throws IOException { + + MediaType contentType = responseContext.getMediaType(); + if (contentType != null) { + String charset = contentType.getParameters().get(MediaType.CHARSET_PARAMETER); + if (charset == null || !charset.equalsIgnoreCase(UTF_8)) { + contentType = contentType.withCharset(UTF_8); + responseContext.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, contentType.toString()); + } + } + } +} \ No newline at end of file diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/helper/RestfulHelper.java b/li.strolch.rest/src/main/java/li/strolch/rest/helper/RestfulHelper.java new file mode 100644 index 000000000..bd0393b12 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/helper/RestfulHelper.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.helper; + +import java.util.Locale; + +import javax.ws.rs.core.HttpHeaders; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + */ +public class RestfulHelper { + + public static Locale getLocale(HttpHeaders headers) { + Locale locale; + if (headers == null || StringHelper.isEmpty(headers.getHeaderString(HttpHeaders.ACCEPT_LANGUAGE))) + locale = Locale.getDefault(); + else + locale = headers.getAcceptableLanguages().get(0); + + return locale; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/AgentOverview.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/AgentOverview.java new file mode 100644 index 000000000..fe0506c71 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/AgentOverview.java @@ -0,0 +1,88 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.text.MessageFormat; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Agent") +public class AgentOverview { + + @XmlElement(name = "realms") + private List realms; + + public AgentOverview() { + // no-arg constructor for JAXB + } + + public AgentOverview(List realms) { + this.realms = realms; + } + + /** + * @return the realms + */ + public List getRealms() { + return this.realms; + } + + /** + * @param realms + * the realms to set + */ + public void setRealms(List realms) { + this.realms = realms; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.realms == null) ? 0 : this.realms.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AgentOverview other = (AgentOverview) obj; + if (this.realms == null) { + if (other.realms != null) + return false; + } else if (!this.realms.equals(other.realms)) + return false; + return true; + } + + @Override + public String toString() { + return MessageFormat.format("AgentOverview [realms={0}]", this.realms); //$NON-NLS-1$ + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/ElementMapOverview.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/ElementMapOverview.java new file mode 100644 index 000000000..9fb83e490 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/ElementMapOverview.java @@ -0,0 +1,140 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.text.MessageFormat; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "ElementMap") +public class ElementMapOverview { + + @XmlAttribute(name = "elementMapName") + private String elementMapName; + @XmlAttribute(name = "size") + private long size; + @XmlElement(name = "types", type = TypeOverview.class) + private List typeOverviews; + + public ElementMapOverview() { + // no-arg constructor for JAXB + } + + /** + * @param elementMapName + * @param typeOverviews + */ + public ElementMapOverview(String elementMapName, List typeOverviews) { + this.elementMapName = elementMapName; + this.typeOverviews = typeOverviews; + this.size = this.typeOverviews.size(); + } + + /** + * @return the elementMapName + */ + public String getElementMapName() { + return this.elementMapName; + } + + /** + * @param elementMapName + * the elementMapName to set + */ + public void setElementMapName(String elementMapName) { + this.elementMapName = elementMapName; + } + + /** + * @return the size + */ + public long getSize() { + return this.size; + } + + /** + * @param size + * the size to set + */ + public void setSize(long size) { + this.size = size; + } + + /** + * @return the typeOverviews + */ + public List getTypeOverviews() { + return this.typeOverviews; + } + + /** + * @param typeOverviews + * the typeOverviews to set + */ + public void setTypeOverviews(List typeOverviews) { + this.typeOverviews = typeOverviews; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.elementMapName == null) ? 0 : this.elementMapName.hashCode()); + result = prime * result + (int) (this.size ^ (this.size >>> 32)); + result = prime * result + ((this.typeOverviews == null) ? 0 : this.typeOverviews.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ElementMapOverview other = (ElementMapOverview) obj; + if (this.elementMapName == null) { + if (other.elementMapName != null) + return false; + } else if (!this.elementMapName.equals(other.elementMapName)) + return false; + if (this.size != other.size) + return false; + if (this.typeOverviews == null) { + if (other.typeOverviews != null) + return false; + } else if (!this.typeOverviews.equals(other.typeOverviews)) + return false; + return true; + } + + @Override + public String toString() { + return MessageFormat.format( + "ElementMapOverview [elementMapName={0}, size={1}, typeOverviews={2}]", this.elementMapName, //$NON-NLS-1$ + this.size, this.typeOverviews); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/ElementMapType.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/ElementMapType.java new file mode 100644 index 000000000..a4cbbf433 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/ElementMapType.java @@ -0,0 +1,37 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import li.strolch.model.Tags; + +/** + * @author Robert von Burg + */ +public enum ElementMapType { + RESOURCE(Tags.RESOURCE), ORDER(Tags.ORDER); + private String name; + + private ElementMapType(String name) { + this.name = name; + } + + /** + * @return the name + */ + public String getName() { + return this.name; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/ElementMapsOverview.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/ElementMapsOverview.java new file mode 100644 index 000000000..3676ecb2f --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/ElementMapsOverview.java @@ -0,0 +1,181 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "ElementMaps") +public class ElementMapsOverview { + + @XmlAttribute(name = "name") + private String name; + + @XmlAttribute(name = "elementMapType") + private ElementMapType elementMapType; + + @XmlAttribute(name = "nrOfElements") + private long nrOfElements; + + @XmlElement(name = "types") + private Set types; + + public ElementMapsOverview() { + // no-arg constructor for JAXB + } + + /** + * @param elementMapType + */ + public ElementMapsOverview(ElementMapType elementMapType) { + this.elementMapType = elementMapType; + this.name = elementMapType.getName(); + } + + /** + * + * @param elementMapType + * @param nrOfElements + * @param types + */ + public ElementMapsOverview(ElementMapType elementMapType, long nrOfElements, Set types) { + this(elementMapType); + this.nrOfElements = nrOfElements; + this.types = types; + } + + /** + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the elementMapType + */ + public ElementMapType getElementMapType() { + return this.elementMapType; + } + + /** + * @param elementMapType + * the elementMapType to set + */ + public void setElementMapType(ElementMapType elementMapType) { + this.elementMapType = elementMapType; + } + + /** + * @return the types + */ + public Set getTypes() { + return this.types; + } + + /** + * @param types + * the types to set + */ + public void setTypes(Set types) { + this.types = types; + } + + /** + * @return the nrOfElements + */ + public long getNrOfElements() { + return this.nrOfElements; + } + + /** + * @param nrOfElements + * the nrOfElements to set + */ + public void setNrOfElements(long nrOfElements) { + this.nrOfElements = nrOfElements; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.elementMapType == null) ? 0 : this.elementMapType.hashCode()); + result = prime * result + ((this.name == null) ? 0 : this.name.hashCode()); + result = prime * result + (int) (this.nrOfElements ^ (this.nrOfElements >>> 32)); + result = prime * result + ((this.types == null) ? 0 : this.types.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ElementMapsOverview other = (ElementMapsOverview) obj; + if (this.elementMapType != other.elementMapType) + return false; + if (this.name == null) { + if (other.name != null) + return false; + } else if (!this.name.equals(other.name)) + return false; + if (this.nrOfElements != other.nrOfElements) + return false; + if (this.types == null) { + if (other.types != null) + return false; + } else if (!this.types.equals(other.types)) + return false; + return true; + } + + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("ElementMapsOverview [name="); + sb.append(this.name); + sb.append(", elementMapType="); + sb.append(this.elementMapType); + sb.append(", nrOfElements="); + sb.append(this.nrOfElements); + sb.append(", types="); + sb.append(this.types); + sb.append("]"); + return sb.toString(); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/GroupedParameterizedElementDetail.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/GroupedParameterizedElementDetail.java new file mode 100644 index 000000000..a25e8890e --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/GroupedParameterizedElementDetail.java @@ -0,0 +1,102 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +import li.strolch.model.GroupedParameterizedElement; +import li.strolch.model.ParameterBag; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "GroupedParameterizedElement") +@XmlSeeAlso({ ResourceDetail.class, OrderDetail.class }) +public class GroupedParameterizedElementDetail extends StrolchElementDetail { + + @XmlElement(name = "parameterBags", type = ParameterizedElementDetail.class) + private List parameterizedElements; + + public GroupedParameterizedElementDetail() { + // no-arg constructor for JAXB + } + + public GroupedParameterizedElementDetail(String id, String name, String type, + List parameterizedElements) { + super(id, name, type); + this.parameterizedElements = parameterizedElements; + } + + public GroupedParameterizedElementDetail(GroupedParameterizedElement groupedParameterizedElement) { + super(groupedParameterizedElement); + + Set bagKeySet = groupedParameterizedElement.getParameterBagKeySet(); + this.parameterizedElements = new ArrayList<>(bagKeySet.size()); + for (String bagId : bagKeySet) { + ParameterBag parameterBag = groupedParameterizedElement.getParameterBag(bagId); + this.parameterizedElements.add(new ParameterizedElementDetail(parameterBag)); + } + } + + /** + * @return the parameterizedElements + */ + public List getParameterizedElements() { + return this.parameterizedElements; + } + + /** + * @param parameterizedElements + * the parameterizedElements to set + */ + public void setParameterizedElements(List parameterizedElements) { + this.parameterizedElements = parameterizedElements; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.parameterizedElements == null) ? 0 : this.parameterizedElements.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + GroupedParameterizedElementDetail other = (GroupedParameterizedElementDetail) obj; + if (this.parameterizedElements == null) { + if (other.parameterizedElements != null) + return false; + } else if (!this.parameterizedElements.equals(other.parameterizedElements)) + return false; + return true; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/Login.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/Login.java new file mode 100644 index 000000000..7a573e658 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/Login.java @@ -0,0 +1,68 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Login") +public class Login { + + @XmlAttribute + private String username; + @XmlAttribute + private String password; + + public Login() { + // no-arg constructor for JAXB + } + + /** + * @return the username + */ + public String getUsername() { + return this.username; + } + + /** + * @param username + * the username to set + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * @return the password + */ + public String getPassword() { + return this.password; + } + + /** + * @param password + * the password to set + */ + public void setPassword(String password) { + this.password = password; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/LoginResult.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/LoginResult.java new file mode 100644 index 000000000..eaae483ef --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/LoginResult.java @@ -0,0 +1,153 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "LoginResult") +public class LoginResult { + + @XmlAttribute(name = "username") + private String username; + + @XmlAttribute(name = "sessionId") + private String sessionId; + + @XmlAttribute(name = "locale") + private String locale; + + @XmlAttribute(name = "parameters") + private Map parameters; + + @XmlAttribute(name = "msg") + private String msg; + + @XmlAttribute(name = "privileges") + private List privileges; + + public LoginResult() { + // no-arg constructor for JAXB + } + + /** + * @return the username + */ + public String getUsername() { + return this.username; + } + + /** + * @param username + * the username to set + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * @return the sessionId + */ + public String getSessionId() { + return this.sessionId; + } + + /** + * @param sessionId + * the sessionId to set + */ + public void setSessionId(String sessionId) { + this.sessionId = sessionId; + } + + /** + * @return the locale + */ + public String getLocale() { + return this.locale; + } + + /** + * @param locale + * the locale to set + */ + public void setLocale(String locale) { + this.locale = locale; + } + + /** + * @param locale + * the locale to set + */ + public void setLocale(Locale locale) { + this.locale = locale.toString(); + } + + /** + * @return the parameters + */ + public Map getParameters() { + return this.parameters; + } + + /** + * @param parameters + * the parameters to set + */ + public void setParameters(Map parameters) { + this.parameters = parameters; + } + + /** + * @return the msg + */ + public String getMsg() { + return this.msg; + } + + /** + * @param msg + * the msg to set + */ + public void setMsg(String msg) { + this.msg = msg; + } + + /** + * @return the privileges + */ + public List getPrivileges() { + return this.privileges; + } + + /** + * @param privileges + * the privileges to set + */ + public void setPrivileges(List privileges) { + this.privileges = privileges; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/Logout.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/Logout.java new file mode 100644 index 000000000..881e9d144 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/Logout.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.rest.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlRootElement(name = "Logout") +@XmlAccessorType(XmlAccessType.NONE) +public class Logout { + + @XmlAttribute(name = "username") + private String username; + + @XmlAttribute(name = "sessionId") + private String sessionId; + + public Logout() { + // no-arg constructor for JAXB + } + + /** + * @return the username + */ + public String getUsername() { + return this.username; + } + + /** + * @param username + * the username to set + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * @return the sessionId + */ + public String getSessionId() { + return this.sessionId; + } + + /** + * @param sessionId + * the sessionId to set + */ + public void setSessionId(String sessionId) { + this.sessionId = sessionId; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/LogoutResult.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/LogoutResult.java new file mode 100644 index 000000000..db37aa98d --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/LogoutResult.java @@ -0,0 +1,87 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "LogoutResult") +public class LogoutResult { + + @XmlAttribute(name = "username") + private String username; + + @XmlAttribute(name = "sessionId") + private String sessionId; + + @XmlAttribute(name = "msg") + private String msg; + + public LogoutResult() { + // no-arg constructor for JAXB + } + + /** + * @return the msg + */ + public String getMsg() { + return this.msg; + } + + /** + * @param msg + * the msg to set + */ + public void setMsg(String msg) { + this.msg = msg; + } + + /** + * @return the username + */ + public String getUsername() { + return this.username; + } + + /** + * @param username + * the username to set + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * @return the sessionId + */ + public String getSessionId() { + return this.sessionId; + } + + /** + * @param sessionId + * the sessionId to set + */ + public void setSessionId(String sessionId) { + this.sessionId = sessionId; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/OrderDetail.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/OrderDetail.java new file mode 100644 index 000000000..a84590da2 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/OrderDetail.java @@ -0,0 +1,129 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.util.Date; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import li.strolch.model.Order; +import li.strolch.model.State; +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Order") +@XmlType(name = "") +public class OrderDetail extends GroupedParameterizedElementDetail { + + @XmlAttribute(name = "date") + private String date; + @XmlAttribute(name = "state") + private State state; + + public OrderDetail() { + // no-arg constructor for JAXB + } + + /** + * @param id + * @param name + * @param type + * @param date + * @param state + * @param parameterizedElementDetails + */ + public OrderDetail(String id, String name, String type, Date date, State state, + List parameterizedElementDetails) { + super(id, name, type, parameterizedElementDetails); + this.state = state; + this.date = ISO8601FormatFactory.getInstance().formatDate(date); + } + + /** + * @param order + */ + public OrderDetail(Order order) { + super(order); + this.state = order.getState(); + this.date = ISO8601FormatFactory.getInstance().formatDate(order.getDate()); + } + + /** + * @return the date + */ + public String getDate() { + return this.date; + } + + /** + * @param date + * the date to set + */ + public void setDate(String date) { + this.date = date; + } + + /** + * @return the state + */ + public State getState() { + return this.state; + } + + /** + * @param state + * the state to set + */ + public void setState(State state) { + this.state = state; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.date == null) ? 0 : this.date.hashCode()); + result = prime * result + ((this.state == null) ? 0 : this.state.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + OrderDetail other = (OrderDetail) obj; + if (this.date == null) { + if (other.date != null) + return false; + } else if (!this.date.equals(other.date)) + return false; + if (this.state != other.state) + return false; + return true; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/OrderOverview.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/OrderOverview.java new file mode 100644 index 000000000..46b6581cf --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/OrderOverview.java @@ -0,0 +1,122 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.util.Date; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +import li.strolch.model.Order; +import li.strolch.model.State; +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Order") +public class OrderOverview extends StrolchElementOverview { + + @XmlAttribute(name = "date") + private String date; + @XmlAttribute(name = "state") + private State state; + + public OrderOverview() { + // no-arg constructor for JAXB + } + + /** + * @param id + * @param name + * @param type + */ + public OrderOverview(String id, String name, String type, Date date, State state) { + super(id, name, type); + this.state = state; + this.date = ISO8601FormatFactory.getInstance().formatDate(date); + } + + /** + * @param order + */ + public OrderOverview(Order order) { + super(order); + this.state = order.getState(); + this.date = ISO8601FormatFactory.getInstance().formatDate(order.getDate()); + } + + /** + * @return the date + */ + public String getDate() { + return this.date; + } + + /** + * @param date + * the date to set + */ + public void setDate(String date) { + this.date = date; + } + + /** + * @return the state + */ + public State getState() { + return this.state; + } + + /** + * @param state + * the state to set + */ + public void setState(State state) { + this.state = state; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.date == null) ? 0 : this.date.hashCode()); + result = prime * result + ((this.state == null) ? 0 : this.state.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + OrderOverview other = (OrderOverview) obj; + if (this.date == null) { + if (other.date != null) + return false; + } else if (!this.date.equals(other.date)) + return false; + if (this.state != other.state) + return false; + return true; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/ParameterDetail.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/ParameterDetail.java new file mode 100644 index 000000000..460e013fd --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/ParameterDetail.java @@ -0,0 +1,174 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +import li.strolch.model.parameter.Parameter; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Parameter") +public class ParameterDetail extends StrolchElementDetail { + + @XmlAttribute(name = "hidden") + private boolean hidden; + @XmlAttribute(name = "interpretation") + private String interpretation; + @XmlAttribute(name = "uom") + private String uom; + @XmlAttribute(name = "value") + private String value; + + public ParameterDetail() { + // no-arg constructor for JAXB + } + + /** + * + * @param id + * @param name + * @param type + * @param hidden + * @param interpretation + * @param uom + * @param value + */ + public ParameterDetail(String id, String name, String type, boolean hidden, String interpretation, String uom, + String value) { + super(id, name, type); + this.hidden = hidden; + this.interpretation = interpretation; + this.uom = uom; + this.value = value; + } + + /** + * @param parameter + */ + public ParameterDetail(Parameter parameter) { + super(parameter); + this.hidden = parameter.isHidden(); + this.interpretation = parameter.getInterpretation(); + this.uom = parameter.getUom(); + this.value = parameter.getValueAsString(); + } + + /** + * @return the hidden + */ + public boolean isHidden() { + return this.hidden; + } + + /** + * @param hidden + * the hidden to set + */ + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + + /** + * @return the interpretation + */ + public String getInterpretation() { + return this.interpretation; + } + + /** + * @param interpretation + * the interpretation to set + */ + public void setInterpretation(String interpretation) { + this.interpretation = interpretation; + } + + /** + * @return the uom + */ + public String getUom() { + return this.uom; + } + + /** + * @param uom + * the uom to set + */ + public void setUom(String uom) { + this.uom = uom; + } + + /** + * @return the value + */ + public String getValue() { + return this.value; + } + + /** + * @param value + * the value to set + */ + public void setValue(String value) { + this.value = value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (this.hidden ? 1231 : 1237); + result = prime * result + ((this.interpretation == null) ? 0 : this.interpretation.hashCode()); + result = prime * result + ((this.uom == null) ? 0 : this.uom.hashCode()); + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + ParameterDetail other = (ParameterDetail) obj; + if (this.hidden != other.hidden) + return false; + if (this.interpretation == null) { + if (other.interpretation != null) + return false; + } else if (!this.interpretation.equals(other.interpretation)) + return false; + if (this.uom == null) { + if (other.uom != null) + return false; + } else if (!this.uom.equals(other.uom)) + return false; + if (this.value == null) { + if (other.value != null) + return false; + } else if (!this.value.equals(other.value)) + return false; + return true; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/ParameterizedElementDetail.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/ParameterizedElementDetail.java new file mode 100644 index 000000000..410ae09fb --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/ParameterizedElementDetail.java @@ -0,0 +1,97 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import li.strolch.model.ParameterizedElement; +import li.strolch.model.parameter.Parameter; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "ParameterBag") +public class ParameterizedElementDetail extends StrolchElementDetail { + + @XmlElement(name = "parameters", type = ParameterDetail.class) + private List parameters; + + public ParameterizedElementDetail() { + // no-arg constructor for JAXB + } + + public ParameterizedElementDetail(String id, String name, String type, List parameters) { + super(id, name, type); + this.parameters = parameters; + } + + public ParameterizedElementDetail(ParameterizedElement parameterizedElement) { + super(parameterizedElement); + + List> parameters = parameterizedElement.getParameters(); + this.parameters = new ArrayList<>(parameters.size()); + for (Parameter parameter : parameters) { + this.parameters.add(new ParameterDetail(parameter)); + } + } + + /** + * @return the parameters + */ + public List getParameters() { + return this.parameters; + } + + /** + * @param parameters + * the parameters to set + */ + public void setParameters(List parameters) { + this.parameters = parameters; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.parameters == null) ? 0 : this.parameters.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + ParameterizedElementDetail other = (ParameterizedElementDetail) obj; + if (this.parameters == null) { + if (other.parameters != null) + return false; + } else if (!this.parameters.equals(other.parameters)) + return false; + return true; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/RealmDetail.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/RealmDetail.java new file mode 100644 index 000000000..b741d3b3e --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/RealmDetail.java @@ -0,0 +1,92 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Realm") +public class RealmDetail { + + @XmlElement(name = "elementMaps") + private List elementMapOverviews; + + public RealmDetail() { + // no-arg constructor for JAXB + } + + public RealmDetail(List elementMapOverviews) { + this.elementMapOverviews = elementMapOverviews; + } + + /** + * @return the elementMapOverviews + */ + public List getElementMapOverviews() { + return this.elementMapOverviews; + } + + /** + * @param elementMapOverviews + * the elementMapOverviews to set + */ + public void setElementMapOverviews(List elementMapOverviews) { + this.elementMapOverviews = elementMapOverviews; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.elementMapOverviews == null) ? 0 : this.elementMapOverviews.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RealmDetail other = (RealmDetail) obj; + if (this.elementMapOverviews == null) { + if (other.elementMapOverviews != null) + return false; + } else if (!this.elementMapOverviews.equals(other.elementMapOverviews)) + return false; + return true; + } + + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("RealmDetail [elementMapOverviews="); + sb.append(this.elementMapOverviews); + sb.append("]"); + return sb.toString(); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/RealmOverview.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/RealmOverview.java new file mode 100644 index 000000000..916c110e1 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/RealmOverview.java @@ -0,0 +1,117 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "RealmOverview") +public class RealmOverview { + + @XmlAttribute(name = "realmName") + private String realmName; + @XmlAttribute(name = "size") + private long size; + + public RealmOverview() { + // no-arg constructor for JAXB + } + + /** + * @param realmName + * @param size + */ + public RealmOverview(String realmName, long size) { + this.realmName = realmName; + this.size = size; + } + + /** + * @return the realmName + */ + public String getRealmName() { + return this.realmName; + } + + /** + * @param realmName + * the realmName to set + */ + public void setRealmName(String realmName) { + this.realmName = realmName; + } + + /** + * @return the size + */ + public long getSize() { + return this.size; + } + + /** + * @param size + * the size to set + */ + public void setSize(long size) { + this.size = size; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.realmName == null) ? 0 : this.realmName.hashCode()); + result = prime * result + (int) (this.size ^ (this.size >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RealmOverview other = (RealmOverview) obj; + if (this.realmName == null) { + if (other.realmName != null) + return false; + } else if (!this.realmName.equals(other.realmName)) + return false; + if (this.size != other.size) + return false; + return true; + } + + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("RealmOverview [realmName="); + sb.append(this.realmName); + sb.append(", size="); + sb.append(this.size); + sb.append("]"); + return sb.toString(); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/ResourceDetail.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/ResourceDetail.java new file mode 100644 index 000000000..cc3303df6 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/ResourceDetail.java @@ -0,0 +1,55 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import li.strolch.model.Resource; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Resource") +@XmlType(name = "") +public class ResourceDetail extends GroupedParameterizedElementDetail { + + public ResourceDetail() { + // no-arg constructor for JAXB + } + + /** + * @param id + * @param name + * @param type + * @param parameterizedElements + */ + public ResourceDetail(String id, String name, String type, List parameterizedElements) { + super(id, name, type, parameterizedElements); + } + + /** + * @param resource + */ + public ResourceDetail(Resource resource) { + super(resource); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/ResourceOverview.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/ResourceOverview.java new file mode 100644 index 000000000..5516188c2 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/ResourceOverview.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import li.strolch.model.Resource; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Resource") +public class ResourceOverview extends StrolchElementOverview { + + public ResourceOverview() { + // no-arg constructor for JAXB + } + + /** + * @param id + * @param name + * @param type + */ + public ResourceOverview(String id, String name, String type) { + super(id, name, type); + } + + /** + * @param resource + */ + public ResourceOverview(Resource resource) { + super(resource); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/StrolchElementDetail.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/StrolchElementDetail.java new file mode 100644 index 000000000..18203a718 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/StrolchElementDetail.java @@ -0,0 +1,144 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSeeAlso; + +import li.strolch.model.StrolchElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlSeeAlso({ GroupedParameterizedElementDetail.class, ParameterizedElementDetail.class, ParameterDetail.class }) +public abstract class StrolchElementDetail { + + @XmlAttribute(name = "id", required = true) + private String id; + @XmlAttribute(name = "name", required = true) + private String name; + @XmlAttribute(name = "type", required = true) + private String type; + + public StrolchElementDetail() { + // no-arg constructor for JAXB + } + + /** + * @param id + * @param name + * @param type + */ + public StrolchElementDetail(String id, String name, String type) { + this.id = id; + this.name = name; + this.type = type; + } + + /** + * @param strolchElement + */ + public StrolchElementDetail(StrolchElement strolchElement) { + this.id = strolchElement.getId(); + this.name = strolchElement.getName(); + this.type = strolchElement.getType(); + } + + /** + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * @param id + * the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the type + */ + public String getType() { + return this.type; + } + + /** + * @param type + * the type to set + */ + public void setType(String type) { + this.type = type; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + result = prime * result + ((this.name == null) ? 0 : this.name.hashCode()); + result = prime * result + ((this.type == null) ? 0 : this.type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StrolchElementDetail other = (StrolchElementDetail) obj; + if (this.id == null) { + if (other.id != null) + return false; + } else if (!this.id.equals(other.id)) + return false; + if (this.name == null) { + if (other.name != null) + return false; + } else if (!this.name.equals(other.name)) + return false; + if (this.type == null) { + if (other.type != null) + return false; + } else if (!this.type.equals(other.type)) + return false; + return true; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/StrolchElementOverview.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/StrolchElementOverview.java new file mode 100644 index 000000000..864b2bbaf --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/StrolchElementOverview.java @@ -0,0 +1,144 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSeeAlso; + +import li.strolch.model.StrolchElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlSeeAlso({ ResourceOverview.class, OrderOverview.class }) +public abstract class StrolchElementOverview { + + @XmlAttribute(name = "id", required = true) + private String id; + @XmlAttribute(name = "name", required = true) + private String name; + @XmlAttribute(name = "type", required = true) + private String type; + + public StrolchElementOverview() { + // no-arg constructor for JAXB + } + + /** + * @param id + * @param name + * @param type + */ + public StrolchElementOverview(String id, String name, String type) { + this.id = id; + this.name = name; + this.type = type; + } + + /** + * @param strolchElement + */ + public StrolchElementOverview(StrolchElement strolchElement) { + this.id = strolchElement.getId(); + this.name = strolchElement.getName(); + this.type = strolchElement.getType(); + } + + /** + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * @param id + * the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the type + */ + public String getType() { + return this.type; + } + + /** + * @param type + * the type to set + */ + public void setType(String type) { + this.type = type; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + result = prime * result + ((this.name == null) ? 0 : this.name.hashCode()); + result = prime * result + ((this.type == null) ? 0 : this.type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StrolchElementOverview other = (StrolchElementOverview) obj; + if (this.id == null) { + if (other.id != null) + return false; + } else if (!this.id.equals(other.id)) + return false; + if (this.name == null) { + if (other.name != null) + return false; + } else if (!this.name.equals(other.name)) + return false; + if (this.type == null) { + if (other.type != null) + return false; + } else if (!this.type.equals(other.type)) + return false; + return true; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/TypeDetail.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/TypeDetail.java new file mode 100644 index 000000000..52ec0bcd5 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/TypeDetail.java @@ -0,0 +1,114 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Types") +public class TypeDetail { + + @XmlAttribute(name = "type") + private String type; + + @XmlElements({ @XmlElement(name = "orders", type = OrderOverview.class), + @XmlElement(name = "resources", type = ResourceOverview.class) }) + private List elementOverviews; + + public TypeDetail() { + // no-arg constructor for JAXB + } + + /** + * @param type + * @param elementOverviews + */ + public TypeDetail(String type, List elementOverviews) { + this.type = type; + this.elementOverviews = elementOverviews; + } + + /** + * @return the type + */ + public String getType() { + return this.type; + } + + /** + * @param type + * the type to set + */ + public void setType(String type) { + this.type = type; + } + + /** + * @return the elementOverviews + */ + public List getElementOverviews() { + return this.elementOverviews; + } + + /** + * @param elementOverviews + * the elementOverviews to set + */ + public void setElementOverviews(List elementOverviews) { + this.elementOverviews = elementOverviews; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.elementOverviews == null) ? 0 : this.elementOverviews.hashCode()); + result = prime * result + ((this.type == null) ? 0 : this.type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TypeDetail other = (TypeDetail) obj; + if (this.elementOverviews == null) { + if (other.elementOverviews != null) + return false; + } else if (!this.elementOverviews.equals(other.elementOverviews)) + return false; + if (this.type == null) { + if (other.type != null) + return false; + } else if (!this.type.equals(other.type)) + return false; + return true; + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/TypeOverview.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/TypeOverview.java new file mode 100644 index 000000000..1e51bccd7 --- /dev/null +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/TypeOverview.java @@ -0,0 +1,113 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.model; + +import java.text.MessageFormat; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Robert von Burg + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "Types") +public class TypeOverview { + + @XmlAttribute(name = "type") + private String type; + + @XmlAttribute(name = "size") + private long size; + + public TypeOverview() { + // no-arg constructor for JAXB + } + + /** + * @param type + * @param size + */ + public TypeOverview(String type, long size) { + this.type = type; + this.size = size; + } + + /** + * @return the type + */ + public String getType() { + return this.type; + } + + /** + * @param type + * the type to set + */ + public void setType(String type) { + this.type = type; + } + + /** + * @return the size + */ + public long getSize() { + return this.size; + } + + /** + * @param size + * the size to set + */ + public void setSize(long size) { + this.size = size; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (this.size ^ (this.size >>> 32)); + result = prime * result + ((this.type == null) ? 0 : this.type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TypeOverview other = (TypeOverview) obj; + if (this.size != other.size) + return false; + if (this.type == null) { + if (other.type != null) + return false; + } else if (!this.type.equals(other.type)) + return false; + return true; + } + + @Override + public String toString() { + return MessageFormat.format("TypeOverview [type={0}, size={1}]", this.type, this.size); //$NON-NLS-1$ + } +} diff --git a/li.strolch.rest/src/main/resources/componentVersion.properties b/li.strolch.rest/src/main/resources/componentVersion.properties new file mode 100644 index 000000000..1f050160f --- /dev/null +++ b/li.strolch.rest/src/main/resources/componentVersion.properties @@ -0,0 +1,6 @@ +groupId=${project.groupId} +artifactId=${project.artifactId} +artifactVersion=${project.version} +scmRevision=r${buildNumber} +scmBranch=${scmBranch} +buildTimestamp=${buildTimestamp} \ No newline at end of file diff --git a/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AbstractRestfulTest.java b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AbstractRestfulTest.java new file mode 100644 index 000000000..59fa5dd23 --- /dev/null +++ b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AbstractRestfulTest.java @@ -0,0 +1,112 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.inspector.test; + +import java.io.File; +import java.io.IOException; +import java.net.URI; + +import javax.ws.rs.core.Application; + +import li.strolch.rest.StrolchRestfulClasses; +import li.strolch.testbase.runtime.RuntimeMock; + +import org.glassfish.jersey.filter.LoggingFilter; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.server.ServerProperties; +import org.glassfish.jersey.server.TracingConfig; +import org.glassfish.jersey.servlet.ServletProperties; +import org.glassfish.jersey.test.DeploymentContext; +import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.test.ServletDeploymentContext; +import org.glassfish.jersey.test.TestProperties; +import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory; +import org.glassfish.jersey.test.spi.TestContainerException; +import org.glassfish.jersey.test.spi.TestContainerFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Robert von Burg + */ +@SuppressWarnings("nls") +public abstract class AbstractRestfulTest extends JerseyTest { + + private static final URI BASE_URI = URI.create("http://localhost:8888/base"); + protected static final Logger logger = LoggerFactory.getLogger(AbstractRestfulTest.class); + private static final String RUNTIME_PATH = "target/withPrivilegeRuntime/"; //$NON-NLS-1$ + private static final String CONFIG_SRC = "src/test/resources/withPrivilegeRuntime"; //$NON-NLS-1$ + private static RuntimeMock runtimeMock; + + @BeforeClass + public static void beforeClass() throws IllegalArgumentException, IOException { + + File rootPath = new File(RUNTIME_PATH); + File configSrc = new File(CONFIG_SRC); + runtimeMock = new RuntimeMock(); + runtimeMock.mockRuntime(rootPath, configSrc); + runtimeMock.startContainer(); + } + + @Override + protected URI getBaseUri() { + return BASE_URI; + } + + @AfterClass + public static void afterClass() { + runtimeMock.destroyRuntime(); + } + + @Override + protected TestContainerFactory getTestContainerFactory() throws TestContainerException { + return new GrizzlyWebTestContainerFactory(); + } + + @Override + protected DeploymentContext configureDeployment() { + return ServletDeploymentContext.builder(configure()).contextPath("rest").build(); + } + + @Override + protected Application configure() { + forceEnable(TestProperties.LOG_TRAFFIC); + enable(TestProperties.DUMP_ENTITY); + return createApp(); + } + + public static ResourceConfig createApp() { + ResourceConfig resourceConfig = new ResourceConfig(); + resourceConfig.setApplicationName("RestTest"); + + for (Class clazz : StrolchRestfulClasses.restfulClasses) { + resourceConfig.register(clazz); + } + for (Class clazz : StrolchRestfulClasses.providerClasses) { + resourceConfig.register(clazz); + } + + resourceConfig.register(LoggingFilter.class); + //.register(createMoxyJsonResolver()) + // Logging + // Tracing support. + resourceConfig.property(ServerProperties.TRACING, TracingConfig.ALL.name()); + resourceConfig.property(ServletProperties.FILTER_FORWARD_ON_404, true); + return resourceConfig; + } +} diff --git a/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AuthenticationTest.java b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AuthenticationTest.java new file mode 100644 index 000000000..f9b1f7af8 --- /dev/null +++ b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AuthenticationTest.java @@ -0,0 +1,141 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.inspector.test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.Locale; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import li.strolch.rest.model.Login; +import li.strolch.rest.model.LoginResult; +import li.strolch.rest.model.LogoutResult; + +import org.junit.Ignore; +import org.junit.Test; + +/** + * @author Robert von Burg + */ +@Ignore +@SuppressWarnings("nls") +public class AuthenticationTest extends AbstractRestfulTest { + + private static final String ROOT_PATH = "strolch/authentication"; + + @Test + public void shouldAuthenticate() { + + // login + Login login = new Login(); + login.setUsername("jill"); + login.setPassword("jill"); + Entity loginEntity = Entity.entity(login, MediaType.APPLICATION_JSON); + Response result = target().path(ROOT_PATH).request(MediaType.APPLICATION_JSON).post(loginEntity); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + LoginResult loginResult = result.readEntity(LoginResult.class); + assertNotNull(loginResult); + assertEquals("jill", loginResult.getUsername()); + assertEquals(64, loginResult.getSessionId().length()); + assertNull(loginResult.getMsg()); + + // logout + result = target().path(ROOT_PATH + "/" + loginResult.getSessionId()).request(MediaType.APPLICATION_JSON) + .delete(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + assertNotNull(loginResult); + LogoutResult logoutResult = result.readEntity(LogoutResult.class); + assertNotNull(logoutResult); + assertNull(logoutResult.getMsg()); + } + + @Test + public void shouldUseRequestedLanguage() { + + // login + Login login = new Login(); + login.setUsername("jill"); + login.setPassword("jill"); + Entity loginEntity = Entity.entity(login, MediaType.APPLICATION_JSON); + Builder builder = target().path(ROOT_PATH).request(MediaType.APPLICATION_JSON); + builder = builder.acceptLanguage(Locale.ITALY); + Response result = builder.post(loginEntity); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + LoginResult loginResult = result.readEntity(LoginResult.class); + assertNotNull(loginResult); + assertEquals("jill", loginResult.getUsername()); + assertEquals(64, loginResult.getSessionId().length()); + assertEquals(Locale.ITALY.toString(), loginResult.getLocale()); + assertNull(loginResult.getMsg()); + + // logout + result = target().path(ROOT_PATH + "/" + loginResult.getSessionId()).request(MediaType.APPLICATION_JSON) + .delete(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + assertNotNull(loginResult); + LogoutResult logoutResult = result.readEntity(LogoutResult.class); + assertNotNull(logoutResult); + assertNull(logoutResult.getMsg()); + } + + @Test + public void shouldNotAuthenticate() { + + // login + Login login = new Login(); + login.setUsername("admin"); + login.setPassword("blalba"); + Entity loginEntity = Entity.entity(login, MediaType.APPLICATION_JSON); + Response result = target().path(ROOT_PATH).request(MediaType.APPLICATION_JSON).post(loginEntity); + assertEquals(Status.UNAUTHORIZED.getStatusCode(), result.getStatus()); + LogoutResult logoutResult = result.readEntity(LogoutResult.class); + assertNotNull(logoutResult); + assertEquals("Could not log in due to: Authentication credentials are invalid", logoutResult.getMsg()); + } + + @Test + public void shouldFailLogoutIllegalSession() { + + // login + Login login = new Login(); + login.setUsername("jill"); + login.setPassword("jill"); + Entity loginEntity = Entity.entity(login, MediaType.APPLICATION_JSON); + Response result = target().path(ROOT_PATH).request(MediaType.APPLICATION_JSON).post(loginEntity); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + LoginResult loginResult = result.readEntity(LoginResult.class); + assertNotNull(loginResult); + assertEquals("jill", loginResult.getUsername()); + assertEquals(64, loginResult.getSessionId().length()); + assertNull(loginResult.getMsg()); + + // logout + result = target().path(ROOT_PATH + "/blabla").request(MediaType.APPLICATION_JSON).delete(); + assertEquals(Status.UNAUTHORIZED.getStatusCode(), result.getStatus()); + LogoutResult logoutResult = result.readEntity(LogoutResult.class); + assertNotNull(logoutResult); + assertThat(logoutResult.getMsg(), containsString("No certificate exists for sessionId blabla")); + } +} diff --git a/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/EnumTest.java b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/EnumTest.java new file mode 100644 index 000000000..3ae7e0c3a --- /dev/null +++ b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/EnumTest.java @@ -0,0 +1,81 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.inspector.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Locale; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import li.strolch.runtime.query.enums.StrolchEnum; + +import org.junit.Ignore; +import org.junit.Test; + +/** + * @author Robert von Burg + */ +@Ignore +@SuppressWarnings("nls") +public class EnumTest extends AbstractRestfulTest { + + private static final String ROOT_PATH = "strolch/enums"; + + @Test + public void shouldQuerySex() { + + // query + Response result = target().path(ROOT_PATH + "/sex").request(MediaType.APPLICATION_JSON) + .acceptLanguage(Locale.ENGLISH).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + StrolchEnum strolchEnum = result.readEntity(StrolchEnum.class); + assertNotNull(strolchEnum); + assertEquals("sex", strolchEnum.getName()); + assertEquals(4, strolchEnum.getValues().size()); + } + + @Test + public void shouldQuerySalutation() { + + // query + Response result = target().path(ROOT_PATH + "/salutation").request(MediaType.APPLICATION_JSON) + .acceptLanguage(Locale.ENGLISH).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + StrolchEnum strolchEnum = result.readEntity(StrolchEnum.class); + assertNotNull(strolchEnum); + assertEquals("salutation", strolchEnum.getName()); + assertEquals(3, strolchEnum.getValues().size()); + assertEquals("Mrs", strolchEnum.getValue("mrs")); + } + + @Test + public void shouldQueryGermanSalutation() { + + // query + Response result = target().path(ROOT_PATH + "/salutation").request(MediaType.APPLICATION_JSON) + .acceptLanguage(Locale.GERMAN).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + StrolchEnum strolchEnum = result.readEntity(StrolchEnum.class); + assertNotNull(strolchEnum); + assertEquals("salutation", strolchEnum.getName()); + assertEquals(3, strolchEnum.getValues().size()); + assertEquals("Frau", strolchEnum.getValue("mrs")); + } +} diff --git a/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/InspectorTest.java b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/InspectorTest.java new file mode 100644 index 000000000..94d474701 --- /dev/null +++ b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/InspectorTest.java @@ -0,0 +1,185 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.inspector.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import li.strolch.rest.model.AgentOverview; +import li.strolch.rest.model.ElementMapOverview; +import li.strolch.rest.model.ElementMapType; +import li.strolch.rest.model.ElementMapsOverview; +import li.strolch.rest.model.RealmDetail; +import li.strolch.rest.model.RealmOverview; +import li.strolch.rest.model.TypeOverview; + +import org.junit.Ignore; +import org.junit.Test; + +/** + * @author Robert von Burg + */ +@SuppressWarnings("nls") +@Ignore +public class InspectorTest extends AbstractRestfulTest { + + private static final String ROOT_PATH = "strolch/inspector/"; + + @Test + public void shouldGetAgent() { + + Response response = target().path("/").request(MediaType.TEXT_HTML).get(); + assertEquals(Status.OK.getStatusCode(), response.getStatus()); + + // expected result + List realms = new ArrayList<>(1); + realms.add(new RealmOverview("defaultRealm", 6)); + AgentOverview expectedAgentOverview = new AgentOverview(realms); + + // query + Response result = target().path(ROOT_PATH).request(MediaType.APPLICATION_JSON).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + AgentOverview agentOverview = result.readEntity(AgentOverview.class); + + // assertions + assertEquals(expectedAgentOverview, agentOverview); + } + + @Test + public void shouldGetRealm() { + + // expected result + List elementMapOverviews = new ArrayList<>(2); + Set resourceTypes = new HashSet<>(); + resourceTypes.add("Template"); + resourceTypes.add("TestType"); + resourceTypes.add("Enumeration"); + elementMapOverviews.add(new ElementMapsOverview(ElementMapType.RESOURCE, 4, resourceTypes)); + Set orderTypes = new HashSet<>(); + orderTypes.add("Template"); + orderTypes.add("TestType"); + elementMapOverviews.add(new ElementMapsOverview(ElementMapType.ORDER, 2, orderTypes)); + RealmDetail expectedRealmDetail = new RealmDetail(elementMapOverviews); + + // query + Response result = target().path(ROOT_PATH + "defaultRealm").request(MediaType.APPLICATION_JSON).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + RealmDetail realmDetail = result.readEntity(RealmDetail.class); + + // assertions + assertEquals(expectedRealmDetail, realmDetail); + } + + @Test + public void shouldGetResourcesOverview() { + + // expected result + String elementMapName = "Resource"; + List typeOverviews = new ArrayList<>(2); + typeOverviews.add(new TypeOverview("Enumeration", 2)); + typeOverviews.add(new TypeOverview("Template", 1)); + typeOverviews.add(new TypeOverview("TestType", 1)); + ElementMapOverview expectedElementMapOverview = new ElementMapOverview(elementMapName, typeOverviews); + + // query + Response result = target().path(ROOT_PATH + "defaultRealm/resource").request(MediaType.APPLICATION_JSON).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + ElementMapOverview elementMapOverview = result.readEntity(ElementMapOverview.class); + + // assertions + assertEquals(expectedElementMapOverview, elementMapOverview); + } + + @Test + public void shouldGetOrdersOverview() { + + // expected result + String elementMapName = "Order"; + List typeOverviews = new ArrayList<>(2); + typeOverviews.add(new TypeOverview("Template", 1)); + typeOverviews.add(new TypeOverview("TestType", 1)); + ElementMapOverview expectedElementMapOverview = new ElementMapOverview(elementMapName, typeOverviews); + + // query + Response result = target().path(ROOT_PATH + "defaultRealm/order").request(MediaType.APPLICATION_JSON).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + ElementMapOverview elementMapOverview = result.readEntity(ElementMapOverview.class); + + // assertions + assertEquals(expectedElementMapOverview, elementMapOverview); + } + + // TODO modify object model to include discriminator values, so that we can parse the objects + + @Test + public void shouldGetResourceTypeDetails() { + + // query + + WebTarget target = target(); + Response result = target.path(ROOT_PATH + "defaultRealm/resource/Template").request(MediaType.APPLICATION_JSON) + .get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + String entity = result.readEntity(String.class); + String expected = "{\"type\":\"Template\",\"resources\":[{\"id\":\"TestType\",\"name\":\"TestType Template\",\"type\":\"Template\"}]}"; + assertEquals(expected, entity); + } + + @Test + public void shouldGetOrderTypeDetails() { + + // query + Response result = target().path(ROOT_PATH + "defaultRealm/order/Template").request(MediaType.APPLICATION_JSON) + .get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + String entity = result.readEntity(String.class); + String expected = "{\"type\":\"Template\",\"orders\":[{\"id\":\"TestType\",\"name\":\"MyTestOrder Template\",\"type\":\"Template\",\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\"}]}"; + assertEquals(expected, entity); + } + + @Test + public void shouldGetResource() { + + // query + Response result = target().path(ROOT_PATH + "defaultRealm/resource/Template/TestType") + .request(MediaType.APPLICATION_JSON).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + String entity = result.readEntity(String.class); + assertTrue(entity.contains("name\":\"TestType Template\",\"type\":\"Template\",\"parameterBags\":")); + } + + @Test + public void shouldGetOrder() { + + // query + Response result = target().path(ROOT_PATH + "defaultRealm/order/Template/TestType") + .request(MediaType.APPLICATION_JSON).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + String entity = result.readEntity(String.class); + assertTrue(entity + .contains("\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\",\"parameterBags\"")); + } +} diff --git a/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/VersionQueryTest.java b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/VersionQueryTest.java new file mode 100644 index 000000000..0aa6fd7dd --- /dev/null +++ b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/VersionQueryTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.rest.inspector.test; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import li.strolch.agent.api.AgentVersion; +import li.strolch.agent.api.ComponentVersion; +import li.strolch.agent.api.VersionQueryResult; + +import org.junit.Ignore; +import org.junit.Test; + +/** + * @author Robert von Burg + */ +@Ignore +@SuppressWarnings("nls") +public class VersionQueryTest extends AbstractRestfulTest { + + private static final String ROOT_PATH = "strolch/version"; + + @Test + public void shouldQueryVersion() { + + // query + Response result = target().path(ROOT_PATH).request(MediaType.APPLICATION_JSON).get(); + assertEquals(Status.OK.getStatusCode(), result.getStatus()); + VersionQueryResult versionQueryResult = result.readEntity(VersionQueryResult.class); + if (versionQueryResult.hasErrors()) { + for (String error : versionQueryResult.getErrors()) { + logger.error(error); + } + } + + AgentVersion agentVersion = versionQueryResult.getAgentVersion(); + logger.info(agentVersion.toString()); + List componentVersions = versionQueryResult.getComponentVersions(); + assertEquals(6, componentVersions.size()); + for (ComponentVersion version : componentVersions) { + logger.info(version.toString()); + assertEquals("li.strolch", agentVersion.getGroupId()); + } + + assertEquals("StrolchPersistenceTest", agentVersion.getAgentName()); + assertEquals("li.strolch", agentVersion.getGroupId()); + assertEquals("li.strolch.agent", agentVersion.getArtifactId()); + } +} diff --git a/li.strolch.rest/src/test/resources/log4j.xml b/li.strolch.rest/src/test/resources/log4j.xml new file mode 100644 index 000000000..0a2a73d06 --- /dev/null +++ b/li.strolch.rest/src/test/resources/log4j.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/li.strolch.rest/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml new file mode 100644 index 000000000..9d7a227e3 --- /dev/null +++ b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/li.strolch.rest/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml new file mode 100644 index 000000000..bad34f118 --- /dev/null +++ b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml @@ -0,0 +1,88 @@ + + + + + + SYSTEM + + agent + + + + Application + Administrator + ENABLED + en_GB + + PrivilegeAdmin + AppUser + + + + + + + + + Bob + Bernstein + ENABLED + en_GB + + AppUser + + + + + Jill + Johnson + ENABLED + en_GB + + OnlyGreetingServiceRole + + + + + System User + Administrator + SYSTEM + en_GB + + sysAdmin + AppUser + + + + + + + + + + + + true + + + + + + true + + + true + + + + + + + + + li.strolch.service.test.GreetingService + + + + + \ No newline at end of file diff --git a/li.strolch.rest/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml new file mode 100644 index 000000000..3a04698cf --- /dev/null +++ b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml @@ -0,0 +1,63 @@ + + + + + StrolchPersistenceTest + + true + + + + PrivilegeHandler + li.strolch.runtime.privilege.PrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PrivilegeHandler + + TRANSIENT + StrolchModel.xml + + + + ServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler + + true + + + + RestfulHandler + li.strolch.rest.RestfulStrolchComponent + li.strolch.rest.RestfulStrolchComponent + + + + + SessionHandler + li.strolch.rest.StrolchSessionHandler + li.strolch.rest.DefaultStrolchSessionHandler + + true + + + + EnumHandler + li.strolch.runtime.query.enums.EnumHandler + li.strolch.runtime.query.enums.DefaultEnumHandler + RealmHandler + + defaultRealm + Resource/Enumeration/salutation + Resource/Enumeration/sex + + + + \ No newline at end of file diff --git a/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/Enums.xml b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/Enums.xml new file mode 100644 index 000000000..8e7afdc99 --- /dev/null +++ b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/Enums.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/Orders.xml b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/Orders.xml new file mode 100644 index 000000000..55358bcaa --- /dev/null +++ b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/Orders.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/Resources.xml b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/Resources.xml new file mode 100644 index 000000000..e6259cb83 --- /dev/null +++ b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/Resources.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/StrolchModel.xml b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/StrolchModel.xml new file mode 100644 index 000000000..bc5e3d9a6 --- /dev/null +++ b/li.strolch.rest/src/test/resources/withPrivilegeRuntime/data/StrolchModel.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file