Commit 1da02b46 authored by Francesco Chicchiricco's avatar Francesco Chicchiricco
Browse files

Kicking out the choremocks webapp

parent c51e78b0
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016 The CHOReVOLUTION project
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.
-->
<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>eu.chorevolution.idm</groupId>
<artifactId>syncope</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<name>CHOReVOLUTION IdM: Mock-ups</name>
<artifactId>choremocks</artifactId>
<packaging>war</packaging>
<properties>
<rootpom.basedir>${basedir}/..</rootpom.basedir>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>org.apache.brooklyn</groupId>
<artifactId>brooklyn-rest-api</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-search</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
</dependencies>
<build>
<finalName>choremocks</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
</project>
/*
* Copyright 2016 The CHOReVOLUTION project
*
* 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 eu.chorevolution.idm.choremocks;
import java.io.IOException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Response;
import org.apache.cxf.common.util.Base64Exception;
import org.apache.cxf.common.util.Base64Utility;
public class AuthenticationHandler implements ContainerRequestFilter {
@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
String authorization = requestContext.getHeaderString("Authorization");
if (authorization == null) {
authorization = "";
}
String[] parts = authorization.split(" ");
if (parts.length != 2 || !"Basic".equals(parts[0])) {
requestContext.abortWith(createFaultResponse());
return;
}
String decodedValue;
try {
decodedValue = new String(Base64Utility.decode(parts[1]));
} catch (Base64Exception e) {
requestContext.abortWith(createFaultResponse());
return;
}
String[] namePassword = decodedValue.split(":");
if (isAuthenticated(namePassword[0], namePassword[1])) {
// let request to continue
} else {
// authentication failed, request the authetication, add the realm name if needed to the value of
// WWW-Authenticate
requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic").build());
}
}
private Response createFaultResponse() {
return Response.status(401).header("WWW-Authenticate", "Basic realm=\"CHOReVOLUTION IdM Mock-ups\"").build();
}
private boolean isAuthenticated(final String username, final String password) {
return "admin".equals(username) && "admin".equals(password);
}
}
/*
* Copyright 2016 The CHOReVOLUTION project
*
* 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 eu.chorevolution.idm.choremocks.ee;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/v1/choreography")
@Api("Choreography")
public interface ChoreographyApi {
@GET
@Path("/start/{choreography_id}")
@ApiOperation(
value = "Start a running choreography."
)
Response start(
@ApiParam(name = "choreography_id", value = "The ID of the choregraphy to start", required = true)
@PathParam("choreography_id")
String choreography_id);
@GET
@Path("/stop/{choreography_id}")
@ApiOperation(
value = "Stop a running choreography."
)
Response stop(
@ApiParam(name = "choreography_id", value = "The ID of the choregraphy to stop", required = true)
@PathParam("choreography_id")
String choreography_id);
@GET
@Path("/pause/{choreography_id}")
@ApiOperation(
value = "Pause a running choreography."
)
Response pause(
@ApiParam(name = "choreography_id", value = "The ID of the choregraphy to pause", required = true)
@PathParam("choreography_id")
String choreography_id);
/*
@ApiOperation(
value = "Check the status of a choreography deployment process."
)
@ApiErrors(value = {
@ApiError(code = 404, reason = "Choreography not existing")
})*/
@GET
@Path("/check_status/{choreography_id}")
Response check_status(
@ApiParam(name = "choreography_id", value = "The ID of the choregraphy to check", required = true)
@PathParam("choreography_id")
String choreography_id);
@POST
@Path("/deploy/{choreography_name}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
value = "Deploy a choreography onto a cloud environment.",
response = org.apache.brooklyn.rest.domain.TaskSummary.class
)
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Undefined entity or location"),
@ApiResponse(code = 412, message = "Choreography already registered")
})
Response deploy(
@ApiParam(name = "choreography_name", value = "Choreography ID or name", required = true)
@PathParam("choreography_name") String choreography_name,
@ApiParam(name = "choreography", value = "Choreography specifications", required = true)
String choreography);
@POST
@Path("/resize/{choreography_name}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
value = "Resize VM pool running a running choreography.",
response = org.apache.brooklyn.rest.domain.TaskSummary.class
)
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Undefined entity or location"),
@ApiResponse(code = 412, message = "Choreography already registered")
})
Response resize(
@ApiParam(name = "choreography_name", value = "Choreography ID or name", required = true)
@PathParam("choreography_name") String choreography_name,
@ApiParam(name = "desired_pool_size", value = "Desired size of the VMs pool", required = true)
int desired_size);
}
/*
* Copyright 2016 The CHOReVOLUTION project
*
* 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 eu.chorevolution.idm.choremocks.ee;
import javax.ws.rs.core.Response;
import org.springframework.stereotype.Service;
@Service
public class ChoreographyResource implements ChoreographyApi {
@Override
public Response start(final String choreography_id) {
return null;
}
@Override
public Response stop(final String choreography_id) {
return null;
}
@Override
public Response pause(final String choreography_id) {
return null;
}
@Override
public Response check_status(final String choreography_id) {
return null;
}
@Override
public Response deploy(final String choreography_name, final String choreography) {
return null;
}
@Override
public Response resize(final String choreography_name, final int desired_size) {
return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016 The CHOReVOLUTION project
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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- CXF Configuration - BEGIN -->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<context:component-scan base-package="eu.chorevolution.idm.choremocks"/>
<bean id="authenticationHandler" class="eu.chorevolution.idm.choremocks.AuthenticationHandler"/>
<jaxrs:server address="/"
basePackages="eu.chorevolution.idm.choremocks.ee"
staticSubresourceResolution="true">
<jaxrs:providers>
<ref bean="authenticationHandler"/>
</jaxrs:providers>
</jaxrs:server>
<!-- CXF Configuration - END -->
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016 The CHOReVOLUTION project
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.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>CHOReVOLUTION IdM: Mock-ups</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/*Context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
......@@ -227,6 +227,12 @@ limitations under the License.
</configfiles>
</configuration>
<deployables>
<deployable>
<location>../choremocks/target/choremocks</location>
<properties>
<context>choremocks</context>
</properties>
</deployable>
<deployable>
<location>../core/target/syncope</location>
<properties>
......
......@@ -262,6 +262,7 @@ limitations under the License.
<module>console</module>
<module>enduser</module>
<module>ext</module>
<module>choremocks</module>
</modules>
</project>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment