Merge branch 'master' of ../rest

This commit is contained in:
Robert von Burg 2014-09-16 09:03:40 +02:00
commit f235cf6a4f
54 changed files with 4812 additions and 0 deletions

5
li.strolch.rest/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
target/
.project
.settings
.classpath
.DS_Store

202
li.strolch.rest/LICENSE Normal file
View File

@ -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.

View File

@ -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

166
li.strolch.rest/pom.xml Normal file
View File

@ -0,0 +1,166 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../li.strolch.parent/pom.xml</relativePath>
</parent>
<artifactId>li.strolch.rest</artifactId>
<name>li.strolch.rest</name>
<description>Restful Web Service API for Strolch</description>
<url>https://github.com/eitchnet/li.strolch.rest</url>
<inceptionYear>2011</inceptionYear>
<issueManagement>
<system>Github Issues</system>
<url>https://github.com/eitchnet/li.strolch.rest/issues</url>
</issueManagement>
<scm>
<connection>scm:git:https://github.com/eitchnet/li.strolch.rest.git</connection>
<developerConnection>scm:git:git@github.com:eitch/li.strolch.rest.git</developerConnection>
<url>https://github.com/eitchnet/li.strolch.rest</url>
</scm>
<properties>
<jersey.version>2.11</jersey.version>
<!-- <org.eclipse.persistence.version>2.5.1</org.eclipse.persistence.version> -->
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- due to bug in persistence 2.5.0 -->
<!-- <dependency> -->
<!-- <groupId>org.eclipse.persistence</groupId> -->
<!-- <artifactId>org.eclipse.persistence.moxy</artifactId> -->
<!-- <version>${org.eclipse.persistence.version}</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.eclipse.persistence</groupId> -->
<!-- <artifactId>org.eclipse.persistence.antlr</artifactId> -->
<!-- <version>${org.eclipse.persistence.version}</version> -->
<!-- </dependency> -->
</dependencies>
</dependencyManagement>
<dependencies>
<!-- main -->
<dependency>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.model</artifactId>
</dependency>
<dependency>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.agent</artifactId>
</dependency>
<dependency>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.service</artifactId>
</dependency>
<!-- Servlet 3.0 API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<!-- Restful API -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.testbase</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-bundle</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/componentVersion.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,129 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
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<String, Certificate> 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);
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
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> T getComponent(Class<T> clazz) {
return getContainer().getComponent(clazz);
}
public PrivilegeHandler getPrivilegeHandler() {
return getContainer().getPrivilegeHandler();
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
public class StrolchRestfulClasses {
public static Set<Class<?>> restfulClasses;
public static Set<Class<?>> providerClasses;
static {
Set<Class<?>> restfulClasses = new HashSet<>();
restfulClasses.add(AuthenticationService.class);
restfulClasses.add(Inspector.class);
restfulClasses.add(VersionQuery.class);
restfulClasses.add(EnumQuery.class);
Set<Class<?>> 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<Class<?>> getRestfulClasses() {
return restfulClasses;
}
public static Set<Class<?>> getProviderClasses() {
return providerClasses;
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
public class StrolchRestfulConstants {
public static final String STROLCH_CERTIFICATE = "strolch.certificate"; //$NON-NLS-1$
}

View File

@ -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<Exception> {
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();
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
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);
}

View File

@ -0,0 +1,156 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<LoginResult> entity = new GenericEntity<LoginResult>(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<String> 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<LogoutResult> entity = new GenericEntity<LogoutResult>(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();
}
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<StrolchEnum> entity = new GenericEntity<StrolchEnum>(strolchEnum, StrolchEnum.class) {
//
};
return Response.ok().entity(entity).build();
} catch (Exception e) {
logger.error(e.getMessage(), e);
return Response.serverError().entity(e.getMessage()).build();
}
}
}

View File

@ -0,0 +1,393 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@Path("strolch/inspector")
public class Inspector {
private StrolchTransaction openTx(Certificate certificate, String realm) {
return RestfulStrolchComponent.getInstance().getContainer().getRealm(realm)
.openTx(certificate, Inspector.class);
}
/**
* <p>
* Root path of the inspector
* </p>
*
* <p>
* Returns the root element, which is an overview of the configured realms
* </p>
*
* @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<String> realmNames = container.getRealmNames();
List<RealmOverview> 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<AgentOverview> entity = new GenericEntity<AgentOverview>(agentOverview, AgentOverview.class) {
//
};
return Response.ok().entity(entity).build();
} catch (Exception e) {
//e.printStackTrace();
throw e;
}
}
/**
* <p>
* Realm inspector
* </p>
*
* <p>
* Returns the overview of a specific relam
* </p>
*
* @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<ElementMapsOverview> 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<RealmDetail> entity = new GenericEntity<RealmDetail>(modelOverview, RealmDetail.class) {
//
};
return Response.ok().entity(entity).build();
}
/**
* <p>
* Resource inspector
* </p>
* <p>
* Returns an overview of the {@link Resource Resources}. This is a list of all the types and the size each type has
* </p>
*
* @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<String> types = new ArrayList<>(resourceMap.getTypes(tx));
Collections.sort(types);
List<TypeOverview> 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<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(resourcesOverview,
ElementMapOverview.class) {
//
};
return Response.ok().entity(entity).build();
}
/**
* <p>
* Order inspector
* </p>
* <p>
* Returns an overview of the {@link Order Orders}. This is a list of all the types and the size each type has
* </p>
*
* @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<String> types = new ArrayList<>(orderMap.getTypes(tx));
Collections.sort(types);
List<TypeOverview> 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<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(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
/**
* <p>
* Resource type inspector
* </p>
* <p>
* Returns an overview of the {@link Resource Resources} with the given type. This is a list of overviews of the
* resources
* </p>
*
* @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<Resource> byType = tx.getResourceMap().getElementsBy(tx, type);
List<StrolchElementOverview> elementOverviews = new ArrayList<>(byType.size());
for (Resource resource : byType) {
ResourceOverview resourceOverview = new ResourceOverview(resource);
elementOverviews.add(resourceOverview);
}
typeDetail = new TypeDetail(type, elementOverviews);
}
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) {
//
};
return Response.ok().entity(entity).build();
}
/**
* <p>
* Order type inspector
* </p>
* <p>
* Returns an overview of the {@link Order Orders} with the given type. This is a list of overviews of the orders
* </p>
*
* @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<Order> byType = tx.getOrderMap().getElementsBy(tx, type);
List<StrolchElementOverview> elementOverviews = new ArrayList<>(byType.size());
for (Order order : byType) {
OrderOverview orderOverview = new OrderOverview(order);
elementOverviews.add(orderOverview);
}
typeDetail = new TypeDetail(type, elementOverviews);
}
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) {
//
};
return Response.ok().entity(entity).build();
}
/**
* <p>
* Resource inspector
* </p>
*
* <p>
* Returns the resource with the given id
* </p>
*
* @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<ResourceDetail> entity = new GenericEntity<ResourceDetail>(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<OrderDetail> entity = new GenericEntity<OrderDetail>(orderDetail, OrderDetail.class) {
//
};
return Response.ok().entity(entity).build();
}
}

View File

@ -0,0 +1,55 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<VersionQueryResult> entity = new GenericEntity<VersionQueryResult>(versionQueryResult,
VersionQueryResult.class) {
//
};
return Response.ok().entity(entity).build();
}
}

View File

@ -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<String, Object> 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$
}
}

View File

@ -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 <reto.breitenmoser@4trees.ch>
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@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$
}
}
}
}

View File

@ -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 <reto.breitenmoser@4trees.ch>
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@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());
}
}
}

View File

@ -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 <eitch@eitchnet.ch>
*/
@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());
}
}
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
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;
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Agent")
public class AgentOverview {
@XmlElement(name = "realms")
private List<RealmOverview> realms;
public AgentOverview() {
// no-arg constructor for JAXB
}
public AgentOverview(List<RealmOverview> realms) {
this.realms = realms;
}
/**
* @return the realms
*/
public List<RealmOverview> getRealms() {
return this.realms;
}
/**
* @param realms
* the realms to set
*/
public void setRealms(List<RealmOverview> 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$
}
}

