Revision: 52710
Author: adouma
Date: 2015-04-01 23:19:14 +0200 (Wed, 01 Apr 2015)
Log Message:
-----------
REPO-1205: use CXF JAXRSInvoker to inject and handle repository based
authentication as this works both in CXF 2.6 (CMS 7.9) and CXF 3.x (CMS 10)
Modified Paths:
--------------
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/JaxrsApplication.java
Added Paths:
-----------
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/RepositoryAuthenticatingJaxrsInvoker.java
Removed Paths:
-------------
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/JaxrsAuthenticationHandler.java
Modified:
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/JaxrsApplication.java
===================================================================
---
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/JaxrsApplication.java
2015-04-01 15:52:43 UTC (rev 52709)
+++
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/JaxrsApplication.java
2015-04-01 21:19:14 UTC (rev 52710)
@@ -42,15 +42,9 @@
private Set<Object> dummySingletons = Collections.unmodifiableSet(new
HashSet<Object>() {{ add(new DummyService()); }});
private Set<Object> singletons;
- private Set<Class<?>> classes = Collections.unmodifiableSet(new
HashSet<Class<?>>() {{ add(JaxrsAuthenticationHandler.class); }});
private volatile int version = -1;
@Override
- public Set<Class<?>> getClasses() {
- return classes;
- }
-
- @Override
public Set<Object> getSingletons() {
if (updateSingletonsNeeded()) {
updateSingletons();
@@ -67,6 +61,7 @@
private void updateSingletons() {
final Set<Object> singletons = new HashSet<>();
+ version = HippoServiceRegistry.getVersion();
final List<HippoServiceRegistration> registrations =
getJaxrsServiceRegistrations();
for (HippoServiceRegistration registration : registrations) {
final Object service = registration.getService();
@@ -74,7 +69,6 @@
singletons.add(service);
}
this.singletons = Collections.unmodifiableSet(singletons);
- version = HippoServiceRegistry.getVersion();
}
protected List<HippoServiceRegistration> getJaxrsServiceRegistrations() {
Deleted:
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/JaxrsAuthenticationHandler.java
===================================================================
---
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/JaxrsAuthenticationHandler.java
2015-04-01 15:52:43 UTC (rev 52709)
+++
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/JaxrsAuthenticationHandler.java
2015-04-01 21:19:14 UTC (rev 52710)
@@ -1,66 +0,0 @@
-/*
- * Copyright 2015 Hippo B.V. (http://www.onehippo.com)
- *
- * 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 org.onehippo.cms7.jaxrs;
-
-import java.io.IOException;
-import java.security.AccessControlException;
-
-import javax.jcr.LoginException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.core.Response;
-
-import org.apache.cxf.configuration.security.AuthorizationPolicy;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.onehippo.cms7.services.HippoServiceRegistry;
-import org.onehippo.repository.RepositoryService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class JaxrsAuthenticationHandler implements ContainerRequestFilter {
-
- private static final Logger log =
LoggerFactory.getLogger(JaxrsAuthenticationHandler.class);
-
- @Override
- public void filter(final ContainerRequestContext requestContext) throws
IOException {
- final Message message = PhaseInterceptorChain.getCurrentMessage();
- final AuthorizationPolicy policy =
message.get(AuthorizationPolicy.class);
- if (policy == null) {
-
requestContext.abortWith(Response.status(401).header("WWW-Authenticate",
"Basic").build());
- } else {
- Session session = null;
- try {
- final RepositoryService repository =
HippoServiceRegistry.getService(RepositoryService.class);
- session = repository.login(new
SimpleCredentials(policy.getUserName(), policy.getPassword().toCharArray()));
-// session.checkPermission("/content/document", "hippo:rest");
- } catch (AccessControlException | LoginException e) {
-
requestContext.abortWith(Response.status(401).header("WWW-Authenticate",
"Basic").build());
- } catch (RepositoryException e) {
- log.error("Error during login", e);
- requestContext.abortWith(Response.serverError().build());
- } finally {
- if (session != null) {
- session.logout();
- }
- }
- }
- }
-
-}
Added:
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/RepositoryAuthenticatingJaxrsInvoker.java
===================================================================
---
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/RepositoryAuthenticatingJaxrsInvoker.java
(rev 0)
+++
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/RepositoryAuthenticatingJaxrsInvoker.java
2015-04-01 21:19:14 UTC (rev 52710)
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2015 Hippo B.V. (http://www.onehippo.com)
+ *
+ * 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 org.onehippo.cms7.jaxrs;
+
+import java.security.AccessControlException;
+
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
+import org.apache.cxf.jaxrs.JAXRSInvoker;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.MessageContentsList;
+import org.onehippo.cms7.services.HippoServiceRegistry;
+import org.onehippo.repository.RepositoryService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RepositoryAuthenticatingJaxrsInvoker extends JAXRSInvoker {
+
+ private static final Logger log =
LoggerFactory.getLogger(RepositoryAuthenticatingJaxrsInvoker.class);
+
+ @Override
+ public Object invoke(Exchange exchange, Object requestParams, Object
resourceObject) {
+ Object result = null;
+ final AuthorizationPolicy policy =
exchange.getInMessage().get(AuthorizationPolicy.class);
+ if (policy == null) {
+ result = new
MessageContentsList(Response.status(Response.Status.UNAUTHORIZED).header("WWW-Authenticate",
"Basic").build());
+ }
+ else {
+ Session session = null;
+ try {
+ final RepositoryService repository =
HippoServiceRegistry.getService(RepositoryService.class);
+ session = repository.login(new
SimpleCredentials(policy.getUserName(), policy.getPassword().toCharArray()));
+ result = super.invoke(exchange, requestParams, resourceObject);
+ }
+ catch (AccessControlException | LoginException e) {
+ result = new
MessageContentsList(Response.status(Response.Status.UNAUTHORIZED).header("WWW-Authenticate",
"Basic").build());
+ }
+ catch (RepositoryException e) {
+ log.error("Error during login", e);
+ result = new
MessageContentsList(Response.serverError().build());
+ }
+ finally
+ {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+ return result;
+ }
+}
Property changes on:
hippo-cms7/repository/trunk/engine/src/main/java/org/onehippo/cms7/jaxrs/RepositoryAuthenticatingJaxrsInvoker.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
_______________________________________________
Hippocms-svn mailing list
[email protected]
https://lists.onehippo.org/mailman/listinfo/hippocms-svn