From daff202fe1a46141badcf73309d3237dcf4f8ef0 Mon Sep 17 00:00:00 2001 From: Brian Demers Date: Tue, 5 Jul 2016 15:35:35 -0400 Subject: [PATCH 1/6] Initial CDI import --- pom.xml | 2 +- support/cdi/core/pom.xml | 135 ++++++++++++++ .../org/ops4j/pax/shiro/cdi/ShiroIni.java | 52 ++++++ .../org/ops4j/pax/shiro/cdi/ShiroSecured.java | 52 ++++++ .../config/CdiIniSecurityManagerFactory.java | 74 ++++++++ .../shiro/cdi/impl/BeanManagerProvider.java | 73 ++++++++ .../pax/shiro/cdi/impl/NamedBeanMap.java | 136 ++++++++++++++ .../pax/shiro/cdi/impl/ShiroIniLiteral.java | 39 ++++ .../pax/shiro/cdi/impl/ShiroProducer.java | 139 +++++++++++++++ .../pax/shiro/cdi/impl/package-info.java | 22 +++ .../cdi/interceptor/ShiroInterceptor.java | 69 ++++++++ .../org/ops4j/pax/shiro/cdi/package-info.java | 23 +++ .../src/main/resources/META-INF/beans.xml | 14 ++ .../ops4j/pax/shiro/cdi/AbstractCdiTest.java | 68 +++++++ .../ops4j/pax/shiro/cdi/ShiroFactoryTest.java | 39 ++++ .../CdiIniSecurityManagerFactoryTest.java | 102 +++++++++++ .../shiro/cdi/config/MyPasswordMatcher.java | 29 +++ .../cdi/impl/BeanManagerProviderTest.java | 43 +++++ .../org/ops4j/pax/shiro/cdi/impl/Curry.java | 38 ++++ .../org/ops4j/pax/shiro/cdi/impl/Food.java | 32 ++++ .../ops4j/pax/shiro/cdi/impl/IceCream.java | 41 +++++ .../pax/shiro/cdi/impl/NamedBeanMapTest.java | 58 ++++++ .../org/ops4j/pax/shiro/cdi/impl/Sausage.java | 38 ++++ .../cdi/interceptor/ShiroInterceptorTest.java | 166 ++++++++++++++++++ .../src/test/resources/META-INF/beans.xml | 23 +++ .../core/src/test/resources/exam.properties | 1 + .../core/src/test/resources/log4j.properties | 38 ++++ .../src/test/resources/test-shiro-cdi.ini | 5 + .../core/src/test/resources/test-shiro.ini | 4 + support/cdi/pom.xml | 40 +++++ support/cdi/web/pom.xml | 79 +++++++++ .../shiro/cdi/web/CdiIniWebEnvironment.java | 62 +++++++ .../web/CdiWebIniSecurityManagerFactory.java | 55 ++++++ support/pom.xml | 1 + 34 files changed, 1791 insertions(+), 1 deletion(-) create mode 100644 support/cdi/core/pom.xml create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroIni.java create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroSecured.java create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactory.java create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProvider.java create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMap.java create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroIniLiteral.java create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroProducer.java create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/package-info.java create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptor.java create mode 100644 support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/package-info.java create mode 100644 support/cdi/core/src/main/resources/META-INF/beans.xml create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/AbstractCdiTest.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/ShiroFactoryTest.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/MyPasswordMatcher.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProviderTest.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Curry.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Food.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/IceCream.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMapTest.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Sausage.java create mode 100644 support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptorTest.java create mode 100644 support/cdi/core/src/test/resources/META-INF/beans.xml create mode 100644 support/cdi/core/src/test/resources/exam.properties create mode 100644 support/cdi/core/src/test/resources/log4j.properties create mode 100644 support/cdi/core/src/test/resources/test-shiro-cdi.ini create mode 100644 support/cdi/core/src/test/resources/test-shiro.ini create mode 100644 support/cdi/pom.xml create mode 100644 support/cdi/web/pom.xml create mode 100644 support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiIniWebEnvironment.java create mode 100644 support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java diff --git a/pom.xml b/pom.xml index a9bcfc131f..50ffdcbf9b 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ 3.1 1.3 1.8.5 - 4.8.2 + 4.12 diff --git a/support/cdi/core/pom.xml b/support/cdi/core/pom.xml new file mode 100644 index 0000000000..1eb3a6de63 --- /dev/null +++ b/support/cdi/core/pom.xml @@ -0,0 +1,135 @@ + + 4.0.0 + + org.apache.shiro + shiro-cdi + 1.3.0-SNAPSHOT + + shiro-cdi-core + bundle + + Apache Shiro :: CDI :: Core + + + cdi + 3.2.0 + + + + + org.apache.shiro + shiro-core + + + org.apache.geronimo.specs + geronimo-jcdi_1.0_spec + 1.0 + + + org.apache.geronimo.specs + geronimo-interceptor_1.1_spec + 1.0 + + + org.apache.geronimo.specs + geronimo-atinject_1.0_spec + 1.0 + + + + org.ops4j.pax.exam + pax-exam-junit4 + ${pax.exam.version} + test + + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + test + + + + org.slf4j + slf4j-log4j12 + test + + + log4j + log4j + test + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + + + + + + + + + + + + + + + + + + openwebbeans + + true + + + + org.apache.openwebbeans + openwebbeans-impl + 1.1.8 + test + + + + org.ops4j.pax.exam + pax-exam-container-openwebbeans + ${pax.exam.version} + test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroIni.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroIni.java new file mode 100644 index 0000000000..bb14a510ba --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroIni.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Qualifies managed beans as referenceable from Shiro INI files with a given name. + *

+ * The bean name can be set explicitly with a {@code @Named} qualifier. Otherwise, if + * {@code Bean.getBeanClass()} is a bean type of the given bean, the bean name will be the simple + * class name of this class, with the first letter converted to lower case. + *