View File

@ -0,0 +1,140 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<TypeOverview> typeOverviews;
public ElementMapOverview() {
// no-arg constructor for JAXB
}
/**
* @param elementMapName
* @param typeOverviews
*/
public ElementMapOverview(String elementMapName, List<TypeOverview> 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<TypeOverview> getTypeOverviews() {
return this.typeOverviews;
}
/**
* @param typeOverviews
* the typeOverviews to set
*/
public void setTypeOverviews(List<TypeOverview> 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);
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
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;
}
}

View File

@ -0,0 +1,181 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<String> 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<String> 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<String> getTypes() {
return this.types;
}
/**
* @param types
* the types to set
*/
public void setTypes(Set<String> 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();
}
}

View File

@ -0,0 +1,102 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "GroupedParameterizedElement")
@XmlSeeAlso({ ResourceDetail.class, OrderDetail.class })
public class GroupedParameterizedElementDetail extends StrolchElementDetail {
@XmlElement(name = "parameterBags", type = ParameterizedElementDetail.class)
private List<ParameterizedElementDetail> parameterizedElements;
public GroupedParameterizedElementDetail() {
// no-arg constructor for JAXB
}
public GroupedParameterizedElementDetail(String id, String name, String type,
List<ParameterizedElementDetail> parameterizedElements) {
super(id, name, type);
this.parameterizedElements = parameterizedElements;
}
public GroupedParameterizedElementDetail(GroupedParameterizedElement groupedParameterizedElement) {
super(groupedParameterizedElement);
Set<String> 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<ParameterizedElementDetail> getParameterizedElements() {
return this.parameterizedElements;
}
/**
* @param parameterizedElements
* the parameterizedElements to set
*/
public void setParameterizedElements(List<ParameterizedElementDetail> 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;
}
}

View File

@ -0,0 +1,68 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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;
}
}

