You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2014/12/17 12:32:28 UTC
deltaspike git commit: DELTASPIKE-801 added test
Repository: deltaspike
Updated Branches:
refs/heads/master 02f28387e -> 16ba76b8a
DELTASPIKE-801 added test
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/16ba76b8
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/16ba76b8
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/16ba76b8
Branch: refs/heads/master
Commit: 16ba76b8a908df33e2c5e77a0691eff3fb098f9c
Parents: 02f2838
Author: gpetracek <gp...@apache.org>
Authored: Wed Dec 17 12:24:05 2014 +0100
Committer: gpetracek <gp...@apache.org>
Committed: Wed Dec 17 12:29:00 2014 +0100
----------------------------------------------------------------------
.../nonbinding/CustomAuthorizer.java | 42 +++++++++++++++
.../nonbinding/CustomSecurityBinding.java | 39 ++++++++++++++
.../ParamBindingWithNonbindingMember.java | 41 ++++++++++++++
.../nonbinding/ParameterValue.java | 39 ++++++++++++++
.../authorization/nonbinding/SecuredBean.java | 31 +++++++++++
...curityParameterWithNonbindingMemberTest.java | 57 ++++++++++++++++++++
6 files changed, 249 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/16ba76b8/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/CustomAuthorizer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/CustomAuthorizer.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/CustomAuthorizer.java
new file mode 100644
index 0000000..585664c
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/CustomAuthorizer.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.deltaspike.test.security.impl.authorization.nonbinding;
+
+import org.apache.deltaspike.security.api.authorization.Secures;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.interceptor.InvocationContext;
+
+@ApplicationScoped
+public class CustomAuthorizer
+{
+ @Secures
+ @CustomSecurityBinding
+ public boolean doSecuredCheck(@ParamBindingWithNonbindingMember(info = "test") ParameterValue obj,
+ InvocationContext invocationContext)
+ throws Exception
+ {
+ if (invocationContext == null)
+ {
+ throw new IllegalArgumentException("no invocation-context found");
+ }
+
+ return obj.isValue();
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/16ba76b8/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/CustomSecurityBinding.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/CustomSecurityBinding.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/CustomSecurityBinding.java
new file mode 100644
index 0000000..d44a400
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/CustomSecurityBinding.java
@@ -0,0 +1,39 @@
+/*
+ * 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.deltaspike.test.security.impl.authorization.nonbinding;
+
+import org.apache.deltaspike.security.api.authorization.SecurityBindingType;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Retention(value = RUNTIME)
+@Target({ TYPE, METHOD })
+
+@Documented
+
+@SecurityBindingType
+public @interface CustomSecurityBinding
+{
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/16ba76b8/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/ParamBindingWithNonbindingMember.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/ParamBindingWithNonbindingMember.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/ParamBindingWithNonbindingMember.java
new file mode 100644
index 0000000..fbf9bd1
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/ParamBindingWithNonbindingMember.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.deltaspike.test.security.impl.authorization.nonbinding;
+
+import org.apache.deltaspike.security.api.authorization.SecurityParameterBinding;
+
+import javax.enterprise.util.Nonbinding;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Retention(value = RUNTIME)
+@Target({ PARAMETER })
+
+@Documented
+
+@SecurityParameterBinding
+public @interface ParamBindingWithNonbindingMember
+{
+ @Nonbinding
+ String info();
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/16ba76b8/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/ParameterValue.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/ParameterValue.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/ParameterValue.java
new file mode 100644
index 0000000..2b97774
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/ParameterValue.java
@@ -0,0 +1,39 @@
+/*
+ * 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.deltaspike.test.security.impl.authorization.nonbinding;
+
+public class ParameterValue
+{
+ private boolean value;
+
+ public ParameterValue(boolean value)
+ {
+ this.value = value;
+ }
+
+ public boolean isValue()
+ {
+ return value;
+ }
+
+ public void setValue(boolean value)
+ {
+ this.value = value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/16ba76b8/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/SecuredBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/SecuredBean.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/SecuredBean.java
new file mode 100644
index 0000000..f7ae2fa
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/SecuredBean.java
@@ -0,0 +1,31 @@
+/*
+ * 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.deltaspike.test.security.impl.authorization.nonbinding;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@CustomSecurityBinding
+@ApplicationScoped
+public class SecuredBean
+{
+ public boolean getResult(@ParamBindingWithNonbindingMember(info = "test") ParameterValue parameterValue)
+ {
+ return parameterValue.isValue();
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/16ba76b8/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/SecurityParameterWithNonbindingMemberTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/SecurityParameterWithNonbindingMemberTest.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/SecurityParameterWithNonbindingMemberTest.java
new file mode 100644
index 0000000..24adfa1
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authorization/nonbinding/SecurityParameterWithNonbindingMemberTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.deltaspike.test.security.impl.authorization.nonbinding;
+
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.security.api.authorization.AccessDeniedException;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test for {@link org.apache.deltaspike.security.api.authorization.Secured}
+ */
+@RunWith(Arquillian.class)
+public class SecurityParameterWithNonbindingMemberTest
+{
+ @Deployment
+ public static WebArchive deploy()
+ {
+ String simpleName = SecurityParameterWithNonbindingMemberTest.class.getSimpleName();
+ String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1);
+
+ return ShrinkWrap.create(WebArchive.class, archiveName + ".war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndSecurityArchive())
+ .addPackage(SecurityParameterWithNonbindingMemberTest.class.getPackage())
+ .addAsWebInfResource(ArchiveUtils.getBeansXml(), "beans.xml");
+ }
+
+ @Test(expected = AccessDeniedException.class)
+ public void securityParameterWithNonbindingMember()
+ {
+ SecuredBean testBean = BeanProvider.getContextualReference(SecuredBean.class, false);
+ testBean.getResult(new ParameterValue(false));
+ Assert.fail();
+ }
+}