Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2014-01-22 02:25:20 +0000
committerRyan D. Brooks2014-01-22 02:25:20 +0000
commit9ea8e0a944e9caee56b35b72a0d913a50394c3e4 (patch)
tree67077a71b076df437c6c87676475e6630dd30f44 /plugins/org.eclipse.osee.account.rest
parent1f33e0bf0a642c17b674bbeb791e88ea07c4726a (diff)
downloadorg.eclipse.osee-9ea8e0a944e9caee56b35b72a0d913a50394c3e4.tar.gz
org.eclipse.osee-9ea8e0a944e9caee56b35b72a0d913a50394c3e4.tar.xz
org.eclipse.osee-9ea8e0a944e9caee56b35b72a0d913a50394c3e4.zip
feature[ats_ATS8933]: Create Account REST API
Diffstat (limited to 'plugins/org.eclipse.osee.account.rest')
-rw-r--r--plugins/org.eclipse.osee.account.rest/.classpath7
-rw-r--r--plugins/org.eclipse.osee.account.rest/.project33
-rw-r--r--plugins/org.eclipse.osee.account.rest/META-INF/MANIFEST.MF19
-rw-r--r--plugins/org.eclipse.osee.account.rest/OSGI-INF/account.rest.application.xml9
-rw-r--r--plugins/org.eclipse.osee.account.rest/REST-INF/.gitignore4
-rw-r--r--plugins/org.eclipse.osee.account.rest/REST-INF/application-doc.xml4
-rw-r--r--plugins/org.eclipse.osee.account.rest/REST-INF/application-grammars.xml4
-rw-r--r--plugins/org.eclipse.osee.account.rest/build.properties6
-rw-r--r--plugins/org.eclipse.osee.account.rest/pom.xml175
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountActiveResource.java89
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountApplication.java44
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountLoginResource.java55
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountLogoutResource.java54
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountOps.java209
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountPreferencesResource.java70
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountResource.java104
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountSessionsResource.java46
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountsResource.java63
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/RequestInfo.java22
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/RequestUtil.java59
20 files changed, 1076 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.account.rest/.classpath b/plugins/org.eclipse.osee.account.rest/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.osee.account.rest/.project b/plugins/org.eclipse.osee.account.rest/.project
new file mode 100644
index 00000000000..1129656acf3
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.account.rest</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ds.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.osee.account.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.account.rest/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..55880e547aa
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: OSEE Accounts REST API (Incubation)
+Bundle-SymbolicName: org.eclipse.osee.account.rest
+Bundle-Version: 0.17.0.qualifier
+Bundle-Vendor: Eclipse Open System Engineering Environment
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Service-Component: OSGI-INF/*.xml
+Import-Package: javax.annotation.security,
+ javax.servlet,
+ javax.servlet.http,
+ javax.ws.rs,
+ javax.ws.rs.core,
+ javax.ws.rs.ext,
+ org.eclipse.osee.account.admin,
+ org.eclipse.osee.account.rest.model,
+ org.eclipse.osee.framework.jdk.core.type,
+ org.eclipse.osee.framework.jdk.core.util
+Bundle-ActivationPolicy: lazy
diff --git a/plugins/org.eclipse.osee.account.rest/OSGI-INF/account.rest.application.xml b/plugins/org.eclipse.osee.account.rest/OSGI-INF/account.rest.application.xml
new file mode 100644
index 00000000000..31c6fbfd648
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/OSGI-INF/account.rest.application.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop">
+ <implementation class="org.eclipse.osee.account.rest.internal.AccountApplication"/>
+ <service>
+ <provide interface="javax.ws.rs.core.Application"/>
+ </service>
+ <property name="context.name" type="String" value="oseex"/>
+ <reference bind="setAccountAdmin" cardinality="1..1" interface="org.eclipse.osee.account.admin.AccountAdmin" name="AccountAdmin" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.account.rest/REST-INF/.gitignore b/plugins/org.eclipse.osee.account.rest/REST-INF/.gitignore
new file mode 100644
index 00000000000..1c748845156
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/REST-INF/.gitignore
@@ -0,0 +1,4 @@
+/doc
+/application.wadl
+/resourcedoc.xml
+/xsd0.xsd
diff --git a/plugins/org.eclipse.osee.account.rest/REST-INF/application-doc.xml b/plugins/org.eclipse.osee.account.rest/REST-INF/application-doc.xml
new file mode 100644
index 00000000000..d0490a93579
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/REST-INF/application-doc.xml
@@ -0,0 +1,4 @@
+<applicationDocs targetNamespace="http://wadl.dev.java.net/2009/02">
+ <doc xml:lang="en" title="Account Management API">
+ </doc>
+</applicationDocs> \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.account.rest/REST-INF/application-grammars.xml b/plugins/org.eclipse.osee.account.rest/REST-INF/application-grammars.xml
new file mode 100644
index 00000000000..aa0a1295583
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/REST-INF/application-grammars.xml
@@ -0,0 +1,4 @@
+<grammars xmlns="http://wadl.dev.java.net/2009/02" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xi="http://www.w3.org/1999/XML/xinclude">
+ <include href="xsd0.xsd" />
+</grammars> \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.account.rest/build.properties b/plugins/org.eclipse.osee.account.rest/build.properties
new file mode 100644
index 00000000000..e7543d13f58
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/build.properties
@@ -0,0 +1,6 @@
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ OSGI-INF/,\
+ REST-INF/
+source.. = src/
diff --git a/plugins/org.eclipse.osee.account.rest/pom.xml b/plugins/org.eclipse.osee.account.rest/pom.xml
new file mode 100644
index 00000000000..7d701996564
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/pom.xml
@@ -0,0 +1,175 @@
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.osee</groupId>
+ <artifactId>org.eclipse.osee.x.core.parent</artifactId>
+ <version>0.17.0-SNAPSHOT</version>
+ <relativePath>../../plugins/org.eclipse.osee.x.core.parent</relativePath>
+ </parent>
+
+ <artifactId>org.eclipse.osee.account.rest</artifactId>
+ <packaging>eclipse-plugin</packaging>
+ <name>OSEE Account REST API - (Incubation)</name>
+
+ <build>
+ <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 -->
+ <resources>
+ <resource>
+ <directory>src</directory>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ </excludes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>${maven-clean-version}</version>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>REST-INF</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ <excludes>
+ <exclude>application-doc.xml</exclude>
+ <exclude>application-grammars.xml</exclude>
+ <exclude>.gitignore</exclude>
+ </excludes>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadoc-version}</version>
+ <inherited>false</inherited>
+ <executions>
+ <execution>
+ <id>resource-doc-accounts</id>
+ <goals>
+ <goal>javadoc</goal>
+ </goals>
+ <phase>compile</phase>
+ <configuration>
+ <debug>false</debug>
+ <encoding>UTF-8</encoding>
+ <verbose>false</verbose>
+ <show>public</show>
+ <sourcepath>${basedir}/src:${basedir}/../org.eclipse.osee.account.rest.model/src</sourcepath>
+ <subpackages>org.eclipse.osee.account.rest.internal:org.eclipse.osee.account.rest.model</subpackages>
+ <doclet>com.sun.jersey.wadl.resourcedoc.ResourceDoclet</doclet>
+ <docletArtifacts>
+ <docletArtifact>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>wadl-resourcedoc-doclet</artifactId>
+ <version>${jersey-wadlgen-version}</version>
+ </docletArtifact>
+ <docletArtifact>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-server</artifactId>
+ <version>${jersey-version}</version>
+ </docletArtifact>
+ <docletArtifact>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>${xerces-version}</version>
+ </docletArtifact>
+ </docletArtifacts>
+ <additionalparam>-output
+ ${rest-output-directory}/resourcedoc.xml</additionalparam>
+ <useStandardDocletOptions>false</useStandardDocletOptions>
+ </configuration>
+ </execution>
+ <execution>
+ <id>jaxb-report-orcs</id>
+ <goals>
+ <goal>javadoc</goal>
+ </goals>
+ <phase>compile</phase>
+ <configuration>
+ <inherited>false</inherited>
+ <debug>false</debug>
+ <verbose>false</verbose>
+ <name>JAXB Report</name>
+ <description>All the JAXB models</description>
+ <sourcepath>${basedir}/../org.eclipse.osee.account.rest.model/src</sourcepath>
+ <subpackages>org.eclipse.osee.account.rest.model</subpackages>
+ <reportOutputDirectory>${rest-output-directory}</reportOutputDirectory>
+ <destDir>doc/models</destDir>
+ <doclet>com.lunatech.doclets.jax.jaxb.JAXBDoclet</doclet>
+ <docletArtifacts>
+ <docletArtifact>
+ <groupId>com.lunatech.jax-doclets</groupId>
+ <artifactId>doclets</artifactId>
+ <version>${jaxdoclet-version}</version>
+ </docletArtifact>
+ </docletArtifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>maven-wadl-plugin</artifactId>
+ <version>${jersey-wadlgen-version}</version>
+ <executions>
+ <execution>
+ <id>generate</id>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ <phase>compile</phase>
+ </execution>
+ </executions>
+ <configuration>
+ <wadlFile>${rest-output-directory}/application.wadl</wadlFile>
+ <formatWadlFile>true</formatWadlFile>
+ <baseUri>oseex</baseUri>
+ <packagesResourceConfig>
+ <param>org.eclipse.osee.account.rest.internal</param>
+ <param>org.eclipse.osee.account.rest.model</param>
+ </packagesResourceConfig>
+ <wadlGenerators>
+ <wadlGeneratorDescription>
+ <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc</className>
+ <properties>
+ <property>
+ <name>applicationDocsFile</name>
+ <value>${rest-output-directory}/application-doc.xml</value>
+ </property>
+ </properties>
+ </wadlGeneratorDescription>
+ <wadlGeneratorDescription>
+ <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport</className>
+ <properties>
+ <property>
+ <name>grammarsFile</name>
+ <value>${rest-output-directory}/application-grammars.xml</value>
+ </property>
+ </properties>
+ </wadlGeneratorDescription>
+ <wadlGeneratorDescription>
+ <className>com.sun.jersey.server.wadl.generators.resourcedoc.WadlGeneratorResourceDocSupport</className>
+ <properties>
+ <property>
+ <name>resourceDocFile</name>
+ <value>${rest-output-directory}/resourcedoc.xml</value>
+ </property>
+ </properties>
+ </wadlGeneratorDescription>
+ </wadlGenerators>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project> \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountActiveResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountActiveResource.java
new file mode 100644
index 00000000000..36370162bae
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountActiveResource.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import org.eclipse.osee.account.admin.SystemRoles;
+import org.eclipse.osee.account.rest.model.AccountActiveData;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AccountActiveResource {
+
+ private final AccountOps accountOps;
+ private final String accountId;
+
+ public AccountActiveResource(AccountOps accountOps, String accountId) {
+ this.accountOps = accountOps;
+ this.accountId = accountId;
+ }
+
+ /**
+ * Get account active status
+ *
+ * @return account active information
+ */
+ @GET
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public AccountActiveData isActive() {
+ return accountOps.isActive(accountId);
+ }
+
+ /**
+ * Set account status to active
+ *
+ * @return response
+ * @response.representation.200.doc account status set to active
+ * @response.representation.304.doc account active status not modified
+ */
+ @PUT
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ public Response setActive() {
+ ResponseBuilder builder;
+ boolean modified = accountOps.setAccountActive(accountId, true);
+ if (modified) {
+ builder = Response.ok();
+ } else {
+ builder = Response.notModified();
+ }
+ return builder.build();
+ }
+
+ /**
+ * Set account status to inactive
+ *
+ * @return response
+ * @response.representation.200.doc account status set to inactive
+ * @response.representation.304.doc account status not modified
+ */
+ @DELETE
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ public Response setInactive() {
+ ResponseBuilder builder;
+ boolean modified = accountOps.setAccountActive(accountId, false);
+ if (modified) {
+ builder = Response.ok();
+ } else {
+ builder = Response.notModified();
+ }
+ return builder.build();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountApplication.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountApplication.java
new file mode 100644
index 00000000000..74abccc400a
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountApplication.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.core.Application;
+import org.eclipse.osee.account.admin.AccountAdmin;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AccountApplication extends Application {
+
+ private final Set<Object> singletons = new HashSet<Object>();
+ private AccountAdmin accountAdmin;
+
+ public void setAccountAdmin(AccountAdmin accountAdmin) {
+ this.accountAdmin = accountAdmin;
+ }
+
+ public void start() {
+ AccountOps ops = new AccountOps(accountAdmin);
+ singletons.add(new AccountsResource(ops));
+ }
+
+ public void stop() {
+ singletons.clear();
+ }
+
+ @Override
+ public Set<Object> getSingletons() {
+ return singletons;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountLoginResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountLoginResource.java
new file mode 100644
index 00000000000..32da9b1badb
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountLoginResource.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import java.net.URI;
+import javax.annotation.security.PermitAll;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+import org.eclipse.osee.account.rest.model.AccountLoginData;
+import org.eclipse.osee.account.rest.model.AccountSessionData;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AccountLoginResource {
+
+ private final AccountOps accountOps;
+
+ public AccountLoginResource(AccountOps accountOps) {
+ this.accountOps = accountOps;
+ }
+
+ /**
+ * Logs user into account and creates a new account Session
+ *
+ * @param data Login data
+ * @return account session information and URL to account info
+ */
+ @POST
+ @PermitAll
+ @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response login(@Context HttpServletRequest request, @Context UriInfo uriInfo, AccountLoginData data) {
+ RequestInfo remoteInfo = accountOps.asRequestInfo(request);
+
+ AccountSessionData token = accountOps.doLogin(remoteInfo, data);
+ String accountId = String.valueOf(token.getAccountId());
+ URI location = UriBuilder.fromUri(uriInfo.getBaseUri()).path(accountId).build();
+ return Response.ok().entity(token).contentLocation(location).build();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountLogoutResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountLogoutResource.java
new file mode 100644
index 00000000000..745d551c031
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountLogoutResource.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import org.eclipse.osee.account.admin.SystemRoles;
+import org.eclipse.osee.account.rest.model.AccountSessionData;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AccountLogoutResource {
+
+ private final AccountOps accountOps;
+
+ public AccountLogoutResource(AccountOps accountOps) {
+ this.accountOps = accountOps;
+ }
+
+ /**
+ * Logs user out of the system
+ *
+ * @return response
+ * @response.representation.200.doc successfully logged out
+ * @response.representation.304.doc session not modified
+ */
+ @POST
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response logout(AccountSessionData data) {
+ ResponseBuilder builder;
+ boolean modified = accountOps.doLogout(data.getToken());
+ if (modified) {
+ builder = Response.ok();
+ } else {
+ builder = Response.notModified();
+ }
+ return builder.build();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountOps.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountOps.java
new file mode 100644
index 00000000000..462eb18d8ab
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountOps.java
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+import org.eclipse.osee.account.admin.Account;
+import org.eclipse.osee.account.admin.AccountAccess;
+import org.eclipse.osee.account.admin.AccountAdmin;
+import org.eclipse.osee.account.admin.AccountLoginRequest;
+import org.eclipse.osee.account.admin.AccountLoginRequestBuilder;
+import org.eclipse.osee.account.admin.AccountPreferences;
+import org.eclipse.osee.account.admin.CreateAccountRequest;
+import org.eclipse.osee.account.admin.CreateAccountRequestBuilder;
+import org.eclipse.osee.account.rest.model.AccountAccessData;
+import org.eclipse.osee.account.rest.model.AccountActiveData;
+import org.eclipse.osee.account.rest.model.AccountDetailsData;
+import org.eclipse.osee.account.rest.model.AccountInfoData;
+import org.eclipse.osee.account.rest.model.AccountInput;
+import org.eclipse.osee.account.rest.model.AccountLoginData;
+import org.eclipse.osee.account.rest.model.AccountPreferencesData;
+import org.eclipse.osee.account.rest.model.AccountPreferencesInput;
+import org.eclipse.osee.account.rest.model.AccountSessionData;
+import org.eclipse.osee.framework.jdk.core.type.Identifiable;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AccountOps {
+
+ private final AccountAdmin accountAdmin;
+
+ public AccountOps(AccountAdmin accountAdmin) {
+ super();
+ this.accountAdmin = accountAdmin;
+ }
+
+ public RequestInfo asRequestInfo(HttpServletRequest request) {
+ final String userAgent = RequestUtil.getUserAgent(request);
+ final String remoteAddress = RequestUtil.getClientIpAddrress(request);
+ return new RequestInfo() {
+
+ @Override
+ public String getDetails() {
+ return userAgent;
+ }
+
+ @Override
+ public String getRemoteIpAddress() {
+ return remoteAddress;
+ }
+
+ };
+ }
+
+ public List<AccountAccessData> getAccountAccessById(String accountId) {
+ ResultSet<AccountAccess> result = accountAdmin.getAccountAccessByUniqueField(accountId);
+ List<AccountAccessData> toReturn = new ArrayList<AccountAccessData>();
+ for (AccountAccess access : result) {
+ toReturn.add(asAccountAccessData(access));
+ }
+ return toReturn;
+ }
+
+ public AccountAccessData asAccountAccessData(AccountAccess access) {
+ AccountAccessData data = new AccountAccessData();
+ data.setAccountId(access.getAccountId());
+ data.setAccessDetails(access.getAccessDetails());
+ data.setAccessedFrom(access.getAccessedFrom());
+ data.setCreatedOn(access.getCreatedOn());
+ data.setLastAccessedOn(access.getLastAccessedOn());
+ return data;
+ }
+
+ public AccountSessionData doLogin(RequestInfo info, AccountLoginData input) {
+ AccountLoginRequestBuilder builder = AccountLoginRequestBuilder.newBuilder();
+ AccountLoginRequest request = builder//
+ .userName(input.getUsername())//
+ .password(input.getPassword())//
+ .scheme(input.getScheme()) //
+ .accessedBy(info.getDetails())//
+ .remoteAddress(info.getRemoteIpAddress()) //
+ .build();
+ AccountAccess session = accountAdmin.login(request);
+ return asSessionData(session);
+ }
+
+ public boolean doLogout(String token) {
+ return accountAdmin.logout(token);
+ }
+
+ public AccountSessionData asSessionData(AccountAccess session) {
+ AccountSessionData data = new AccountSessionData();
+ data.setAccountId(session.getAccountId());
+ data.setToken(session.getAccessToken());
+ return data;
+ }
+
+ public AccountInfoData createAccount(String username, AccountInput input) {
+ CreateAccountRequestBuilder builder = CreateAccountRequestBuilder.newBuilder();
+ CreateAccountRequest request = builder//
+ .userName(username)//
+ .displayName(input.getName())//
+ .email(input.getEmail())//
+ .active(input.isActive()) //
+ .prefs(input.getPreferences()) //
+ .build();
+
+ Identifiable<String> id = accountAdmin.createAccount(request);
+ ResultSet<Account> result = accountAdmin.getAccountByUuid(id.getGuid());
+ Account account = result.getExactlyOne();
+ return asAccountData(account);
+ }
+
+ public boolean deleteAccount(String accountId) {
+ return accountAdmin.deleteAccount(accountId);
+ }
+
+ public boolean setAccountActive(String accountId, boolean active) {
+ return accountAdmin.setActive(accountId, active);
+ }
+
+ public AccountActiveData isActive(String accountId) {
+ ResultSet<Account> result = accountAdmin.getAccountByUniqueField(accountId);
+ Account account = result.getExactlyOne();
+ return asAccountActiveData(account);
+ }
+
+ public List<AccountInfoData> getAllAccounts() {
+ List<AccountInfoData> toReturn = new ArrayList<AccountInfoData>();
+ ResultSet<Account> result = accountAdmin.getAllAccounts();
+ for (Account account : result) {
+ toReturn.add(asAccountData(account));
+ }
+ return toReturn;
+ }
+
+ public AccountDetailsData getAccountDetailsData(String accountId) {
+ ResultSet<Account> result = accountAdmin.getAccountByUniqueField(accountId);
+ Account account = result.getExactlyOne();
+ return asAccountDetailsData(account);
+ }
+
+ public AccountInfoData getAccountData(String value) {
+ ResultSet<Account> result = accountAdmin.getAccountByUniqueField(value);
+ Account account = result.getExactlyOne();
+ return asAccountData(account);
+ }
+
+ public AccountPreferencesData getAccountPreferencesData(String value) {
+ ResultSet<Account> result = accountAdmin.getAccountByUniqueField(value);
+ Account account = result.getExactlyOne();
+ AccountPreferences preferences = account.getPreferences();
+ return asAccountPreferencesData(preferences);
+ }
+
+ private AccountDetailsData asAccountDetailsData(Account account) {
+ AccountDetailsData data = new AccountDetailsData();
+ fillData(account, data);
+ AccountPreferencesData preferences = asAccountPreferencesData(account.getPreferences());
+ data.setPreferences(preferences);
+ return data;
+ }
+
+ private AccountInfoData asAccountData(Account account) {
+ AccountInfoData data = new AccountInfoData();
+ fillData(account, data);
+ return data;
+ }
+
+ private void fillData(Account account, AccountInfoData data) {
+ data.setAccountId(account.getId());
+ data.setGuid(account.getGuid());
+ data.setName(account.getName());
+ data.setEmail(account.getEmail());
+ data.setUserName(account.getUserName());
+ data.setActive(account.isActive());
+ }
+
+ private AccountPreferencesData asAccountPreferencesData(AccountPreferences preferences) {
+ AccountPreferencesData data = new AccountPreferencesData();
+ data.setId(preferences.getId());
+ data.setMap(preferences.asMap());
+ return data;
+ }
+
+ private AccountActiveData asAccountActiveData(Account account) {
+ AccountActiveData data = new AccountActiveData();
+ data.setAccountId(account.getId());
+ data.setGuid(account.getGuid());
+ data.setActive(account.isActive());
+ return data;
+ }
+
+ public boolean setAccountPreferences(String accountId, AccountPreferencesInput input) {
+ return accountAdmin.setAccountPreferences(accountId, input.getMap());
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountPreferencesResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountPreferencesResource.java
new file mode 100644
index 00000000000..14bf266d279
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountPreferencesResource.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import org.eclipse.osee.account.admin.SystemRoles;
+import org.eclipse.osee.account.rest.model.AccountPreferencesData;
+import org.eclipse.osee.account.rest.model.AccountPreferencesInput;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AccountPreferencesResource {
+
+ private final AccountOps accountOps;
+ private final String accountId;
+
+ public AccountPreferencesResource(AccountOps accountOps, String accountId) {
+ this.accountOps = accountOps;
+ this.accountId = accountId;
+ }
+
+ /**
+ * Get account preferences
+ *
+ * @return account preferences
+ */
+ @GET
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public AccountPreferencesData getAccountPreferences() {
+ return accountOps.getAccountPreferencesData(accountId);
+ }
+
+ /**
+ * Sets all preferences to match the incoming preferences.
+ *
+ * @return response
+ * @response.representation.200.doc successfully logged out
+ * @response.representation.304.doc session not modified
+ */
+ @PUT
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response setAccountPreferences(AccountPreferencesInput input) {
+ ResponseBuilder builder;
+ boolean modified = accountOps.setAccountPreferences(accountId, input);
+ if (modified) {
+ builder = Response.ok();
+ } else {
+ builder = Response.notModified();
+ }
+ return builder.build();
+ }
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountResource.java
new file mode 100644
index 00000000000..d919ee5101a
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountResource.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import javax.annotation.security.PermitAll;
+import javax.annotation.security.RolesAllowed;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import org.eclipse.osee.account.admin.SystemRoles;
+import org.eclipse.osee.account.rest.model.AccountContexts;
+import org.eclipse.osee.account.rest.model.AccountDetailsData;
+import org.eclipse.osee.account.rest.model.AccountInfoData;
+import org.eclipse.osee.account.rest.model.AccountInput;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AccountResource {
+
+ private final AccountOps accountOps;
+ private final String accountId;
+
+ public AccountResource(AccountOps accountOps, String accountId) {
+ this.accountOps = accountOps;
+ this.accountId = accountId;
+ }
+
+ /**
+ * Creates a new Account - all fields must be unique
+ *
+ * @param accountInput Account data
+ * @return new account info data
+ */
+ @POST
+ @PermitAll
+ @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public AccountInfoData createAccount(AccountInput accountInput) {
+ return accountOps.createAccount(accountId, accountInput);
+ }
+
+ /**
+ * Deletes the account
+ *
+ * @return response
+ * @response.representation.200.doc account status set to active
+ * @response.representation.304.doc account active status not modified
+ */
+ @DELETE
+ @RolesAllowed(SystemRoles.ROLES_ADMINISTRATOR)
+ public Response deleteAccount() {
+ ResponseBuilder builder;
+ boolean modified = accountOps.deleteAccount(accountId);
+ if (modified) {
+ builder = Response.ok();
+ } else {
+ builder = Response.notModified();
+ }
+ return builder.build();
+ }
+
+ /**
+ * Get account details
+ *
+ * @return account details
+ */
+ @GET
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public AccountDetailsData getAccountDetailsData() {
+ return accountOps.getAccountDetailsData(accountId);
+ }
+
+ @Path(AccountContexts.ACCOUNT_PREFERENCES)
+ public AccountPreferencesResource getAccountSettingsData() {
+ return new AccountPreferencesResource(accountOps, accountId);
+ }
+
+ @Path(AccountContexts.ACCOUNT_ACTIVE)
+ public AccountActiveResource active() {
+ return new AccountActiveResource(accountOps, accountId);
+ }
+
+ @Path(AccountContexts.ACCOUNT_SESSSIONS)
+ public AccountSessionsResource sessions() {
+ return new AccountSessionsResource(accountOps, accountId);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountSessionsResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountSessionsResource.java
new file mode 100644
index 00000000000..1bbb23e697b
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountSessionsResource.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import java.util.List;
+import javax.annotation.security.RolesAllowed;
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.eclipse.osee.account.admin.SystemRoles;
+import org.eclipse.osee.account.rest.model.AccountAccessData;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AccountSessionsResource {
+
+ private final AccountOps accountOps;
+ private final String accountId;
+
+ public AccountSessionsResource(AccountOps accountOps, String accountId) {
+ this.accountOps = accountOps;
+ this.accountId = accountId;
+ }
+
+ /**
+ * Get all accesses for this account
+ *
+ * @return account accesses
+ */
+ @GET
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public List<AccountAccessData> getAccountSessions() {
+ return accountOps.getAccountAccessById(accountId);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountsResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountsResource.java
new file mode 100644
index 00000000000..026e786f0ff
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountsResource.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import java.util.List;
+import javax.annotation.security.RolesAllowed;
+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.MediaType;
+import org.eclipse.osee.account.admin.SystemRoles;
+import org.eclipse.osee.account.rest.model.AccountContexts;
+import org.eclipse.osee.account.rest.model.AccountInfoData;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@Path(AccountContexts.ACCOUNTS)
+public class AccountsResource {
+
+ private final AccountOps accountOps;
+
+ public AccountsResource(AccountOps accountOps) {
+ this.accountOps = accountOps;
+ }
+
+ /**
+ * Get all Accounts
+ *
+ * @return All accounts
+ */
+ @GET
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public List<AccountInfoData> getAccounts() {
+ return accountOps.getAllAccounts();
+ }
+
+ @Path(AccountContexts.ACCOUNT_LOGIN)
+ public AccountLoginResource getLoginResource() {
+ return new AccountLoginResource(accountOps);
+ }
+
+ @Path(AccountContexts.ACCOUNT_LOGOUT)
+ public AccountLogoutResource getLogoutResource() {
+ return new AccountLogoutResource(accountOps);
+ }
+
+ @Path(AccountContexts.ACCOUNT_ID_TEMPLATE)
+ public AccountResource getAccount(@PathParam(AccountContexts.ACCOUNT_ID_PARAM) String accountId) {
+ return new AccountResource(accountOps, accountId);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/RequestInfo.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/RequestInfo.java
new file mode 100644
index 00000000000..8c274f11874
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/RequestInfo.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface RequestInfo {
+
+ String getDetails();
+
+ String getRemoteIpAddress();
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/RequestUtil.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/RequestUtil.java
new file mode 100644
index 00000000000..41a4883bcd9
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/RequestUtil.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.internal;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.HttpHeaders;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class RequestUtil {
+
+ private static final String X_FORWARDED_FOR = "X-Forwarded-For";
+ private static final String PROXY_CLIENT_IP = "Proxy-Client-IP";
+ private static final String HTTP_X_FORWARDED_FOR = "HTTP_X_FORWARDED_FOR";
+ private static final String WL_PROXY_CLIENT_IP = "WL-Proxy-Client-IP";
+ private static final String HTTP_CLIENT_IP = "HTTP_CLIENT_IP";
+ private static final String UNKNOWN = "unknown";
+
+ private RequestUtil() {
+ // Utility class
+ }
+
+ public static String getUserAgent(HttpServletRequest request) {
+ return request != null ? request.getHeader(HttpHeaders.USER_AGENT) : "";
+ }
+
+ public static String getClientIpAddrress(HttpServletRequest request) {
+ String ip = "";
+ if (request != null) {
+ ip = request.getHeader(X_FORWARDED_FOR);
+ if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
+ ip = request.getHeader(PROXY_CLIENT_IP);
+ }
+ if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
+ ip = request.getHeader(WL_PROXY_CLIENT_IP);
+ }
+ if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
+ ip = request.getHeader(HTTP_CLIENT_IP);
+ }
+ if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
+ ip = request.getHeader(HTTP_X_FORWARDED_FOR);
+ }
+ if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
+ ip = request.getRemoteAddr();
+ }
+ }
+ return ip;
+ }
+
+}

Back to the top