View File

@ -0,0 +1,153 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<String, String> parameters;
@XmlAttribute(name = "msg")
private String msg;
@XmlAttribute(name = "privileges")
private List<String> 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<String, String> getParameters() {
return this.parameters;
}
/**
* @param parameters
* the parameters to set
*/
public void setParameters(Map<String, String> 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<String> getPrivileges() {
return this.privileges;
}
/**
* @param privileges
* the privileges to set
*/
public void setPrivileges(List<String> privileges) {
this.privileges = privileges;
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
*/
@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;
}
}

View File

@ -0,0 +1,87 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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;
}
}

View File

@ -0,0 +1,129 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<ParameterizedElementDetail> 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;
}
}

View File

@ -0,0 +1,122 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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;
}
}

View File

@ -0,0 +1,174 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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;
}
}

View File

@ -0,0 +1,97 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "ParameterBag")
public class ParameterizedElementDetail extends StrolchElementDetail {
@XmlElement(name = "parameters", type = ParameterDetail.class)
private List<ParameterDetail> parameters;
public ParameterizedElementDetail() {
// no-arg constructor for JAXB
}
public ParameterizedElementDetail(String id, String name, String type, List<ParameterDetail> parameters) {
super(id, name, type);
this.parameters = parameters;
}
public ParameterizedElementDetail(ParameterizedElement parameterizedElement) {
super(parameterizedElement);
List<Parameter<?>> parameters = parameterizedElement.getParameters();
this.parameters = new ArrayList<>(parameters.size());
for (Parameter<?> parameter : parameters) {
this.parameters.add(new ParameterDetail(parameter));
}
}
/**
* @return the parameters
*/
public List<ParameterDetail> getParameters() {
return this.parameters;
}
/**
* @param parameters
* the parameters to set
*/
public void setParameters(List<ParameterDetail> 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;
}
}

View File

@ -0,0 +1,92 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Realm")
public class RealmDetail {
@XmlElement(name = "elementMaps")
private List<ElementMapsOverview> elementMapOverviews;
public RealmDetail() {
// no-arg constructor for JAXB
}
public RealmDetail(List<ElementMapsOverview> elementMapOverviews) {
this.elementMapOverviews = elementMapOverviews;
}
/**
* @return the elementMapOverviews
*/
public List<ElementMapsOverview> getElementMapOverviews() {
return this.elementMapOverviews;
}
/**
* @param elementMapOverviews
* the elementMapOverviews to set
*/
public void setElementMapOverviews(List<ElementMapsOverview> 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();
}
}

View File

@ -0,0 +1,117 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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();
}
}

View File

@ -0,0 +1,55 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<ParameterizedElementDetail> parameterizedElements) {
super(id, name, type, parameterizedElements);
}
/**
* @param resource
*/
public ResourceDetail(Resource resource) {
super(resource);
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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);
}
}

View File

@ -0,0 +1,144 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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;
}
}

View File

@ -0,0 +1,144 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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;
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<StrolchElementOverview> elementOverviews;
public TypeDetail() {
// no-arg constructor for JAXB
}
/**
* @param type
* @param elementOverviews
*/
public TypeDetail(String type, List<StrolchElementOverview> 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<StrolchElementOverview> getElementOverviews() {
return this.elementOverviews;
}
/**
* @param elementOverviews
* the elementOverviews to set
*/
public void setElementOverviews(List<StrolchElementOverview> 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;
}
}

View File

@ -0,0 +1,113 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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$
}
}

