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 2013/11/10 20:20:14 UTC
git commit: DELTASPIKE-441 AbstractAccessDecisionVoter added
Updated Branches:
refs/heads/master be37dc6b9 -> db666c570
DELTASPIKE-441 AbstractAccessDecisionVoter added
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/db666c57
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/db666c57
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/db666c57
Branch: refs/heads/master
Commit: db666c5709e41343c64a366bf0c853da225d5eb1
Parents: be37dc6
Author: gpetracek <gp...@apache.org>
Authored: Sun Nov 10 19:47:51 2013 +0100
Committer: gpetracek <gp...@apache.org>
Committed: Sun Nov 10 20:16:23 2013 +0100
----------------------------------------------------------------------
.../AbstractAccessDecisionVoter.java | 52 ++++++++++++++++++++
.../authorization/AbstractDecisionVoter.java | 40 +++++++++++++++
.../authorization/DefaultSecurityViolation.java | 39 ---------------
.../authorization/SimpleSecurityViolation.java | 40 +++++++++++++++
4 files changed, 132 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/db666c57/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/AbstractAccessDecisionVoter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/AbstractAccessDecisionVoter.java b/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/AbstractAccessDecisionVoter.java
new file mode 100644
index 0000000..a67baa9
--- /dev/null
+++ b/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/AbstractAccessDecisionVoter.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.deltaspike.security.api.authorization;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Base implementation which provides helper methods.
+ */
+public abstract class AbstractAccessDecisionVoter extends AbstractDecisionVoter implements AccessDecisionVoter
+{
+ private static final long serialVersionUID = -9145021044568668681L;
+
+ /**
+ * It should be final - but proxy-libs won't support it.
+ */
+ @Override
+ public Set<SecurityViolation> checkPermission(AccessDecisionVoterContext accessDecisionVoterContext)
+ {
+ Set<SecurityViolation> result = new HashSet<SecurityViolation>();
+
+ checkPermission(accessDecisionVoterContext, result);
+
+ return result;
+ }
+
+ /**
+ * Allows an easier implementation in combination with {@link #newSecurityViolation(String)}.
+ *
+ * @param accessDecisionVoterContext current accessDecisionVoterContext
+ * @param violations set for adding violations
+ */
+ protected abstract void checkPermission(AccessDecisionVoterContext accessDecisionVoterContext,
+ Set<SecurityViolation> violations);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/db666c57/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/AbstractDecisionVoter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/AbstractDecisionVoter.java b/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/AbstractDecisionVoter.java
new file mode 100644
index 0000000..72e9c41
--- /dev/null
+++ b/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/AbstractDecisionVoter.java
@@ -0,0 +1,40 @@
+/*
+ * 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.security.api.authorization;
+
+/**
+ * Base class for decision-voters
+ */
+//can be used also for similar parts
+//e.g. for custom scopes. like it was done in CODI (see AbstractBeanCreationDecisionVoter)
+public abstract class AbstractDecisionVoter
+{
+ /**
+ * Creates an instance of {@link SecurityViolation} for a given
+ * string which will be used as reason to describe the violation.
+ *
+ * @param reason description of the violation
+ * @return A new instance of {@link SecurityViolation}
+ * which provides details about the found restriction.
+ */
+ protected SecurityViolation newSecurityViolation(String reason)
+ {
+ return new SimpleSecurityViolation(reason);
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/db666c57/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/DefaultSecurityViolation.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/DefaultSecurityViolation.java b/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/DefaultSecurityViolation.java
deleted file mode 100644
index c92492e..0000000
--- a/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/DefaultSecurityViolation.java
+++ /dev/null
@@ -1,39 +0,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
- *
- * 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.security.api.authorization;
-
-/**
- * Simple implementation of a SecurityViolation.
- * It will only store the string it gets via the constructor.
- */
-public class DefaultSecurityViolation implements SecurityViolation
-{
- private String reason;
-
- public DefaultSecurityViolation(String reason)
- {
- this.reason = reason;
- }
-
- @Override
- public String getReason()
- {
- return reason;
- }
-}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/db666c57/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/SimpleSecurityViolation.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/SimpleSecurityViolation.java b/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/SimpleSecurityViolation.java
new file mode 100644
index 0000000..d8e317f
--- /dev/null
+++ b/deltaspike/modules/security/api/src/main/java/org/apache/deltaspike/security/api/authorization/SimpleSecurityViolation.java
@@ -0,0 +1,40 @@
+/*
+ * 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.security.api.authorization;
+
+/**
+ * Implementation which just returns the given reason
+ */
+class SimpleSecurityViolation implements SecurityViolation
+{
+ private static final long serialVersionUID = -5017812464381395966L;
+
+ private final String reason;
+
+ SimpleSecurityViolation(String reason)
+ {
+ this.reason = reason;
+ }
+
+ @Override
+ public String getReason()
+ {
+ return reason;
+ }
+}