refactor(manager-api): rework `web.xml` protected endpoints
MODIFY
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/AbstractJpaStorage.java
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/AbstractJpaStorage.java
@@ -29,12 +29,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
-import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.naming.InitialContext;
import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
@@ -58,19 +55,9 @@ public abstract class AbstractJpaStorage {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractJpaStorage.class);
- // @Inject
- // @PersistenceContext(unitName = "apiman-manager-api-jpa")
- // private EntityManager em;
-
@Inject
private EntityManagerFactoryAccessor emf;
- @PostConstruct
- public void construct() {
- // em = emf.getEntityManager();
- // System.out.println("em(jpa)=" + em.hashCode());
- }
-
/**
* Constructor.
*/

MODIFY
manager/api/war/src/main/java/io/apiman/manager/api/war/WarApiManagerBootstrapperServlet.java
manager/api/war/src/main/java/io/apiman/manager/api/war/WarApiManagerBootstrapperServlet.java
@@ -64,11 +64,6 @@ public class WarApiManagerBootstrapperServlet extends HttpServlet {
*/
@Override
public void init() throws ServletException {
- // LOGGER.info("Trying to run early.... " + ds.toString());
-
- JpaStorageInitializer init = new JpaStorageInitializer(config2.getHibernateDataSource(), config2.getHibernateDialect());
- init.initialize();
-
Thread t = new Thread(() -> {
if (isImportEnabled()){
File dataDir = getDataDir();

MODIFY
manager/api/war/wildfly8/src/main/webapp/WEB-INF/web.xml
manager/api/war/wildfly8/src/main/webapp/WEB-INF/web.xml
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/actions/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
+ <http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/system/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
+ <http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/gateways/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
+ <http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/organizations/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
+ <http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/plugins/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
+ <http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/policyDefs/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
+ <http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/roles/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
+ <http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/search/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
+ <http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/users/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
+ <http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
+
<auth-constraint>
<role-name>apiuser</role-name>
</auth-constraint>
</security-constraint>
+
<security-constraint>
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/gateways/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/developers/*</url-pattern>
- <http-method>GET</http-method>
- <http-method>POST</http-method>
- <http-method>PUT</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
</web-resource-collection>
+
<web-resource-collection>
<web-resource-name>apiman</web-resource-name>
<url-pattern>/search/clients></url-pattern>
- <http-method>POST</http-method>
</web-resource-collection>
+
<auth-constraint>
<role-name>devportaluser</role-name>
</auth-constraint>

MODIFY
manager/test/api/src/main/java/io/apiman/manager/test/server/ManagerApiTestServer.java
manager/test/api/src/main/java/io/apiman/manager/test/server/ManagerApiTestServer.java
@@ -38,6 +38,7 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ThreadLocalRandom;
import javax.naming.InitialContext;
import javax.naming.NameAlreadyBoundException;
import javax.servlet.DispatcherType;
@@ -227,7 +228,7 @@ public class ManagerApiTestServer {
ds.setDriverClassName(Driver.class.getName());
ds.setUsername("sa");
ds.setPassword("");
- ds.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;");
+ ds.setUrl("jdbc:h2:mem:test-" + ThreadLocalRandom.current().nextInt() + ";DB_CLOSE_DELAY=-1;");
Connection connection = ds.getConnection();
connection.close();
System.out.println("DataSource created and bound to JNDI.");

refactor(manager-api): rework `web.xml` protected endpoints