+ * In all other cases (e.g. for producer methods), Shiro will log a warning and the bean will not be + * available in the Shiro environment. + * + * @author Harald Wellmann + * + */ +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RUNTIME) +@Documented +public @interface ShiroIni { + +} diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroSecured.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroSecured.java new file mode 100644 index 0000000000..4a0b883468 --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroSecured.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + +/** + * Interceptor binding for declarative security checks using the annotations from the + * {@code org.apache.shiro.authz.annotation} package. + *

+ * Usage: + *

+ * The secured methods will fail with an {@code AuthorizationException} if the current subject + * does not match the security constraints. + * + * @author Harald Wellmann + * + */ +@Inherited +@InterceptorBinding +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ShiroSecured { + // +} diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactory.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactory.java new file mode 100644 index 0000000000..eb5ece63d8 --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactory.java @@ -0,0 +1,74 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.config; + +import java.util.Map; + +import javax.enterprise.inject.spi.BeanManager; + +import org.apache.shiro.config.Ini; +import org.apache.shiro.config.IniSecurityManagerFactory; +import org.apache.shiro.config.Ini.Section; +import org.ops4j.pax.shiro.cdi.impl.NamedBeanMap; + + +/** + * A CDI-aware extension of {@code IniSecurityManagerFactory}, allowing to reference CDI + * managed beans qualified with {@code @ShiroIni} in Shiro INI files. + * + * @author Harald Wellmann + * + */ +public class CdiIniSecurityManagerFactory extends IniSecurityManagerFactory { + + + private NamedBeanMap namedBeanMap; + + /** + * Constructs a security manager factory for the given INI resource path, considering + * CDI beans from the given bean manager. + * + * @param iniResourcePath INI file resource path + * @param beanManager the current CDI bean manager + */ + public CdiIniSecurityManagerFactory(String iniResourcePath, BeanManager beanManager) { + super(iniResourcePath); + namedBeanMap = new NamedBeanMap(beanManager); + } + + /** + * Constructs a security manager factory for the given INI object, considering + * CDI beans from the given bean manager. + * + * @param ini INI object + * @param beanManager the current CDI bean manager + */ + public CdiIniSecurityManagerFactory(Ini ini, BeanManager beanManager) { + super(ini); + namedBeanMap = new NamedBeanMap(beanManager); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + protected Map createDefaults(Ini ini, Section mainSection) { + Map defaults = super.createDefaults(ini, mainSection); + defaults.putAll(namedBeanMap); + return defaults; + } +} diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProvider.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProvider.java new file mode 100644 index 0000000000..cf3f067f14 --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProvider.java @@ -0,0 +1,73 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + +import javax.enterprise.inject.spi.BeanManager; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +/** + * Provides access to the current bean manager. If the bean manager cannot be found under the + * canonical JNDI name (e.g. when the application is not running in a Java EE environment), this + * class returns a singleton which must be set explicitly by the user with + * {@link #setBeanManager(BeanManager)}. + *

+ * TODO In CDI 1.1, CDI.current().getBeanManager() should be used instead. + * + * @author Harald Wellmann + * + */ +public class BeanManagerProvider { + + private static BeanManager beanManager; + + + /** Hidden constructor. */ + private BeanManagerProvider() { + } + + /** + * Looks up the current bean manager in JNDI, or returns the value set by + * {@link #setBeanManager(BeanManager)} as fallback. + * + * @return + */ + public static BeanManager getBeanManager() { + try { + InitialContext initialContext = new InitialContext(); + return (BeanManager) initialContext.lookup("java:comp/BeanManager"); + } + catch (NamingException e) { + if (beanManager != null) { + return beanManager; + } + throw new IllegalStateException( + "BeanManager not found in JNDI and not set via setBeanManager()"); + } + } + + /** + * @param beanManager + * the beanManager to set + */ + public static void setBeanManager(BeanManager beanManager) { + BeanManagerProvider.beanManager = beanManager; + } + +} diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMap.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMap.java new file mode 100644 index 0000000000..f49baa5b10 --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMap.java @@ -0,0 +1,136 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Partial immutable {@link Map} implementation to provide a subset of CDI beans as Shiro beans to be + * referenced in INI files. The keys are bean names, the values are bean instances. + *

+ * To be considered, a CDI bean must be qualified with {@link ShiroIni} and optionally with + * {@code @Named}. + *

+ * Contextual references of these beans are eagerly created when this class is instantiated. This + * is the main reason for using the dedicated {@code ShiroIni} qualifier, to avoid instantiating + * all named beans. + * + * @author Harald Wellmann + * + */ +public class NamedBeanMap implements Map { + + private static Logger log = LoggerFactory.getLogger(NamedBeanMap.class); + + private Map beans = new HashMap(); + + /** + * + */ + public NamedBeanMap(BeanManager beanManager) { + for (Bean bean : beanManager.getBeans(Object.class, ShiroIniLiteral.INSTANCE)) { + String beanName = getShiroBeanName(bean); + if (beanName == null) { + log.warn("Shiro cannot derive a default name for [{}], " + + "so this bean cannot be referenced in shiro.ini. " + + "Consider adding a @Named qualifier.", bean); + } + else { + log.debug("Found @ShiroIni bean with name [{}]", beanName); + CreationalContext cc = beanManager.createCreationalContext(null); + Object object = beanManager.getReference(bean, Object.class, cc); + beans.put(beanName, object); + } + } + } + + /** + * @param bean + * @return + */ + private String getShiroBeanName(Bean bean) { + String beanName = bean.getName(); + if (beanName == null) { + if (bean.getTypes().contains(bean.getBeanClass())) { + String className = bean.getBeanClass().getSimpleName(); + char first = Character.toLowerCase(className.charAt(0)); + beanName = first + className.substring(1); + } + } + return beanName; + } + + public int size() { + return beans.size(); + } + + public boolean isEmpty() { + return beans.isEmpty(); + } + + public boolean containsKey(Object key) { + return beans.containsKey(key); + } + + public boolean containsValue(Object value) { + throw new UnsupportedOperationException(); + } + + public Object get(Object key) { + return beans.get(key); + } + + public Object put(String key, Object value) { + throw new UnsupportedOperationException(); + } + + public Object remove(Object key) { + throw new UnsupportedOperationException(); + } + + public void putAll(Map m) { + throw new UnsupportedOperationException(); + } + + public void clear() { + throw new UnsupportedOperationException(); + } + + public Set keySet() { + return beans.keySet(); + } + + public Collection values() { + return beans.values(); + } + + public Set> entrySet() { + return beans.entrySet(); + } +} diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroIniLiteral.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroIniLiteral.java new file mode 100644 index 0000000000..83b66cdc79 --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroIniLiteral.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + +import javax.enterprise.util.AnnotationLiteral; + +import org.ops4j.pax.shiro.cdi.ShiroIni; + + +/** + * A literal for the {@link ShiroIni} annotation. + * + * @author Harald Wellmann + * + */ +public class ShiroIniLiteral extends AnnotationLiteral { + + /** Annotation literal instance. */ + public static final ShiroIniLiteral INSTANCE = new ShiroIniLiteral(); + + private static final long serialVersionUID = 1L; + +} diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroProducer.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroProducer.java new file mode 100644 index 0000000000..feff53436e --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroProducer.java @@ -0,0 +1,139 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + +import static org.apache.shiro.SecurityUtils.getSecurityManager; +import static org.apache.shiro.SecurityUtils.getSubject; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; + +import org.apache.shiro.ShiroException; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.session.Session; +import org.apache.shiro.subject.Subject; + +@ApplicationScoped +public class ShiroProducer { + + @Produces + public Subject subject() { + return proxy(Subject.class, new SubjectInvocationHandler()); + } + + @Produces + public SecurityManager securityManager() { + return proxy(SecurityManager.class, new SecurityManagerInvocationHandler()); + } + + @Produces + public Session session() { + return proxy(Session.class, new SessionInvocationHandler()); + } + + private static ShiroException unwrap(InvocationTargetException exc) { + if (exc.getCause() instanceof ShiroException) { + return (ShiroException) exc.getCause(); + } + else { + return new ShiroException(exc.getCause()); + } + } + + @SuppressWarnings("unchecked") + private T proxy(final Class clazz, final InvocationHandler ih) { + ClassLoader cl = getClass().getClassLoader(); + return (T) Proxy.newProxyInstance(cl, new Class[] { clazz }, ih); + } + + private static class SubjectInvocationHandler extends Handler { + + public Object handlerInvoke(final Object proxy, final Method method, final Object[] args) { + try { + return method.invoke(getSubject(), args); + } + catch (IllegalAccessException exc) { + throw new ShiroException(exc); + } + catch (IllegalArgumentException exc) { + throw new ShiroException(exc); + } + catch (InvocationTargetException exc) { + throw unwrap(exc); + } + } + } + + private class SecurityManagerInvocationHandler extends Handler { + + private SecurityManager delegate = getSecurityManager(); + + public Object handlerInvoke(Object proxy, Method method, Object[] args) { + try { + SecurityManager sm = getSecurityManager(); + // avoid infinite recursion + if (sm == proxy) { + sm = delegate; + } + return method.invoke(sm, args); + } + catch (IllegalAccessException exc) { + throw new ShiroException(exc); + } + catch (IllegalArgumentException exc) { + throw new ShiroException(exc); + } + catch (InvocationTargetException exc) { + throw unwrap(exc); + } + } + } + + private class SessionInvocationHandler extends Handler { + + public Object handlerInvoke(Object proxy, Method method, Object[] args) { + try { + return method.invoke(getSubject().getSession(), args); + } + catch (IllegalAccessException exc) { + throw new ShiroException(exc); + } + catch (IllegalArgumentException exc) { + throw new ShiroException(exc); + } + catch (InvocationTargetException exc) { + throw unwrap(exc); + } + } + } + + private abstract static class Handler implements InvocationHandler { + + public abstract Object handlerInvoke(Object proxy, Method method, Object[] args); + + public Object invoke(Object proxy, Method method, Object[] args) { + return handlerInvoke(proxy, method, args); + } + } +} diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/package-info.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/package-info.java new file mode 100644 index 0000000000..be46c07420 --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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. + */ + +/** + * Integration of CDI and Shiro bean concepts. + */ +package org.ops4j.pax.shiro.cdi.impl; diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptor.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptor.java new file mode 100644 index 0000000000..96e764066b --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptor.java @@ -0,0 +1,69 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.interceptor; + +import java.lang.reflect.Method; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import org.apache.shiro.aop.MethodInvocation; +import org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor; +import org.ops4j.pax.shiro.cdi.ShiroSecured; + +/** + * An interceptor for declarative security checks using the annotations from the + * {@code org.apache.shiro.authz.annotation} package. + * + */ +@Interceptor +@ShiroSecured +public class ShiroInterceptor extends AnnotationsAuthorizingMethodInterceptor { + @AroundInvoke + public Object around(final InvocationContext ic) throws Exception { + assertAuthorized(new InvocationContextToMethodInvocationConverter(ic)); + return ic.proceed(); + } + + private static class InvocationContextToMethodInvocationConverter implements MethodInvocation { + private final InvocationContext context; + + public InvocationContextToMethodInvocationConverter(InvocationContext ctx) { + context = ctx; + } + + // CHECKSTYLE:SKIP - interceptor API + public Object proceed() throws Exception { + return context.proceed(); + } + + public Method getMethod() { + return context.getMethod(); + } + + public Object[] getArguments() { + return context.getParameters(); + } + + public Object getThis() { + return context.getTarget(); + } + } +} diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/package-info.java b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/package-info.java new file mode 100644 index 0000000000..0b1f5f323a --- /dev/null +++ b/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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. + */ + +/** + * Annotations for securing applications with Shiro in combination + * with CDI. + */ +package org.ops4j.pax.shiro.cdi; diff --git a/support/cdi/core/src/main/resources/META-INF/beans.xml b/support/cdi/core/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000..edd9bee292 --- /dev/null +++ b/support/cdi/core/src/main/resources/META-INF/beans.xml @@ -0,0 +1,14 @@ + + diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/AbstractCdiTest.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/AbstractCdiTest.java new file mode 100644 index 0000000000..dc60e462b7 --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/AbstractCdiTest.java @@ -0,0 +1,68 @@ +/* + * 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.ops4j.pax.shiro.cdi; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authz.Permission; +import org.apache.shiro.authz.permission.RolePermissionResolver; +import org.apache.shiro.authz.permission.WildcardPermission; +import org.apache.shiro.mgt.DefaultSecurityManager; +import org.apache.shiro.realm.SimpleAccountRealm; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.junit.PaxExam; + +@RunWith(PaxExam.class) +public abstract class AbstractCdiTest { + + private static SimpleAccountRealm realm; + private static DefaultSecurityManager securityManager; + + @BeforeClass + public static void start() throws Exception { + securityManager = new DefaultSecurityManager(); + SecurityUtils.setSecurityManager(securityManager); + + + realm = new SimpleAccountRealm("test-realm"); + realm.addRole("role"); + realm.addAccount("foo", "bar", "role"); + realm.addAccount("bilbo", "precious", "hobbit"); + realm.setRolePermissionResolver(new RolePermissionResolver() { + public Collection resolvePermissionsInRole(String roleString) { + if ("role".equals(roleString)) { + final Permission dp = new WildcardPermission("permission"); + return Arrays.asList(dp); + } + return Collections.emptyList(); + } + }); + securityManager.setRealm(realm); + } + + @AfterClass + public static void close() throws Exception { + SecurityUtils.setSecurityManager(null); + } + + protected String getRealmName() { + return realm.getName(); + } +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/ShiroFactoryTest.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/ShiroFactoryTest.java new file mode 100644 index 0000000000..748aea8c0e --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/ShiroFactoryTest.java @@ -0,0 +1,39 @@ +package org.ops4j.pax.shiro.cdi; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import javax.inject.Inject; + +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.session.Session; +import org.apache.shiro.subject.Subject; +import org.junit.Test; + +public class ShiroFactoryTest extends AbstractCdiTest { + + @Inject + private Subject subject; + + @Inject + private SecurityManager securityManager; + + @Inject + private Session session; + + @Test + public void checkSubjectIsManaged() { + assertNotNull(subject); + assertFalse(subject.isAuthenticated()); + } + + @Test + public void checkSecurityManagerIsManaged() { + assertNotNull(securityManager); + } + + @Test + public void checkSessionIsManaged() { + assertNotNull(session); + } +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java new file mode 100644 index 0000000000..5f2b471e68 --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java @@ -0,0 +1,102 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.config; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; + +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.UsernamePasswordToken; +import org.apache.shiro.authc.credential.PasswordMatcher; +import org.apache.shiro.mgt.DefaultSecurityManager; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.realm.text.IniRealm; +import org.apache.shiro.subject.Subject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.junit.PaxExam; + + +@RunWith(PaxExam.class) +public class CdiIniSecurityManagerFactoryTest { + + + @Inject + private BeanManager beanManager; + + @Inject + private Subject subject; + + @Test + public void getShiroBeanFromIni() { + CdiIniSecurityManagerFactory securityManagerFactory = new CdiIniSecurityManagerFactory("classpath:test-shiro.ini", beanManager); + SecurityManager securityManager = securityManagerFactory.createInstance(); + assertThat(securityManager, is(notNullValue())); + Object passwordMatcher = securityManagerFactory.getBeans().get("passwordMatcher"); + assertThat(passwordMatcher, is(instanceOf(PasswordMatcher.class))); + } + + @Test + public void getCdiBeanFromIni() { + CdiIniSecurityManagerFactory securityManagerFactory = new CdiIniSecurityManagerFactory("classpath:test-shiro-cdi.ini", beanManager); + DefaultSecurityManager securityManager = (DefaultSecurityManager) securityManagerFactory.createInstance(); + assertThat(securityManager, is(notNullValue())); + + SecurityUtils.setSecurityManager(securityManager); + Object passwordMatcher = securityManagerFactory.getBeans().get("myPasswordMatcher"); + assertThat(passwordMatcher, is(instanceOf(MyPasswordMatcher.class))); + IniRealm realm = (IniRealm) securityManager.getRealms().iterator().next(); + assertThat(realm.getCredentialsMatcher(), is(instanceOf(MyPasswordMatcher.class))); + Subject subject = SecurityUtils.getSubject(); + assertThat(subject, is(notNullValue())); + assertThat(subject.getPrincipal(), is(nullValue())); + assertThat(subject.isAuthenticated(), is(false)); + UsernamePasswordToken token = new UsernamePasswordToken("admin", "secret"); + subject.login(token); + assertThat(subject.isAuthenticated(), is(true)); + + subject.logout(); + assertThat(subject.isAuthenticated(), is(false)); + } + + @Test + public void checkInjectedSubject() { + CdiIniSecurityManagerFactory securityManagerFactory = new CdiIniSecurityManagerFactory("classpath:test-shiro-cdi.ini", beanManager); + DefaultSecurityManager securityManager = (DefaultSecurityManager) securityManagerFactory.createInstance(); + assertThat(securityManager, is(notNullValue())); + SecurityUtils.setSecurityManager(securityManager); + + assertThat(subject, is(notNullValue())); + assertThat(subject.getPrincipal(), is(nullValue())); + assertThat(subject.isAuthenticated(), is(false)); + UsernamePasswordToken token = new UsernamePasswordToken("admin", "secret"); + subject.login(token); + assertThat(subject.isAuthenticated(), is(true)); + + subject.logout(); + assertThat(subject.isAuthenticated(), is(false)); + } + +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/MyPasswordMatcher.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/MyPasswordMatcher.java new file mode 100644 index 0000000000..c29ccb2b0c --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/MyPasswordMatcher.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.config; + +import javax.inject.Named; + +import org.apache.shiro.authc.credential.SimpleCredentialsMatcher; +import org.ops4j.pax.shiro.cdi.ShiroIni; + +@Named @ShiroIni +public class MyPasswordMatcher extends SimpleCredentialsMatcher { + +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProviderTest.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProviderTest.java new file mode 100644 index 0000000000..2f227a15f2 --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProviderTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.junit.Assert.assertThat; + +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.junit.PaxExam; + +@RunWith(PaxExam.class) +public class BeanManagerProviderTest { + + @Inject + private BeanManager beanManager; + + @Test + public void findBeanManagerWithoutJndi() { + BeanManagerProvider.setBeanManager(beanManager); + assertThat(BeanManagerProvider.getBeanManager(), is(sameInstance(beanManager))); + } +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Curry.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Curry.java new file mode 100644 index 0000000000..ca9abb4f23 --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Curry.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + +import org.ops4j.pax.shiro.cdi.ShiroIni; + + +/** + * @author Harald Wellmann + * + */ +@ShiroIni +public class Curry implements Food { + + public String getFlavour() { + return "hot"; + } + + public String getOrigin() { + return "India"; + } +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Food.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Food.java new file mode 100644 index 0000000000..330e22a202 --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Food.java @@ -0,0 +1,32 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + + +/** + * @author Harald Wellmann + * + */ +public interface Food { + + String getFlavour(); + + String getOrigin(); + +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/IceCream.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/IceCream.java new file mode 100644 index 0000000000..d6fd9f4ca0 --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/IceCream.java @@ -0,0 +1,41 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + +import javax.enterprise.context.ApplicationScoped; + +import org.ops4j.pax.shiro.cdi.ShiroIni; + + +/** + * @author Harald Wellmann + * + */ +@ShiroIni +@ApplicationScoped +public class IceCream implements Food { + + public String getFlavour() { + return "sweet"; + } + + public String getOrigin() { + return "Italy"; + } +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMapTest.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMapTest.java new file mode 100644 index 0000000000..c8ae7d97b2 --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMapTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.junit.PaxExam; + +@RunWith(PaxExam.class) +public class NamedBeanMapTest { + + @Inject + private BeanManager beanManager; + + @Test + public void findNamedBeans() { + NamedBeanMap namedBeanMap = new NamedBeanMap(beanManager); + assertThat(namedBeanMap.isEmpty(), is(false)); + + List origins = new ArrayList(); + for (Map.Entry entry : namedBeanMap.entrySet()) { + Object object = entry.getValue(); + if (object instanceof Food) { + Food food = (Food) object; + origins.add(food.getOrigin()); + } + } + assertThat(origins.size(), is(3)); + assertThat(origins, hasItems("Germany", "India", "Italy")); + } +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Sausage.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Sausage.java new file mode 100644 index 0000000000..9b6750d2c2 --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Sausage.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.impl; + +import org.ops4j.pax.shiro.cdi.ShiroIni; + + +/** + * @author Harald Wellmann + * + */ +@ShiroIni +public class Sausage implements Food { + + public String getFlavour() { + return "fatty"; + } + + public String getOrigin() { + return "Germany"; + } +} diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptorTest.java b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptorTest.java new file mode 100644 index 0000000000..df73bdab8f --- /dev/null +++ b/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptorTest.java @@ -0,0 +1,166 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.interceptor; + +import static org.junit.Assert.assertEquals; + +import javax.inject.Inject; + +import org.apache.shiro.authz.UnauthenticatedException; +import org.apache.shiro.authz.UnauthorizedException; +import org.apache.shiro.authz.annotation.RequiresAuthentication; +import org.apache.shiro.authz.annotation.RequiresGuest; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.apache.shiro.authz.annotation.RequiresRoles; +import org.apache.shiro.authz.annotation.RequiresUser; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.subject.PrincipalCollection; +import org.apache.shiro.subject.SimplePrincipalCollection; +import org.apache.shiro.subject.Subject; +import org.apache.shiro.subject.support.SubjectThreadState; +import org.apache.shiro.util.ThreadState; +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.ops4j.pax.shiro.cdi.AbstractCdiTest; +import org.ops4j.pax.shiro.cdi.ShiroSecured; + +public class ShiroInterceptorTest extends AbstractCdiTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Inject + private SecuredService service; + + @Inject + private SecurityManager securityManager; + + private ThreadState threadState; + + @After + public void clearSubject() { + if (threadState != null) { + threadState.clear(); + } + } + + protected void bind(Subject subject) { + clearSubject(); + this.threadState = new SubjectThreadState(subject); + this.threadState.bind(); + } + + protected void bindUser() { + PrincipalCollection principals = new SimplePrincipalCollection("foo", getRealmName()); + bind(new Subject.Builder(securityManager).principals(principals).buildSubject()); + } + + protected void bindHobbit() { + PrincipalCollection principals = new SimplePrincipalCollection("bilbo", getRealmName()); + bind(new Subject.Builder(securityManager).principals(principals).buildSubject()); + } + + protected void bindAuthenticatedUser() { + PrincipalCollection principals = new SimplePrincipalCollection("foo", getRealmName()); + bind(new Subject.Builder(securityManager). + principals(principals).authenticated(true).buildSubject()); + } + + @Test + public void guest() { + assertEquals("hi foo", service.simple("foo")); + + thrown.expect(UnauthenticatedException.class); + service.authentication("foo"); + } + + @Test + public void role() { + bindUser(); + assertEquals("hi foo", service.role("foo")); + } + + @Test + public void missingRole() { + bindHobbit(); + + thrown.expect(UnauthorizedException.class); + service.role("foo"); + } + + @Test + public void permission() { + bindUser(); + assertEquals("hi foo", service.permission("foo")); + } + + @Test + public void ḿissingPermission() { + bindHobbit(); + + thrown.expect(UnauthorizedException.class); + service.permission("foo"); + } + + @Test + public void authentication() { + bindAuthenticatedUser(); + assertEquals("hi foo", service.authentication("foo")); + + thrown.expect(UnauthenticatedException.class); + service.simple("foo"); + + } + + @Test + public void user() { + bindUser(); + assertEquals("hi foo", service.user("foo")); + } + + @ShiroSecured + public static class SecuredService { + @RequiresGuest + public String simple(final String name) { + return "hi " + name; + } + + @RequiresRoles({"role"}) + public String role(final String name) { + return "hi " + name; + } + + @RequiresPermissions({"permission"}) + public String permission(final String name) { + return "hi " + name; + } + + @RequiresAuthentication + public String authentication(final String name) { + return "hi " + name; + } + + @RequiresUser + public String user(final String name) { + return "hi " + name; + } + } +} diff --git a/support/cdi/core/src/test/resources/META-INF/beans.xml b/support/cdi/core/src/test/resources/META-INF/beans.xml new file mode 100644 index 0000000000..645aaa80a9 --- /dev/null +++ b/support/cdi/core/src/test/resources/META-INF/beans.xml @@ -0,0 +1,23 @@ + + + + org.ops4j.pax.shiro.cdi.interceptor.ShiroInterceptor + + diff --git a/support/cdi/core/src/test/resources/exam.properties b/support/cdi/core/src/test/resources/exam.properties new file mode 100644 index 0000000000..e1dc015f91 --- /dev/null +++ b/support/cdi/core/src/test/resources/exam.properties @@ -0,0 +1 @@ +pax.exam.system = cdi diff --git a/support/cdi/core/src/test/resources/log4j.properties b/support/cdi/core/src/test/resources/log4j.properties new file mode 100644 index 0000000000..b2b1a5790a --- /dev/null +++ b/support/cdi/core/src/test/resources/log4j.properties @@ -0,0 +1,38 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# +log4j.rootLogger=TRACE, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m %n + +# Pattern to output: date priority [category] - message +log4j.appender.logfile.layout=org.apache.log4j.PatternLayout +log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n + +# Spring logging level is WARN +log4j.logger.org.springframework=WARN + +# General Apache libraries is WARN +log4j.logger.org.apache=WARN + +log4j.logger.net.sf.ehcache=WARN + +log4j.logger.org.apache.shiro=INFO +log4j.logger.org.apache.shiro.util.ThreadContext=WARN \ No newline at end of file diff --git a/support/cdi/core/src/test/resources/test-shiro-cdi.ini b/support/cdi/core/src/test/resources/test-shiro-cdi.ini new file mode 100644 index 0000000000..6dd5f3f9c0 --- /dev/null +++ b/support/cdi/core/src/test/resources/test-shiro-cdi.ini @@ -0,0 +1,5 @@ +[main] +iniRealm.credentialsMatcher = $myPasswordMatcher + +[users] +admin = secret \ No newline at end of file diff --git a/support/cdi/core/src/test/resources/test-shiro.ini b/support/cdi/core/src/test/resources/test-shiro.ini new file mode 100644 index 0000000000..57d185df15 --- /dev/null +++ b/support/cdi/core/src/test/resources/test-shiro.ini @@ -0,0 +1,4 @@ +[main] + +passwordMatcher = org.apache.shiro.authc.credential.PasswordMatcher + diff --git a/support/cdi/pom.xml b/support/cdi/pom.xml new file mode 100644 index 0000000000..d5d286be56 --- /dev/null +++ b/support/cdi/pom.xml @@ -0,0 +1,40 @@ + + + + + + org.apache.shiro + shiro-root + 1.3.0-SNAPSHOT + ../../pom.xml + + + 4.0.0 + shiro-cdi + Apache Shiro :: CDI + pom + + + core + web + + + + diff --git a/support/cdi/web/pom.xml b/support/cdi/web/pom.xml new file mode 100644 index 0000000000..35fa19d501 --- /dev/null +++ b/support/cdi/web/pom.xml @@ -0,0 +1,79 @@ + + 4.0.0 + + org.apache.shiro + shiro-cdi + 1.3.0-SNAPSHOT + + shiro-cdi-web + bundle + + Apache Shiro :: CDI :: Web + + + cdi.web + + + + + org.apache.shiro + shiro-cdi-core + ${project.version} + + + org.apache.shiro + shiro-web + + + org.apache.geronimo.specs + geronimo-jcdi_1.0_spec + 1.0 + provided + + + org.apache.geronimo.specs + geronimo-interceptor_1.1_spec + 1.0 + provided + + + org.apache.geronimo.specs + geronimo-atinject_1.0_spec + 1.0 + provided + + + org.apache.geronimo.specs + geronimo-servlet_3.0_spec + 1.0 + test + + + + + + + + + org.apache.openwebbeans.test + cditest-owb + 1.1.8 + test + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + + + + + + + \ No newline at end of file diff --git a/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiIniWebEnvironment.java b/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiIniWebEnvironment.java new file mode 100644 index 0000000000..091b4d1b28 --- /dev/null +++ b/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiIniWebEnvironment.java @@ -0,0 +1,62 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.web; + +import java.util.Map; + +import javax.enterprise.inject.spi.BeanManager; + +import org.apache.shiro.config.Ini; +import org.apache.shiro.config.IniSecurityManagerFactory; +import org.apache.shiro.util.CollectionUtils; +import org.apache.shiro.web.env.IniWebEnvironment; +import org.apache.shiro.web.mgt.WebSecurityManager; +import org.ops4j.pax.shiro.cdi.impl.BeanManagerProvider; + + +/** + * An extension of {@link IniWebEnvironment} which makes CDI beans qualified with + * {@code @ShiroIni} available to Shiro, to be referenced in INI files. + * + * @author Harald Wellmann + */ +public class CdiIniWebEnvironment extends IniWebEnvironment { + + + @Override + protected WebSecurityManager createWebSecurityManager() { + Ini ini = getIni(); + + if (CollectionUtils.isEmpty(ini)) { + ini = null; + } + + BeanManager beanManager = BeanManagerProvider.getBeanManager(); + IniSecurityManagerFactory factory = new CdiWebIniSecurityManagerFactory(beanManager); + factory.setIni(ini); + + WebSecurityManager wsm = (WebSecurityManager)factory.getInstance(); + Map beans = factory.getBeans(); + if (!CollectionUtils.isEmpty(beans)) { + this.objects.putAll(beans); + } + + return wsm; + } +} diff --git a/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java b/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java new file mode 100644 index 0000000000..3b1a31e8c0 --- /dev/null +++ b/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java @@ -0,0 +1,55 @@ +/* + * Copyright 2013 Harald Wellmann + * + * 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.ops4j.pax.shiro.cdi.web; + +import java.util.Map; + +import javax.enterprise.inject.spi.BeanManager; + +import org.apache.shiro.config.Ini; +import org.apache.shiro.config.Ini.Section; +import org.apache.shiro.web.config.WebIniSecurityManagerFactory; +import org.ops4j.pax.shiro.cdi.impl.NamedBeanMap; + + +/** + * A CDI-aware extension of {@link WebIniSecurityManagerFactory}. Constructs a named bean + * map from the CDI BeanManager and uses these beans as additional default for Shiro + * bean lookup. + * + * @author Harald Wellmann + * + */ +public class CdiWebIniSecurityManagerFactory extends WebIniSecurityManagerFactory { + + + private Map namedBeanMap; + + public CdiWebIniSecurityManagerFactory(BeanManager beanManager) { + this.namedBeanMap = new NamedBeanMap(beanManager); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + protected Map createDefaults(Ini ini, Section mainSection) { + Map defaults = super.createDefaults(ini, mainSection); + defaults.putAll(namedBeanMap); + return defaults; + } +} diff --git a/support/pom.xml b/support/pom.xml index 7fbd4c8fd2..bae318d319 100644 --- a/support/pom.xml +++ b/support/pom.xml @@ -39,6 +39,7 @@ guice features cas + cdi From 8e40907d67e38b961ddffba7a2411bc8745f8139 Mon Sep 17 00:00:00 2001 From: Brian Demers Date: Tue, 5 Jul 2016 15:38:53 -0400 Subject: [PATCH 2/6] renamed cdi packages after import --- .../java/org/{ops4j/pax => apache}/shiro/cdi/ShiroIni.java | 2 +- .../org/{ops4j/pax => apache}/shiro/cdi/ShiroSecured.java | 2 +- .../shiro/cdi/config/CdiIniSecurityManagerFactory.java | 4 ++-- .../pax => apache}/shiro/cdi/impl/BeanManagerProvider.java | 2 +- .../{ops4j/pax => apache}/shiro/cdi/impl/NamedBeanMap.java | 2 +- .../pax => apache}/shiro/cdi/impl/ShiroIniLiteral.java | 4 ++-- .../{ops4j/pax => apache}/shiro/cdi/impl/ShiroProducer.java | 2 +- .../{ops4j/pax => apache}/shiro/cdi/impl/package-info.java | 2 +- .../shiro/cdi/interceptor/ShiroInterceptor.java | 4 ++-- .../org/{ops4j/pax => apache}/shiro/cdi/package-info.java | 2 +- .../{ops4j/pax => apache}/shiro/cdi/AbstractCdiTest.java | 2 +- .../{ops4j/pax => apache}/shiro/cdi/ShiroFactoryTest.java | 2 +- .../shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java | 2 +- .../pax => apache}/shiro/cdi/config/MyPasswordMatcher.java | 4 ++-- .../shiro/cdi/impl/BeanManagerProviderTest.java | 2 +- .../org/{ops4j/pax => apache}/shiro/cdi/impl/Curry.java | 4 ++-- .../java/org/{ops4j/pax => apache}/shiro/cdi/impl/Food.java | 2 +- .../org/{ops4j/pax => apache}/shiro/cdi/impl/IceCream.java | 4 ++-- .../pax => apache}/shiro/cdi/impl/NamedBeanMapTest.java | 2 +- .../org/{ops4j/pax => apache}/shiro/cdi/impl/Sausage.java | 4 ++-- .../shiro/cdi/interceptor/ShiroInterceptorTest.java | 6 +++--- support/cdi/core/src/test/resources/META-INF/beans.xml | 2 +- .../pax => apache}/shiro/cdi/web/CdiIniWebEnvironment.java | 4 ++-- .../shiro/cdi/web/CdiWebIniSecurityManagerFactory.java | 4 ++-- 24 files changed, 35 insertions(+), 35 deletions(-) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/ShiroIni.java (98%) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/ShiroSecured.java (98%) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/config/CdiIniSecurityManagerFactory.java (96%) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/impl/BeanManagerProvider.java (98%) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/impl/NamedBeanMap.java (99%) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/impl/ShiroIniLiteral.java (92%) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/impl/ShiroProducer.java (99%) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/impl/package-info.java (94%) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/interceptor/ShiroInterceptor.java (95%) rename support/cdi/core/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/package-info.java (95%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/AbstractCdiTest.java (98%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/ShiroFactoryTest.java (96%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java (99%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/config/MyPasswordMatcher.java (90%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/impl/BeanManagerProviderTest.java (97%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/impl/Curry.java (91%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/impl/Food.java (95%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/impl/IceCream.java (91%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/impl/NamedBeanMapTest.java (97%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/impl/Sausage.java (91%) rename support/cdi/core/src/test/java/org/{ops4j/pax => apache}/shiro/cdi/interceptor/ShiroInterceptorTest.java (97%) rename support/cdi/web/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/web/CdiIniWebEnvironment.java (95%) rename support/cdi/web/src/main/java/org/{ops4j/pax => apache}/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java (94%) diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroIni.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java similarity index 98% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroIni.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java index bb14a510ba..cc14eb52ee 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroIni.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi; +package org.apache.shiro.cdi; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroSecured.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java similarity index 98% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroSecured.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java index 4a0b883468..c310f11731 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/ShiroSecured.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi; +package org.apache.shiro.cdi; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactory.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java similarity index 96% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactory.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java index eb5ece63d8..145d350420 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactory.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java @@ -16,16 +16,16 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.config; +package org.apache.shiro.cdi.config; import java.util.Map; import javax.enterprise.inject.spi.BeanManager; +import org.apache.shiro.cdi.impl.NamedBeanMap; import org.apache.shiro.config.Ini; import org.apache.shiro.config.IniSecurityManagerFactory; import org.apache.shiro.config.Ini.Section; -import org.ops4j.pax.shiro.cdi.impl.NamedBeanMap; /** diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProvider.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java similarity index 98% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProvider.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java index cf3f067f14..44c55dfbb9 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProvider.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; import javax.enterprise.inject.spi.BeanManager; import javax.naming.InitialContext; diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMap.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java similarity index 99% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMap.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java index f49baa5b10..fc571156a4 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMap.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; import java.util.Collection; import java.util.HashMap; diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroIniLiteral.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java similarity index 92% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroIniLiteral.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java index 83b66cdc79..88f9472d84 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroIniLiteral.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java @@ -16,11 +16,11 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; import javax.enterprise.util.AnnotationLiteral; -import org.ops4j.pax.shiro.cdi.ShiroIni; +import org.apache.shiro.cdi.ShiroIni; /** diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroProducer.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroProducer.java similarity index 99% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroProducer.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroProducer.java index feff53436e..4da8361fdf 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/ShiroProducer.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroProducer.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; import static org.apache.shiro.SecurityUtils.getSecurityManager; import static org.apache.shiro.SecurityUtils.getSubject; diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/package-info.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/package-info.java similarity index 94% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/package-info.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/package-info.java index be46c07420..361a34df49 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/impl/package-info.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/package-info.java @@ -19,4 +19,4 @@ /** * Integration of CDI and Shiro bean concepts. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptor.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/interceptor/ShiroInterceptor.java similarity index 95% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptor.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/interceptor/ShiroInterceptor.java index 96e764066b..9d78e2868a 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptor.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/interceptor/ShiroInterceptor.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.interceptor; +package org.apache.shiro.cdi.interceptor; import java.lang.reflect.Method; @@ -26,7 +26,7 @@ import org.apache.shiro.aop.MethodInvocation; import org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor; -import org.ops4j.pax.shiro.cdi.ShiroSecured; +import org.apache.shiro.cdi.ShiroSecured; /** * An interceptor for declarative security checks using the annotations from the diff --git a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/package-info.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/package-info.java similarity index 95% rename from support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/package-info.java rename to support/cdi/core/src/main/java/org/apache/shiro/cdi/package-info.java index 0b1f5f323a..0fd01ef079 100644 --- a/support/cdi/core/src/main/java/org/ops4j/pax/shiro/cdi/package-info.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/package-info.java @@ -20,4 +20,4 @@ * Annotations for securing applications with Shiro in combination * with CDI. */ -package org.ops4j.pax.shiro.cdi; +package org.apache.shiro.cdi; diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/AbstractCdiTest.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/AbstractCdiTest.java similarity index 98% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/AbstractCdiTest.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/AbstractCdiTest.java index dc60e462b7..a384d98f8a 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/AbstractCdiTest.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/AbstractCdiTest.java @@ -12,7 +12,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi; +package org.apache.shiro.cdi; import java.util.Arrays; import java.util.Collection; diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/ShiroFactoryTest.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/ShiroFactoryTest.java similarity index 96% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/ShiroFactoryTest.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/ShiroFactoryTest.java index 748aea8c0e..6eafd41749 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/ShiroFactoryTest.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/ShiroFactoryTest.java @@ -1,4 +1,4 @@ -package org.ops4j.pax.shiro.cdi; +package org.apache.shiro.cdi; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java similarity index 99% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java index 5f2b471e68..266e6289d1 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactoryTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.config; +package org.apache.shiro.cdi.config; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/MyPasswordMatcher.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/config/MyPasswordMatcher.java similarity index 90% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/MyPasswordMatcher.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/config/MyPasswordMatcher.java index c29ccb2b0c..a7fa4eccb3 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/config/MyPasswordMatcher.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/config/MyPasswordMatcher.java @@ -16,12 +16,12 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.config; +package org.apache.shiro.cdi.config; import javax.inject.Named; import org.apache.shiro.authc.credential.SimpleCredentialsMatcher; -import org.ops4j.pax.shiro.cdi.ShiroIni; +import org.apache.shiro.cdi.ShiroIni; @Named @ShiroIni public class MyPasswordMatcher extends SimpleCredentialsMatcher { diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProviderTest.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/BeanManagerProviderTest.java similarity index 97% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProviderTest.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/BeanManagerProviderTest.java index 2f227a15f2..1a088f7101 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/BeanManagerProviderTest.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/BeanManagerProviderTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.sameInstance; diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Curry.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Curry.java similarity index 91% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Curry.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Curry.java index ca9abb4f23..5fba0c5d2f 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Curry.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Curry.java @@ -16,9 +16,9 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; -import org.ops4j.pax.shiro.cdi.ShiroIni; +import org.apache.shiro.cdi.ShiroIni; /** diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Food.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Food.java similarity index 95% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Food.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Food.java index 330e22a202..d2c37a4073 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Food.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Food.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; /** diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/IceCream.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/IceCream.java similarity index 91% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/IceCream.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/IceCream.java index d6fd9f4ca0..af0ccb54cf 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/IceCream.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/IceCream.java @@ -16,11 +16,11 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; import javax.enterprise.context.ApplicationScoped; -import org.ops4j.pax.shiro.cdi.ShiroIni; +import org.apache.shiro.cdi.ShiroIni; /** diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMapTest.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/NamedBeanMapTest.java similarity index 97% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMapTest.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/NamedBeanMapTest.java index c8ae7d97b2..e54ec6ed76 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMapTest.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/NamedBeanMapTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.is; diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Sausage.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Sausage.java similarity index 91% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Sausage.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Sausage.java index 9b6750d2c2..f0ba818a13 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/impl/Sausage.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Sausage.java @@ -16,9 +16,9 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.impl; +package org.apache.shiro.cdi.impl; -import org.ops4j.pax.shiro.cdi.ShiroIni; +import org.apache.shiro.cdi.ShiroIni; /** diff --git a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptorTest.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/interceptor/ShiroInterceptorTest.java similarity index 97% rename from support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptorTest.java rename to support/cdi/core/src/test/java/org/apache/shiro/cdi/interceptor/ShiroInterceptorTest.java index df73bdab8f..ce76dd0d69 100644 --- a/support/cdi/core/src/test/java/org/ops4j/pax/shiro/cdi/interceptor/ShiroInterceptorTest.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/interceptor/ShiroInterceptorTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.interceptor; +package org.apache.shiro.cdi.interceptor; import static org.junit.Assert.assertEquals; @@ -29,6 +29,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresUser; +import org.apache.shiro.cdi.ShiroSecured; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.subject.PrincipalCollection; import org.apache.shiro.subject.SimplePrincipalCollection; @@ -39,8 +40,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.ops4j.pax.shiro.cdi.AbstractCdiTest; -import org.ops4j.pax.shiro.cdi.ShiroSecured; +import org.apache.shiro.cdi.AbstractCdiTest; public class ShiroInterceptorTest extends AbstractCdiTest { diff --git a/support/cdi/core/src/test/resources/META-INF/beans.xml b/support/cdi/core/src/test/resources/META-INF/beans.xml index 645aaa80a9..c74bdaad72 100644 --- a/support/cdi/core/src/test/resources/META-INF/beans.xml +++ b/support/cdi/core/src/test/resources/META-INF/beans.xml @@ -18,6 +18,6 @@ http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd"> - org.ops4j.pax.shiro.cdi.interceptor.ShiroInterceptor + org.apache.shiro.cdi.interceptor.ShiroInterceptor diff --git a/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiIniWebEnvironment.java b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java similarity index 95% rename from support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiIniWebEnvironment.java rename to support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java index 091b4d1b28..53ca381bd5 100644 --- a/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiIniWebEnvironment.java +++ b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.web; +package org.apache.shiro.cdi.web; import java.util.Map; @@ -27,7 +27,7 @@ import org.apache.shiro.util.CollectionUtils; import org.apache.shiro.web.env.IniWebEnvironment; import org.apache.shiro.web.mgt.WebSecurityManager; -import org.ops4j.pax.shiro.cdi.impl.BeanManagerProvider; +import org.apache.shiro.cdi.impl.BeanManagerProvider; /** diff --git a/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java similarity index 94% rename from support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java rename to support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java index 3b1a31e8c0..365fa8e1c9 100644 --- a/support/cdi/web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java +++ b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java @@ -16,16 +16,16 @@ * limitations under the License. */ -package org.ops4j.pax.shiro.cdi.web; +package org.apache.shiro.cdi.web; import java.util.Map; import javax.enterprise.inject.spi.BeanManager; +import org.apache.shiro.cdi.impl.NamedBeanMap; import org.apache.shiro.config.Ini; import org.apache.shiro.config.Ini.Section; import org.apache.shiro.web.config.WebIniSecurityManagerFactory; -import org.ops4j.pax.shiro.cdi.impl.NamedBeanMap; /** From b806d61d40aad94db5e9f76b10e57d54cab8ba52 Mon Sep 17 00:00:00 2001 From: Brian Demers Date: Tue, 5 Jul 2016 16:14:46 -0400 Subject: [PATCH 3/6] Replaced geronimo spec dependencies with javax equivalents --- pom.xml | 15 ++++++++ support/cdi/core/pom.xml | 74 +++++++++++++++++++--------------------- support/cdi/web/pom.xml | 40 +++++++++------------- 3 files changed, 67 insertions(+), 62 deletions(-) diff --git a/pom.xml b/pom.xml index 50ffdcbf9b..47a5a379d8 100644 --- a/pom.xml +++ b/pom.xml @@ -844,6 +844,21 @@ + + javax.inject + javax.inject + 1 + + + javax.interceptor + javax.interceptor-api + 1.2 + + + javax.enterprise + cdi-api + 1.2 + diff --git a/support/cdi/core/pom.xml b/support/cdi/core/pom.xml index 1eb3a6de63..b526bf067a 100644 --- a/support/cdi/core/pom.xml +++ b/support/cdi/core/pom.xml @@ -21,21 +21,19 @@ shiro-core - org.apache.geronimo.specs - geronimo-jcdi_1.0_spec - 1.0 + javax.enterprise + cdi-api - org.apache.geronimo.specs - geronimo-interceptor_1.1_spec - 1.0 + javax.interceptor + javax.interceptor-api - org.apache.geronimo.specs - geronimo-atinject_1.0_spec - 1.0 + javax.inject + javax.inject + org.ops4j.pax.exam pax-exam-junit4 @@ -73,14 +71,14 @@ - - - - - - - - + + org.apache.maven.plugins + maven-surefire-plugin + + 1 + 0 + + @@ -89,7 +87,7 @@ openwebbeans - true + false @@ -108,27 +106,27 @@ - - - - - - - - - - - - + + weld + + true + + + + org.jboss.weld + weld-core + 1.1.13.Final + test + - - - - - - - - + + org.ops4j.pax.exam + pax-exam-container-weld + ${pax.exam.version} + test + + + diff --git a/support/cdi/web/pom.xml b/support/cdi/web/pom.xml index 35fa19d501..a101bbe042 100644 --- a/support/cdi/web/pom.xml +++ b/support/cdi/web/pom.xml @@ -25,41 +25,33 @@ shiro-web - org.apache.geronimo.specs - geronimo-jcdi_1.0_spec - 1.0 + javax.inject + javax.inject provided - org.apache.geronimo.specs - geronimo-interceptor_1.1_spec - 1.0 - provided + javax.interceptor + javax.interceptor-api - org.apache.geronimo.specs - geronimo-atinject_1.0_spec - 1.0 + javax.inject + javax.inject provided - - org.apache.geronimo.specs - geronimo-servlet_3.0_spec - 1.0 - test - + - - + + + + + + + + + - - org.apache.openwebbeans.test - cditest-owb - 1.1.8 - test - From 4dfcbd0b770b2d45e8daf52f6ad80a26c9abb16b Mon Sep 17 00:00:00 2001 From: Brian Demers Date: Tue, 5 Jul 2016 16:33:06 -0400 Subject: [PATCH 4/6] Removed @author javadoc tags --- .../cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java | 3 --- .../core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java | 3 --- .../apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java | 3 --- .../java/org/apache/shiro/cdi/impl/BeanManagerProvider.java | 3 --- .../src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java | 3 --- .../main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java | 3 --- .../core/src/test/java/org/apache/shiro/cdi/impl/Curry.java | 3 +-- .../cdi/core/src/test/java/org/apache/shiro/cdi/impl/Food.java | 1 - .../core/src/test/java/org/apache/shiro/cdi/impl/IceCream.java | 3 +-- .../core/src/test/java/org/apache/shiro/cdi/impl/Sausage.java | 1 - .../java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java | 2 -- .../apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java | 3 --- 12 files changed, 2 insertions(+), 29 deletions(-) diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java index cc14eb52ee..9066b9755e 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java @@ -39,9 +39,6 @@ *

* In all other cases (e.g. for producer methods), Shiro will log a warning and the bean will not be * available in the Shiro environment. - * - * @author Harald Wellmann - * */ @Qualifier @Target({ TYPE, METHOD, PARAMETER, FIELD }) diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java index c310f11731..157b766e49 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java @@ -39,9 +39,6 @@ * * The secured methods will fail with an {@code AuthorizationException} if the current subject * does not match the security constraints. - * - * @author Harald Wellmann - * */ @Inherited @InterceptorBinding diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java index 145d350420..bf0e166b87 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java @@ -31,9 +31,6 @@ /** * A CDI-aware extension of {@code IniSecurityManagerFactory}, allowing to reference CDI * managed beans qualified with {@code @ShiroIni} in Shiro INI files. - * - * @author Harald Wellmann - * */ public class CdiIniSecurityManagerFactory extends IniSecurityManagerFactory { diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java index 44c55dfbb9..5f3c0ec149 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java @@ -29,9 +29,6 @@ * {@link #setBeanManager(BeanManager)}. *

* TODO In CDI 1.1, CDI.current().getBeanManager() should be used instead. - * - * @author Harald Wellmann - * */ public class BeanManagerProvider { diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java index fc571156a4..4f10f2b5f0 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java @@ -40,9 +40,6 @@ * Contextual references of these beans are eagerly created when this class is instantiated. This * is the main reason for using the dedicated {@code ShiroIni} qualifier, to avoid instantiating * all named beans. - * - * @author Harald Wellmann - * */ public class NamedBeanMap implements Map { diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java index 88f9472d84..d30193f75b 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java @@ -25,9 +25,6 @@ /** * A literal for the {@link ShiroIni} annotation. - * - * @author Harald Wellmann - * */ public class ShiroIniLiteral extends AnnotationLiteral { diff --git a/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Curry.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Curry.java index 5fba0c5d2f..e23eb7462b 100644 --- a/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Curry.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Curry.java @@ -22,8 +22,7 @@ /** - * @author Harald Wellmann - * + * */ @ShiroIni public class Curry implements Food { diff --git a/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Food.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Food.java index d2c37a4073..fc79dad7c6 100644 --- a/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Food.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Food.java @@ -20,7 +20,6 @@ /** - * @author Harald Wellmann * */ public interface Food { diff --git a/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/IceCream.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/IceCream.java index af0ccb54cf..c9b1b12956 100644 --- a/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/IceCream.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/IceCream.java @@ -24,8 +24,7 @@ /** - * @author Harald Wellmann - * + * */ @ShiroIni @ApplicationScoped diff --git a/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Sausage.java b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Sausage.java index f0ba818a13..6702a6abf9 100644 --- a/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Sausage.java +++ b/support/cdi/core/src/test/java/org/apache/shiro/cdi/impl/Sausage.java @@ -22,7 +22,6 @@ /** - * @author Harald Wellmann * */ @ShiroIni diff --git a/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java index 53ca381bd5..66b2176656 100644 --- a/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java +++ b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java @@ -33,8 +33,6 @@ /** * An extension of {@link IniWebEnvironment} which makes CDI beans qualified with * {@code @ShiroIni} available to Shiro, to be referenced in INI files. - * - * @author Harald Wellmann */ public class CdiIniWebEnvironment extends IniWebEnvironment { diff --git a/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java index 365fa8e1c9..decc57d9c1 100644 --- a/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java +++ b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java @@ -32,9 +32,6 @@ * A CDI-aware extension of {@link WebIniSecurityManagerFactory}. Constructs a named bean * map from the CDI BeanManager and uses these beans as additional default for Shiro * bean lookup. - * - * @author Harald Wellmann - * */ public class CdiWebIniSecurityManagerFactory extends WebIniSecurityManagerFactory { From 0200e716f2df8ad552bc852b356485696fae07a6 Mon Sep 17 00:00:00 2001 From: Brian Demers Date: Tue, 5 Jul 2016 17:00:42 -0400 Subject: [PATCH 5/6] Updated license headers to match project --- support/cdi/core/pom.xml | 20 +++++++++++ .../java/org/apache/shiro/cdi/ShiroIni.java | 30 ++++++++-------- .../org/apache/shiro/cdi/ShiroSecured.java | 30 ++++++++-------- .../config/CdiIniSecurityManagerFactory.java | 30 ++++++++-------- .../shiro/cdi/impl/BeanManagerProvider.java | 30 ++++++++-------- .../apache/shiro/cdi/impl/NamedBeanMap.java | 30 ++++++++-------- .../shiro/cdi/impl/ShiroIniLiteral.java | 30 ++++++++-------- .../apache/shiro/cdi/impl/ShiroProducer.java | 30 ++++++++-------- .../apache/shiro/cdi/impl/package-info.java | 30 ++++++++-------- .../cdi/interceptor/ShiroInterceptor.java | 30 ++++++++-------- .../org/apache/shiro/cdi/package-info.java | 30 ++++++++-------- .../src/main/resources/META-INF/beans.xml | 20 +++++++++++ .../org/apache/shiro/cdi/AbstractCdiTest.java | 18 ++++++++++ .../apache/shiro/cdi/ShiroFactoryTest.java | 18 ++++++++++ .../CdiIniSecurityManagerFactoryTest.java | 30 ++++++++-------- .../shiro/cdi/config/MyPasswordMatcher.java | 30 ++++++++-------- .../cdi/impl/BeanManagerProviderTest.java | 30 ++++++++-------- .../java/org/apache/shiro/cdi/impl/Curry.java | 30 ++++++++-------- .../java/org/apache/shiro/cdi/impl/Food.java | 30 ++++++++-------- .../org/apache/shiro/cdi/impl/IceCream.java | 30 ++++++++-------- .../shiro/cdi/impl/NamedBeanMapTest.java | 30 ++++++++-------- .../org/apache/shiro/cdi/impl/Sausage.java | 30 ++++++++-------- .../cdi/interceptor/ShiroInterceptorTest.java | 30 ++++++++-------- .../src/test/resources/META-INF/beans.xml | 20 +++++++++++ .../core/src/test/resources/exam.properties | 19 ++++++++++ .../core/src/test/resources/log4j.properties | 1 + support/cdi/pom.xml | 36 ++++++++++--------- support/cdi/web/pom.xml | 20 +++++++++++ .../shiro/cdi/web/CdiIniWebEnvironment.java | 30 ++++++++-------- .../web/CdiWebIniSecurityManagerFactory.java | 30 ++++++++-------- 30 files changed, 470 insertions(+), 332 deletions(-) diff --git a/support/cdi/core/pom.xml b/support/cdi/core/pom.xml index b526bf067a..307015daff 100644 --- a/support/cdi/core/pom.xml +++ b/support/cdi/core/pom.xml @@ -1,3 +1,23 @@ + 4.0.0 diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java index 9066b9755e..27e8838a56 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroIni.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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.apache.shiro.cdi; import static java.lang.annotation.ElementType.FIELD; diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java index 157b766e49..215ff6e0e3 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/ShiroSecured.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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.apache.shiro.cdi; import java.lang.annotation.ElementType; diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java index bf0e166b87..283165cd7e 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/config/CdiIniSecurityManagerFactory.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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.apache.shiro.cdi.config; import java.util.Map; diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java index 5f3c0ec149..eb4859e11f 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/BeanManagerProvider.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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.apache.shiro.cdi.impl; import javax.enterprise.inject.spi.BeanManager; diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java index 4f10f2b5f0..054be8a267 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/NamedBeanMap.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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.apache.shiro.cdi.impl; import java.util.Collection; diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java index d30193f75b..74ae366936 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroIniLiteral.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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.apache.shiro.cdi.impl; import javax.enterprise.util.AnnotationLiteral; diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroProducer.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroProducer.java index 4da8361fdf..6021b61ece 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroProducer.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/ShiroProducer.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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 * - * 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. + * 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.apache.shiro.cdi.impl; import static org.apache.shiro.SecurityUtils.getSecurityManager; diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/package-info.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/package-info.java index 361a34df49..d47d2622e3 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/package-info.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/impl/package-info.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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. */ - /** * Integration of CDI and Shiro bean concepts. */ diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/interceptor/ShiroInterceptor.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/interceptor/ShiroInterceptor.java index 9d78e2868a..4b7e36f48e 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/interceptor/ShiroInterceptor.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/interceptor/ShiroInterceptor.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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.apache.shiro.cdi.interceptor; import java.lang.reflect.Method; diff --git a/support/cdi/core/src/main/java/org/apache/shiro/cdi/package-info.java b/support/cdi/core/src/main/java/org/apache/shiro/cdi/package-info.java index 0fd01ef079..e3524221f6 100644 --- a/support/cdi/core/src/main/java/org/apache/shiro/cdi/package-info.java +++ b/support/cdi/core/src/main/java/org/apache/shiro/cdi/package-info.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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. */ - /** * Annotations for securing applications with Shiro in combination * with CDI. diff --git a/support/cdi/core/src/main/resources/META-INF/beans.xml b/support/cdi/core/src/main/resources/META-INF/beans.xml index edd9bee292..0dae11dc6d 100644 --- a/support/cdi/core/src/main/resources/META-INF/beans.xml +++ b/support/cdi/core/src/main/resources/META-INF/beans.xml @@ -1,3 +1,23 @@ + + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. + +--> diff --git a/support/cdi/web/pom.xml b/support/cdi/web/pom.xml index a101bbe042..e01431ade5 100644 --- a/support/cdi/web/pom.xml +++ b/support/cdi/web/pom.xml @@ -1,3 +1,23 @@ + 4.0.0 diff --git a/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java index 66b2176656..d70038d5e0 100644 --- a/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java +++ b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiIniWebEnvironment.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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.apache.shiro.cdi.web; import java.util.Map; diff --git a/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java index decc57d9c1..04504ea856 100644 --- a/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java +++ b/support/cdi/web/src/main/java/org/apache/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java @@ -1,21 +1,21 @@ -/* - * Copyright 2013 Harald Wellmann - * - * 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 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * See the License for the specific language governing permissions and - * limitations under the License. + * 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.apache.shiro.cdi.web; import java.util.Map; From 8c380223fd8acc02f6d809a426e31079cd11c9c0 Mon Sep 17 00:00:00 2001 From: Brian Demers Date: Wed, 6 Jul 2016 12:34:32 -0400 Subject: [PATCH 6/6] Attempting to add a CDI example from ops4j/org.ops4j.pax.shiro original sample: https://github.com/ops4j/org.ops4j.pax.shiro/blob/master/samples/sample-cdi-web Added README.md from: https://ops4j1.jira.com/wiki/display/PAXSHIRO/CDI+Support Added TODO.md in support/cdi and samples/cdi with thoughts on the project --- samples/cdi/TODO.md | 8 + samples/cdi/pom.xml | 195 ++++++++++++++++++ .../apache/shiro/samples/cdi/DemoRealm.java | 52 +++++ .../cdi/LoggingAuthenticationListener.java | 52 +++++ .../org/apache/shiro/samples/cdi/Login.java | 72 +++++++ .../shiro/samples/cdi/SecurityProducer.java | 42 ++++ .../apache/shiro/samples/cdi/SubjectBean.java | 41 ++++ .../org/apache/shiro/samples/cdi/User.java | 90 ++++++++ .../org/apache/shiro/samples/cdi/UserDao.java | 41 ++++ .../shiro/samples/cdi/UserRepository.java | 60 ++++++ .../cdi/src/main/resources/log4j.properties | 49 +++++ samples/cdi/src/main/webapp/WEB-INF/beans.xml | 4 + .../src/main/webapp/WEB-INF/faces-config.xml | 9 + .../src/main/webapp/WEB-INF/jetty-context.xml | 9 + .../cdi/src/main/webapp/WEB-INF/jetty-env.xml | 17 ++ samples/cdi/src/main/webapp/WEB-INF/shiro.ini | 24 +++ .../src/main/webapp/WEB-INF/web-override.xml | 12 ++ samples/cdi/src/main/webapp/WEB-INF/web.xml | 32 +++ samples/cdi/src/main/webapp/loggedout.xhtml | 16 ++ samples/cdi/src/main/webapp/login.xhtml | 22 ++ samples/cdi/src/main/webapp/logout.xhtml | 1 + samples/cdi/src/main/webapp/welcome.jsf | 1 + samples/cdi/src/main/webapp/welcome.xhtml | 13 ++ .../shiro/test/AbstractContainerTest.java | 101 +++++++++ .../shiro/test/ContainerIntegrationTest.java | 81 ++++++++ samples/pom.xml | 1 + support/cdi/README.md | 73 +++++++ support/cdi/TODO.md | 11 + support/cdi/core/pom.xml | 5 + support/cdi/web/pom.xml | 5 +- 30 files changed, 1136 insertions(+), 3 deletions(-) create mode 100644 samples/cdi/TODO.md create mode 100644 samples/cdi/pom.xml create mode 100644 samples/cdi/src/main/java/org/apache/shiro/samples/cdi/DemoRealm.java create mode 100644 samples/cdi/src/main/java/org/apache/shiro/samples/cdi/LoggingAuthenticationListener.java create mode 100644 samples/cdi/src/main/java/org/apache/shiro/samples/cdi/Login.java create mode 100644 samples/cdi/src/main/java/org/apache/shiro/samples/cdi/SecurityProducer.java create mode 100644 samples/cdi/src/main/java/org/apache/shiro/samples/cdi/SubjectBean.java create mode 100644 samples/cdi/src/main/java/org/apache/shiro/samples/cdi/User.java create mode 100644 samples/cdi/src/main/java/org/apache/shiro/samples/cdi/UserDao.java create mode 100644 samples/cdi/src/main/java/org/apache/shiro/samples/cdi/UserRepository.java create mode 100644 samples/cdi/src/main/resources/log4j.properties create mode 100644 samples/cdi/src/main/webapp/WEB-INF/beans.xml create mode 100644 samples/cdi/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 samples/cdi/src/main/webapp/WEB-INF/jetty-context.xml create mode 100644 samples/cdi/src/main/webapp/WEB-INF/jetty-env.xml create mode 100644 samples/cdi/src/main/webapp/WEB-INF/shiro.ini create mode 100644 samples/cdi/src/main/webapp/WEB-INF/web-override.xml create mode 100644 samples/cdi/src/main/webapp/WEB-INF/web.xml create mode 100644 samples/cdi/src/main/webapp/loggedout.xhtml create mode 100644 samples/cdi/src/main/webapp/login.xhtml create mode 100644 samples/cdi/src/main/webapp/logout.xhtml create mode 100644 samples/cdi/src/main/webapp/welcome.jsf create mode 100644 samples/cdi/src/main/webapp/welcome.xhtml create mode 100644 samples/cdi/src/test/java/org/apache/shiro/test/AbstractContainerTest.java create mode 100644 samples/cdi/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java create mode 100644 support/cdi/README.md create mode 100644 support/cdi/TODO.md diff --git a/samples/cdi/TODO.md b/samples/cdi/TODO.md new file mode 100644 index 0000000000..6d83549da9 --- /dev/null +++ b/samples/cdi/TODO.md @@ -0,0 +1,8 @@ +TODO +==== + +* Make this project work with jetty + weld (or some other simple CDI container) +* remove the need for faces in this example (this still have references to the PAX example) +* Update all samples to use newer eclipse jetty (this project will require it), so everything should be constant. + +**NOTE:** this Example has been hacked up a bit while attempting to make work against jetty. It does NOT currently work. \ No newline at end of file diff --git a/samples/cdi/pom.xml b/samples/cdi/pom.xml new file mode 100644 index 0000000000..5a056d0a3b --- /dev/null +++ b/samples/cdi/pom.xml @@ -0,0 +1,195 @@ + + + + + + + org.apache.shiro.samples + shiro-samples + 1.3.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + samples-cdi + Apache Shiro :: Samples :: CDI + war + + + 9.4.0.M0 + + + + + + maven-surefire-plugin + + never + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.version} + + + / + + + src/main/webapp/WEB-INF/jetty-context.xml + + 9080 + 60000 + + + ./target/yyyy_mm_dd.request.log + 90 + true + false + GMT + + + + + org.jboss.weld.servlet + weld-servlet + 2.3.5.Final + + + + + + + + + + + javax.inject + javax.inject + + + javax.enterprise + cdi-api + + + + + org.apache.shiro + shiro-cdi-core + ${project.version} + + + org.apache.shiro + shiro-cdi-web + ${project.version} + + + javax.servlet + jstl + runtime + + + javax.servlet + servlet-api + provided + + + org.slf4j + slf4j-log4j12 + runtime + + + log4j + log4j + runtime + + + net.sourceforge.htmlunit + htmlunit + 2.6 + test + + + org.apache.shiro + shiro-core + + + org.apache.shiro + shiro-web + + + org.slf4j + jcl-over-slf4j + runtime + + + + org.eclipse.jetty + jetty-server + ${jetty.version} + test + + + org.eclipse.jetty + jetty-webapp + ${jetty.version} + test + + + org.eclipse.jetty + jetty-jndi + ${jetty.version} + test + + + org.eclipse.jetty + jetty-plus + ${jetty.version} + test + + + org.eclipse.jetty + apache-jsp + ${jetty.version} + test + + + + org.jboss.weld.servlet + weld-servlet + 2.3.5.Final + test + + + org.jboss.weld.servlet + weld-servlet-core + 2.3.5.Final + test + + + + + + + + + + + diff --git a/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/DemoRealm.java b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/DemoRealm.java new file mode 100644 index 0000000000..6e6f8f826d --- /dev/null +++ b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/DemoRealm.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.samples.cdi; + +import javax.inject.Inject; + +import org.apache.shiro.authc.AuthenticationException; +import org.apache.shiro.authc.AuthenticationInfo; +import org.apache.shiro.authc.AuthenticationToken; +import org.apache.shiro.authc.SimpleAccount; +import org.apache.shiro.authc.UsernamePasswordToken; +import org.apache.shiro.realm.AuthenticatingRealm; +import org.apache.shiro.cdi.ShiroIni; + +/** + * Simple realm implementation, delegating to a UserDao. + * The {@code ShiroIni} annotation ensures we can reference + * this CDI bean in shiro.ini + */ +@ShiroIni +public class DemoRealm extends AuthenticatingRealm { + + @Inject + private UserDao userDao; + + @Override + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) { + UsernamePasswordToken upToken = (UsernamePasswordToken) token; + User user = userDao.findUser(upToken.getUsername()); + if (user == null) { + throw new AuthenticationException(); + } + return new SimpleAccount(user, user.getHashedPassword(), getName()); + } +} diff --git a/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/LoggingAuthenticationListener.java b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/LoggingAuthenticationListener.java new file mode 100644 index 0000000000..c99ee26a37 --- /dev/null +++ b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/LoggingAuthenticationListener.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.samples.cdi; + +import org.apache.shiro.authc.AuthenticationException; +import org.apache.shiro.authc.AuthenticationInfo; +import org.apache.shiro.authc.AuthenticationListener; +import org.apache.shiro.authc.AuthenticationToken; +import org.apache.shiro.subject.PrincipalCollection; +import org.apache.shiro.cdi.ShiroIni; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * + */ +@ShiroIni +public class LoggingAuthenticationListener implements AuthenticationListener { + + private static Logger log = LoggerFactory.getLogger(LoggingAuthenticationListener.class); + + public void onSuccess(AuthenticationToken token, AuthenticationInfo info) { + log.info("login success for [{}]", token.getPrincipal()); + } + + public void onFailure(AuthenticationToken token, AuthenticationException ae) { + log.info("login failure for [{}]", token.getPrincipal()); + } + + public void onLogout(PrincipalCollection principals) { + log.info("logout: [{}]", principals.getPrimaryPrincipal()); + } + +} diff --git a/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/Login.java b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/Login.java new file mode 100644 index 0000000000..93a82736e4 --- /dev/null +++ b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/Login.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.samples.cdi; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + + +/** + * Backing bean for the login form. + * + */ +@Named +@RequestScoped +public class Login { + + private String userName; + + private String password; + + + /** + * @return the userName + */ + public String getUserName() { + return userName; + } + + + /** + * @param userName the userName to set + */ + public void setUserName(String userName) { + this.userName = userName; + } + + + /** + * @return the password + */ + public String getPassword() { + return password; + } + + + /** + * @param password the password to set + */ + public void setPassword(String password) { + this.password = password; + } + + + +} diff --git a/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/SecurityProducer.java b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/SecurityProducer.java new file mode 100644 index 0000000000..4c637b2c3c --- /dev/null +++ b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/SecurityProducer.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.samples.cdi; + +import javax.enterprise.inject.Produces; +import javax.inject.Named; + +import org.apache.shiro.authc.credential.DefaultPasswordService; +import org.apache.shiro.authc.credential.PasswordService; +import org.apache.shiro.cdi.ShiroIni; + +/** + * Produces a password service CDI bean to be referenced in shiro.ini. + * + */ +public class SecurityProducer { + + @Produces + @ShiroIni + @Named + public PasswordService passwordService() { + return new DefaultPasswordService(); + } + +} diff --git a/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/SubjectBean.java b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/SubjectBean.java new file mode 100644 index 0000000000..a43f90690b --- /dev/null +++ b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/SubjectBean.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.samples.cdi; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.shiro.subject.Subject; + +/** + * A named bean wrapping the Subject bean. To be used in JSF views. + */ +@RequestScoped +@Named("subject") +public class SubjectBean { + + @Inject + private Subject subject; + + public String getUsername() { + return subject.getPrincipal().toString(); + } +} diff --git a/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/User.java b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/User.java new file mode 100644 index 0000000000..e55f956689 --- /dev/null +++ b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/User.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.samples.cdi; + + +/** + * Simple user object, containing the username and the hashed password. + * In real life, this would most likely be stored in a database. + *

+ * For this sample, we just use a global hash map. + */ +public class User { + + private String name; + + private String hashedPassword; + + private String displayName; + + public User() { + } + + public User(String name, String hashedPassword) { + this.name = name; + this.hashedPassword = hashedPassword; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + + /** + * @return the hashedPassword + */ + public String getHashedPassword() { + return hashedPassword; + } + + + /** + * @param hashedPassword the hashedPassword to set + */ + public void setHashedPassword(String hashedPassword) { + this.hashedPassword = hashedPassword; + } + + + public String getDisplayName() { + return displayName; + } + + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + @Override + public String toString() { + return name; + } +} diff --git a/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/UserDao.java b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/UserDao.java new file mode 100644 index 0000000000..d24b1bc336 --- /dev/null +++ b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/UserDao.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.samples.cdi; + +//import javax.ejb.Stateless; +import javax.inject.Inject; + + +/** + * Demo user DAO implementation. In real life, we might inject + * a PersistenceContext and fetch users from a database. + *

+ * For this demo, we just delegate to simple in-memory repository. + */ +//@Stateless +public class UserDao { + + @Inject + private UserRepository userRepository; + + public User findUser(String username) { + return userRepository.findUser(username); + } +} diff --git a/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/UserRepository.java b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/UserRepository.java new file mode 100644 index 0000000000..eecee36cb9 --- /dev/null +++ b/samples/cdi/src/main/java/org/apache/shiro/samples/cdi/UserRepository.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.samples.cdi; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +import org.apache.shiro.authc.credential.PasswordService; +import org.apache.shiro.cdi.ShiroIni; + +/** + * Simple memory-based user repository. Two users are inserted when this bean is created. The + * passwords get encrypted using an injected PasswordService. + */ +@ApplicationScoped +public class UserRepository { + + private Map users = new HashMap(); + + @Inject + @ShiroIni + private PasswordService passwordService; + + @PostConstruct + public void init() { + createUser("admin", "secret", "Administrator"); + createUser("user", "changeme", "Mary Smith"); + } + + public void createUser(String username, String rawPassword, String displayName) { + User user = new User(username, passwordService.encryptPassword(rawPassword)); + user.setDisplayName(displayName); + users.put(username, user); + } + + public User findUser(String username) { + return users.get(username); + } +} diff --git a/samples/cdi/src/main/resources/log4j.properties b/samples/cdi/src/main/resources/log4j.properties new file mode 100644 index 0000000000..002a8d7970 --- /dev/null +++ b/samples/cdi/src/main/resources/log4j.properties @@ -0,0 +1,49 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +# This file is used to format all logging output +log4j.rootLogger=TRACE, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c]: %m%n + +# ============================================================================= +# 3rd Party Libraries +# OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL +# ============================================================================= +# ehcache caching manager: +log4j.logger.net.sf.ehcache=WARN + +# Most all Apache libs: +log4j.logger.org.apache=WARN + +# Quartz Enterprise Scheular (java 'cron' utility) +log4j.logger.org.quartz=WARN + +# ============================================================================= +# Apache Shiro +# ============================================================================= +# Shiro security framework +log4j.logger.org.apache.shiro=TRACE +#log4j.logger.org.apache.shiro.realm.text.PropertiesRealm=INFO +#log4j.logger.org.apache.shiro.cache.ehcache.EhCache=INFO +#log4j.logger.org.apache.shiro.io=INFO +#log4j.logger.org.apache.shiro.web.servlet=INFO +log4j.logger.org.apache.shiro.util.ThreadContext=INFO diff --git a/samples/cdi/src/main/webapp/WEB-INF/beans.xml b/samples/cdi/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..f26bec7bac --- /dev/null +++ b/samples/cdi/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,4 @@ + + diff --git a/samples/cdi/src/main/webapp/WEB-INF/faces-config.xml b/samples/cdi/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000000..b3d2ce3408 --- /dev/null +++ b/samples/cdi/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/samples/cdi/src/main/webapp/WEB-INF/jetty-context.xml b/samples/cdi/src/main/webapp/WEB-INF/jetty-context.xml new file mode 100644 index 0000000000..14ddcf2a9a --- /dev/null +++ b/samples/cdi/src/main/webapp/WEB-INF/jetty-context.xml @@ -0,0 +1,9 @@ + + + + + + -org.eclipse.jetty.servlet.ServletContextHandler.Decorator + + + \ No newline at end of file diff --git a/samples/cdi/src/main/webapp/WEB-INF/jetty-env.xml b/samples/cdi/src/main/webapp/WEB-INF/jetty-env.xml new file mode 100644 index 0000000000..f74ca532ec --- /dev/null +++ b/samples/cdi/src/main/webapp/WEB-INF/jetty-env.xml @@ -0,0 +1,17 @@ + + + + + + + + BeanManager + + + javax.enterprise.inject.spi.BeanManager + org.jboss.weld.resources.ManagerObjectFactory + + + + + \ No newline at end of file diff --git a/samples/cdi/src/main/webapp/WEB-INF/shiro.ini b/samples/cdi/src/main/webapp/WEB-INF/shiro.ini new file mode 100644 index 0000000000..7ccbaca476 --- /dev/null +++ b/samples/cdi/src/main/webapp/WEB-INF/shiro.ini @@ -0,0 +1,24 @@ +[main] + +# demoRealm is a named CDI bean +securityManager.realms = $demoRealm + +securityManager.authenticator.authenticationListeners = $loggingAuthenticationListener + +authc.loginUrl = /login.jsf +authc.usernameParam = login:username +authc.passwordParam = login:password + +logout.redirectUrl = /loggedout.jsf + +passwordMatcher = org.apache.shiro.authc.credential.PasswordMatcher + +# $passwordService is a named CDI bean +passwordMatcher.passwordService = $passwordService + +demoRealm.credentialsMatcher = $passwordMatcher + +[urls] +/logout.jsf = logout, anon +/loggedout.jsf = anon +/** = authc diff --git a/samples/cdi/src/main/webapp/WEB-INF/web-override.xml b/samples/cdi/src/main/webapp/WEB-INF/web-override.xml new file mode 100644 index 0000000000..da55f702cd --- /dev/null +++ b/samples/cdi/src/main/webapp/WEB-INF/web-override.xml @@ -0,0 +1,12 @@ + + + + + BeanManager + javax.enterprise.inject.spi.BeanManager + + + diff --git a/samples/cdi/src/main/webapp/WEB-INF/web.xml b/samples/cdi/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..6f5a96e1ab --- /dev/null +++ b/samples/cdi/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,32 @@ + + + + + shiroEnvironmentClass + org.apache.shiro.cdi.web.CdiIniWebEnvironment + + + + + org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener + + + org.apache.shiro.web.env.EnvironmentLoaderListener + + + + ShiroFilter + org.apache.shiro.web.servlet.ShiroFilter + + + + ShiroFilter + /* + + + + welcome.jsf + + + diff --git a/samples/cdi/src/main/webapp/loggedout.xhtml b/samples/cdi/src/main/webapp/loggedout.xhtml new file mode 100644 index 0000000000..68390485eb --- /dev/null +++ b/samples/cdi/src/main/webapp/loggedout.xhtml @@ -0,0 +1,16 @@ + + + +

Shiro CDI Web Sample

+ +

You are logged out.

+ + + + + + + + + \ No newline at end of file diff --git a/samples/cdi/src/main/webapp/login.xhtml b/samples/cdi/src/main/webapp/login.xhtml new file mode 100644 index 0000000000..d260449055 --- /dev/null +++ b/samples/cdi/src/main/webapp/login.xhtml @@ -0,0 +1,22 @@ + + + +

Shiro CDI Web Sample

+ +

Enter "admin" and password "secret", or "user" and password "changeme" to log in.

+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/cdi/src/main/webapp/logout.xhtml b/samples/cdi/src/main/webapp/logout.xhtml new file mode 100644 index 0000000000..16807dd648 --- /dev/null +++ b/samples/cdi/src/main/webapp/logout.xhtml @@ -0,0 +1 @@ + diff --git a/samples/cdi/src/main/webapp/welcome.jsf b/samples/cdi/src/main/webapp/welcome.jsf new file mode 100644 index 0000000000..74c8c66c32 --- /dev/null +++ b/samples/cdi/src/main/webapp/welcome.jsf @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/samples/cdi/src/main/webapp/welcome.xhtml b/samples/cdi/src/main/webapp/welcome.xhtml new file mode 100644 index 0000000000..467674aa48 --- /dev/null +++ b/samples/cdi/src/main/webapp/welcome.xhtml @@ -0,0 +1,13 @@ + + + +

Welcome to the Shiro CDI Web Sample

+

You are now logged in as #{subject.username}.

+

Your display name is .

+ + \ No newline at end of file diff --git a/samples/cdi/src/test/java/org/apache/shiro/test/AbstractContainerTest.java b/samples/cdi/src/test/java/org/apache/shiro/test/AbstractContainerTest.java new file mode 100644 index 0000000000..471a3cca2d --- /dev/null +++ b/samples/cdi/src/test/java/org/apache/shiro/test/AbstractContainerTest.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.test; + +import com.gargoylesoftware.htmlunit.WebClient; +import static org.junit.Assert.assertTrue; + +import org.eclipse.jetty.server.Connector; +import org.junit.Before; +import org.junit.BeforeClass; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.webapp.WebAppContext; +import org.jboss.weld.environment.servlet.Listener; + +import java.net.BindException; + +public abstract class AbstractContainerTest { + public static final int MAX_PORT = 9200; + + protected static PauseableServer server; + + private static int port = 9180; + + protected final WebClient webClient = new WebClient(); + + @BeforeClass + public static void startContainer() throws Exception { + while (server == null && port < MAX_PORT) { + try { + server = createAndStartServer(port); + } catch (BindException e) { + System.err.printf("Unable to listen on port %d. Trying next port.", port); + port++; + } + } + assertTrue(server.isStarted()); + } + + private static PauseableServer createAndStartServer(final int port) throws Exception { + PauseableServer server = new PauseableServer(); + ServerConnector connector = new ServerConnector(server); + connector.setPort(port); + server.addConnector(connector); + + WebAppContext context = new WebAppContext(); +// String[] jettyConfigurationClasses = {"org.eclipse.jetty.webapp.WebXmlConfiguration", }; +// context.setConfigurationClasses(jettyConfigurationClasses); + context.setContextPath("/"); + context.setResourceBase("src/main/webapp"); +// context.setClassLoader(Thread.currentThread().getContextClassLoader()); + server.setHandler(context); + + context.addEventListener(new Listener()); + + server.start(); + server.join(); + return server; + } + + protected static String getBaseUri() { + return "http://localhost:" + port + "/"; + } + + @Before + public void beforeTest() { + webClient.setThrowExceptionOnFailingStatusCode(true); + } + + public void pauseServer(boolean paused) { + if (server != null) server.pause(paused); + } + + public static class PauseableServer extends Server { + public synchronized void pause(boolean paused) { + try { + if (paused) for (Connector connector : getConnectors()) + connector.stop(); + else for (Connector connector : getConnectors()) + connector.start(); + } catch (Exception e) { + } + } + } +} diff --git a/samples/cdi/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java b/samples/cdi/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java new file mode 100644 index 0000000000..7123cc427a --- /dev/null +++ b/samples/cdi/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.shiro.test; + +import com.gargoylesoftware.htmlunit.ElementNotFoundException; +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.WebAssert; +import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlInput; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.IOException; +import java.net.MalformedURLException; + +@Ignore +public class ContainerIntegrationTest extends AbstractContainerTest { + + @Before + public void logOut() throws IOException { + // Make sure we are logged out + final HtmlPage homePage = webClient.getPage(getBaseUri()); + try { + homePage.getAnchorByHref("/logout").click(); + } + catch (ElementNotFoundException e) { + //Ignore + } + } + + @Test + public void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException { + + HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp"); + HtmlForm form = page.getFormByName("loginform"); + form.getInputByName("username").setValueAttribute("root"); + form.getInputByName("password").setValueAttribute("secret"); + page = form.getInputByName("submit").click(); + // This'll throw an expection if not logged in + page.getAnchorByHref("/logout"); + } + + @Test + public void logInAndRememberMe() throws Exception { + HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp"); + HtmlForm form = page.getFormByName("loginform"); + form.getInputByName("username").setValueAttribute("root"); + form.getInputByName("password").setValueAttribute("secret"); + HtmlCheckBoxInput checkbox = form.getInputByName("rememberMe"); + checkbox.setChecked(true); + page = form.getInputByName("submit").click(); + server.stop(); + server.start(); + page = webClient.getPage(getBaseUri()); + // page.getAnchorByHref("/logout"); + WebAssert.assertLinkPresentWithText(page, "Log out"); + page = page.getAnchorByHref("/account").click(); + // login page should be shown again - user remembered but not authenticated + WebAssert.assertFormPresent(page, "loginform"); + } + +} diff --git a/samples/pom.xml b/samples/pom.xml index ae8e70820c..37ddb52a6c 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -39,6 +39,7 @@ spring-client spring spring-hibernate + cdi diff --git a/support/cdi/README.md b/support/cdi/README.md new file mode 100644 index 0000000000..4b9c530996 --- /dev/null +++ b/support/cdi/README.md @@ -0,0 +1,73 @@ +Shiro Objects as Managed Beans +------------------------------ + +`shiro-cdi-core` provides the following Shiro objects as application-scoped managed beans: + +* SecurityManager +* Subject +* Session + +These beans are implemented as dynamic proxies which access the target object via `SecurityUtils.getSecurityManager()`. `shiro-cdi-core` does not itself instantiate a security manager. + +Securing Methods with Shiro Annotations +--------------------------------------- + +Apache Shiro defines a set of annotations in package `org.apache.shiro.authz.annotation` which can be used to declare the required roles or permissions for invoking a given method. These annotations require a suitable enabling technology like aspects or interceptors. Apache Shiro supports Spring, Guice or AspectJ as enabling technologies. Shiro adds support for CDI in full-blown Java EE applications, in web-only applications with CDI (e.g. Tomcat + Weld), or in Java SE applications with CDI. +To enable Shiro annotations with CDI, include the `shiro-cdi-core` library in your application and enable the `ShiroInterceptor` in your beans.xml descriptor: +```xml + + + org.apache.shiro.cdi.interceptor.ShiroInterceptor + + +``` + +Managed Beans and Shiro INI Files +--------------------------------- + +INI files are the preferred configuration mechanism for Apache Shiro. In fact, these INI files can be regarded as a kind of poor man's bean context, defining a set of Shiro-flavoured managed beans. +In a CDI application, however, these INI-configured Shiro objects are not managed beans, as they are not instantiated by the CDI bean manager. `shiro-cdi-core` lets you reference CDI managed beans from Shiro INI files, so you can inject any transitive dependencies of Shiro objects by means of CDI. +To mark a managed bean as referenceable from Shiro INI files, simply add the `@ShiroIni` qualifier. The bean name can be set explicitly with a `@Named` qualifier. Otherwise, if Bean.getBeanClass() is a bean type of the given bean, the bean name will be the simple class name of this class, with the first letter converted to lower case. +Example: +```java +@ShiroIni +public class MyPasswordMatcher extends SimpleCredentialsMatcher { + + @Inject + private MyDependency myDependency; + + // body omitted +} +``` + +``` +[main] +iniRealm.credentialsMatcher = $myPasswordMatcher +``` + +CDI Support for Shiro Web Applications +-------------------------------------- + +`shiro-cdi-web` builds on `shiro-cdi-core` and provides a `CdiIniWebEnvironment`. To secure your web application with Apache Shiro and CDI support from Shiro, include the following in your `web.xml` descriptor: +```xml + + shiroEnvironmentClass + org.apache.shiro.cdi.web.CdiIniWebEnvironment + + + + org.apache.shiro.web.env.EnvironmentLoaderListener + + + + ShiroFilter + org.apache.shiro.web.servlet.ShiroFilter + + + + ShiroFilter + /* + +``` + +See `sample-cdi` for an example, which should work on any Java EE 6 server (tested on JBoss AS 7.2). \ No newline at end of file diff --git a/support/cdi/TODO.md b/support/cdi/TODO.md new file mode 100644 index 0000000000..f0bf370ce5 --- /dev/null +++ b/support/cdi/TODO.md @@ -0,0 +1,11 @@ +TODO +==== + +* compress `core` and `web` to match the other support modules + maybe just make dependency on shiro-web optional. +* confirm the use of the javax artifacts over geronimo + [@bdemers] is heavily bias for javax as guice uses javax.inject +* Think about Unit Tests, these seem to all be ITs (PaxExam). This may be fine in this context, but it makes it difficult to test other CDI containers. + The original PAX source, used Maven profiles, which required multiple maven executions. (which means we will not be running those tests all the time (i.e. durring release) +* For initial version we _should_ target a single CDI container, much like all of the examples use jetty. +* rename `impl' package to be consistent with other packages in Shiro \ No newline at end of file diff --git a/support/cdi/core/pom.xml b/support/cdi/core/pom.xml index 307015daff..0444f34af1 100644 --- a/support/cdi/core/pom.xml +++ b/support/cdi/core/pom.xml @@ -104,6 +104,11 @@
+ + openwebbeans diff --git a/support/cdi/web/pom.xml b/support/cdi/web/pom.xml index e01431ade5..6b15bc4223 100644 --- a/support/cdi/web/pom.xml +++ b/support/cdi/web/pom.xml @@ -45,9 +45,8 @@ shiro-web - javax.inject - javax.inject - provided + javax.enterprise + cdi-api javax.interceptor