View File

@ -0,0 +1,6 @@
groupId=${project.groupId}
artifactId=${project.artifactId}
artifactVersion=${project.version}
scmRevision=r${buildNumber}
scmBranch=${scmBranch}
buildTimestamp=${buildTimestamp}

View File

@ -0,0 +1,112 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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;
}
}

View File

@ -0,0 +1,141 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<Login> 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<Login> 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<Login> 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<Login> 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"));
}
}

View File

@ -0,0 +1,81 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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"));
}
}

View File

@ -0,0 +1,185 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<RealmOverview> 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<ElementMapsOverview> elementMapOverviews = new ArrayList<>(2);
Set<String> resourceTypes = new HashSet<>();
resourceTypes.add("Template");
resourceTypes.add("TestType");
resourceTypes.add("Enumeration");
elementMapOverviews.add(new ElementMapsOverview(ElementMapType.RESOURCE, 4, resourceTypes));
Set<String> 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<TypeOverview> 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<TypeOverview> 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\""));
}
}

View File

@ -0,0 +1,68 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
@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<ComponentVersion> 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());
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC
"-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration debug="false" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p [%t] %C{1} %M - %m%n" />
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.FileAppender">
<param name="File" value="sample.log"/>
<param name="BufferedIO" value="true" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p [%t] %C{1} %M - %m%n" />
</layout>
</appender>
<logger name="ch.eitchnet">
<level value="info" />
</logger>
<root>
<priority value="info" />
<appender-ref ref="CONSOLE" />
<!-- appender-ref ref="FILE" / -->
</root>
</log4j:configuration>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Privilege>
<Container>
<Parameters>
<!-- parameters for the container itself -->
<Parameter name="autoPersistOnPasswordChange" value="true" />
</Parameters>
<EncryptionHandler class="ch.eitchnet.privilege.handler.DefaultEncryptionHandler">
<Parameters>
<Parameter name="hashAlgorithm" value="SHA-256" />
</Parameters>
</EncryptionHandler>
<PersistenceHandler class="ch.eitchnet.privilege.handler.XmlPersistenceHandler">
<Parameters>
<Parameter name="basePath" value="target/strolchRuntime/config" />
<Parameter name="modelXmlFile" value="PrivilegeModel.xml" />
</Parameters>
</PersistenceHandler>
</Container>
<Policies>
<Policy name="DefaultPrivilege" class="ch.eitchnet.privilege.policy.DefaultPrivilege" />
</Policies>
</Privilege>

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<UsersAndRoles>
<Users>
<User userId="1" username="agent">
<State>SYSTEM</State>
<Roles>
<Role>agent</Role>
</Roles>
</User>
<User userId="1" username="admin" password="8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918">
<Firstname>Application</Firstname>
<Lastname>Administrator</Lastname>
<State>ENABLED</State>
<Locale>en_GB</Locale>
<Roles>
<Role>PrivilegeAdmin</Role>
<Role>AppUser</Role>
</Roles>
<Properties>
<Property name="organization" value="eitchnet.ch" />
<Property name="organizationalUnit" value="Development" />
</Properties>
</User>
<User userId="2" username="bob" password="81b637d8fcd2c6da6359e6963113a1170de795e4b725b84d1e0b4cfd9ec58ce9">
<Firstname>Bob</Firstname>
<Lastname>Bernstein</Lastname>
<State>ENABLED</State>
<Locale>en_GB</Locale>
<Roles>
<Role>AppUser</Role>
</Roles>
</User>
<User userId="3" username="jill" password="8cf37351b60f00084392043ce2e6256b96cea92949f90c7abce464cf164fbfa6">
<Firstname>Jill</Firstname>
<Lastname>Johnson</Lastname>
<State>ENABLED</State>
<Locale>en_GB</Locale>
<Roles>
<Role>OnlyGreetingServiceRole</Role>
</Roles>
</User>
<User userId="4" username="sysAdmin" password="8cffb494ef5ff3f74a571206e141d4fb84f833e431b98c8b3be43727c4cbddc1">
<Firstname>System User</Firstname>
<Lastname>Administrator</Lastname>
<State>SYSTEM</State>
<Locale>en_GB</Locale>
<Roles>
<Role>sysAdmin</Role>
<Role>AppUser</Role>
</Roles>
</User>
</Users>
<Roles>
<Role name="PrivilegeAdmin" />
<Role name="agent">
<Privilege name="li.strolch.agent.impl.StartRealms" policy="DefaultPrivilege">
<AllAllowed>true</AllAllowed>
</Privilege>
</Role>
<Role name="AppUser">
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
<AllAllowed>true</AllAllowed>
</Privilege>
<Privilege name="li.strolch.model.query.StrolchQuery" policy="DefaultPrivilege">
<AllAllowed>true</AllAllowed>
</Privilege>
</Role>
<Role name="sysAdmin">
</Role>
<Role name="OnlyGreetingServiceRole">
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
<Allow>li.strolch.service.test.GreetingService</Allow>
</Privilege>
</Role>
</Roles>
</UsersAndRoles>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<StrolchConfiguration>
<env id="dev">
<Runtime>
<applicationName>StrolchPersistenceTest</applicationName>
<Properties>
<verbose>true</verbose>
</Properties>
</Runtime>
<Component>
<name>PrivilegeHandler</name>
<api>li.strolch.runtime.privilege.PrivilegeHandler</api>
<impl>li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler</impl>
<Properties>
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
</Properties>
</Component>
<Component>
<name>RealmHandler</name>
<api>li.strolch.agent.api.RealmHandler</api>
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
<depends>PrivilegeHandler</depends>
<Properties>
<dataStoreMode>TRANSIENT</dataStoreMode>
<dataStoreFile>StrolchModel.xml</dataStoreFile>
</Properties>
</Component>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.service.api.ServiceHandler</api>
<impl>li.strolch.service.api.DefaultServiceHandler</impl>
<Properties>
<verbose>true</verbose>
</Properties>
</Component>
<Component>
<name>RestfulHandler</name>
<api>li.strolch.rest.RestfulStrolchComponent</api>
<impl>li.strolch.rest.RestfulStrolchComponent</impl>
<Properties>
</Properties>
</Component>
<Component>
<name>SessionHandler</name>
<api>li.strolch.rest.StrolchSessionHandler</api>
<impl>li.strolch.rest.DefaultStrolchSessionHandler</impl>
<Properties>
<rememberUser>true</rememberUser>
</Properties>
</Component>
<Component>
<name>EnumHandler</name>
<api>li.strolch.runtime.query.enums.EnumHandler</api>
<impl>li.strolch.runtime.query.enums.DefaultEnumHandler</impl>
<depends>RealmHandler</depends>
<Properties>
<realm>defaultRealm</realm>
<salutation>Resource/Enumeration/salutation</salutation>
<sex>Resource/Enumeration/sex</sex>
</Properties>
</Component>
</env>
</StrolchConfiguration>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<StrolchModel>
<Resource Id="salutation" Name="Salutations" Type="Enumeration">
<ParameterBag Id="en" Name="Salutations" Type="Enumeration">
<Parameter Id="mr" Name="Mr" Type="String" Value="Mr" />
<Parameter Id="ms" Name="Ms" Type="String" Value="Ms" />
<Parameter Id="mrs" Name="Mrs" Type="String" Value="Mrs" />
</ParameterBag>
<ParameterBag Id="de" Name="Salutations" Type="Enumeration">
<Parameter Id="mr" Name="Mr" Type="String" Value="Herr" />
<Parameter Id="ms" Name="Ms" Type="String" Value="Frau" />
<Parameter Id="mrs" Name="Mrs" Type="String" Value="Frau" />
</ParameterBag>
</Resource>
<Resource Id="sex" Name="Sex" Type="Enumeration">
<ParameterBag Id="en" Name="Sex" Type="Enumeration">
<Parameter Id="undefined" Name="Undefined" Type="String" Value="undefined" />
<Parameter Id="both" Name="Both" Type="String" Value="both" />
<Parameter Id="female" Name="Female" Type="String" Value="female" />
<Parameter Id="male" Name="Male" Type="String" Value="male" />
</ParameterBag>
</Resource>
</StrolchModel>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<StrolchModel>
<Order Id="MyTestOrder" Name="Test Name" Type="TestType" Date="2013-11-20T07:42:57.699+01:00" State="CREATED">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
</Order>
</StrolchModel>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<StrolchModel>
<Resource Id="MyTestResource" Name="Test Name" Type="TestType">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
</Resource>
</StrolchModel>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<StrolchModel>
<Resource Id="TestType" Name="TestType Template" Type="Template">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
</Resource>
<Order Id="TestType" Name="MyTestOrder Template" Type="Template" Date="2012-11-30T18:12:05.628+01:00">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
</Order>
<IncludeFile file="Resources.xml" />
<IncludeFile file="Orders.xml" />
<IncludeFile file="Enums.xml" />
</StrolchModel>