Author: scabanovich
Date: 2012-05-22 20:44:26 -0400 (Tue, 22 May 2012)
New Revision: 41270
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeAuthorityMethod.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityBindingConfiguration.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityDefinitionContext.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSeverityPreferenceInitializer.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/DeltaspikeValidationMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/messages.properties
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.xml
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeConstants.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityExtension.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSeverityPreferences.java
Log:
JBIDE-11552
https://issues.jboss.org/browse/JBIDE-11552
Initial implementation of deltaspike security extension.
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.xml 2012-05-23 00:25:01
UTC (rev 41269)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.xml 2012-05-23 00:44:26
UTC (rev 41270)
@@ -26,4 +26,8 @@
</cdiextension>
</extension>
+ <extension point="org.eclipse.core.runtime.preferences">
+ <initializer
class="org.jboss.tools.cdi.deltaspike.core.DeltaspikeSeverityPreferenceInitializer"/>
+ </extension>
+
</plugin>
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeAuthorityMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeAuthorityMethod.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeAuthorityMethod.java 2012-05-23
00:44:26 UTC (rev 41270)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.deltaspike.core;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.cdi.internal.core.impl.CDIProject;
+import org.jboss.tools.cdi.internal.core.impl.definition.MethodDefinition;
+import org.jboss.tools.common.java.IAnnotationDeclaration;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class DeltaspikeAuthorityMethod {
+ MethodDefinition method;
+ IPath path;
+ String declaringTypeName;
+
+ Map<IAnnotationDeclaration, DeltaspikeSecurityBindingConfiguration> bindings = new
HashMap<IAnnotationDeclaration, DeltaspikeSecurityBindingConfiguration>();
+
+ public DeltaspikeAuthorityMethod(MethodDefinition method) {
+ this.method = method;
+ IType type = method.getTypeDefinition().getType();
+ if(type != null) {
+ path = type.getPath();
+ declaringTypeName = type.getFullyQualifiedName();
+ }
+ }
+
+ public MethodDefinition getMethod() {
+ return method;
+ }
+
+ public IPath getPath() {
+ return path;
+ }
+
+ public String getDeclaringTypeName() {
+ return declaringTypeName;
+ }
+
+ public void addBinding(IAnnotationDeclaration d, DeltaspikeSecurityBindingConfiguration
c) {
+ bindings.put(d, c);
+ }
+
+ public Map<IAnnotationDeclaration, DeltaspikeSecurityBindingConfiguration>
getBindings() {
+ return bindings;
+ }
+
+ public boolean isMatching(IAnnotationDeclaration d) throws CoreException {
+ if(bindings.isEmpty()) {
+ return false;
+ }
+ String key = CDIProject.getAnnotationDeclarationKey(d);
+ for (IAnnotationDeclaration d2: bindings.keySet()) {
+ if(d2.getTypeName().equals(d.getTypeName())) {
+ if(key.equals(CDIProject.getAnnotationDeclarationKey(d2))) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeAuthorityMethod.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeConstants.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeConstants.java 2012-05-23
00:25:01 UTC (rev 41269)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeConstants.java 2012-05-23
00:44:26 UTC (rev 41270)
@@ -10,6 +10,11 @@
******************************************************************************/
package org.jboss.tools.cdi.deltaspike.core;
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
public interface DeltaspikeConstants {
public String CONFIG_PROPERTY_ANNOTATION_TYPE_NAME =
"org.apache.deltaspike.core.api.config.annotation.ConfigProperty";
//$NON-NLS-1$
@@ -30,6 +35,8 @@
public String SECURITY_BINDING_ANNOTATION_TYPE_NAME =
"org.apache.deltaspike.security.api.authorization.annotation.SecurityBindingType";
//$NON-NLS-1$
public String SECURITY_PARAM_BINDING_ANNOTATION_TYPE_NAME =
"org.apache.deltaspike.security.api.authorization.annotation.SecurityParameterBinding";
//$NON-NLS-1$
- public String MESSAGE_BUNDLE_ANNOTATION_KIND = "messageBundleAnnotation";
+ public String MESSAGE_BUNDLE_ANNOTATION_KIND = "messageBundleAnnotation";
//$NON-NLS-1$
+ public String SECURITY_BINDING_ANNOTATION_KIND = "securityBindingAnnotation";
//$NON-NLS-1$
+ public String SECURES_ANNOTATION_KIND = "securesAnnotation"; //$NON-NLS-1$
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityBindingConfiguration.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityBindingConfiguration.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityBindingConfiguration.java 2012-05-23
00:44:26 UTC (rev 41270)
@@ -0,0 +1,72 @@
+package org.jboss.tools.cdi.deltaspike.core;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.jboss.tools.cdi.core.IQualifierDeclaration;
+import org.jboss.tools.cdi.internal.core.impl.definition.AbstractMemberDefinition;
+import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
+import org.jboss.tools.common.java.IAnnotationDeclaration;
+
+public class DeltaspikeSecurityBindingConfiguration {
+ String securityBindingTypeName;
+ AnnotationDefinition securityBindingType;
+
+ Map<AbstractMemberDefinition, IAnnotationDeclaration> boundMembers = new
HashMap<AbstractMemberDefinition, IAnnotationDeclaration>();
+ Set<DeltaspikeAuthorityMethod> authorizerMembers = new
HashSet<DeltaspikeAuthorityMethod>();
+
+ Set<IPath> involvedResources = new HashSet<IPath>();
+
+ public DeltaspikeSecurityBindingConfiguration(String securityBindingTypeName) {
+ this.securityBindingTypeName = securityBindingTypeName;
+ }
+
+ public void setSecurityBundingTypeDefinition(AnnotationDefinition securityBindingType,
DeltaspikeSecurityDefinitionContext context) {
+ this.securityBindingType = securityBindingType;
+ }
+
+ public void clear(IPath path) {
+ involvedResources.remove(path);
+ }
+
+ public void clear(String typeName) {
+ Iterator<AbstractMemberDefinition> it = boundMembers.keySet().iterator();
+ while(it.hasNext()) {
+ if(typeName.equals(it.next().getTypeDefinition().getQualifiedName())) {
+ it.remove();
+ }
+ }
+ Iterator<DeltaspikeAuthorityMethod> it2 = authorizerMembers.iterator();
+ while(it2.hasNext()) {
+ if(typeName.equals(it2.next().getDeclaringTypeName())) {
+ it2.remove();
+ }
+ }
+ }
+
+ Map<AbstractMemberDefinition, IAnnotationDeclaration> getBoundMembers() {
+ return boundMembers;
+ }
+
+ Set<DeltaspikeAuthorityMethod> getAuthorizerMembers() {
+ return authorizerMembers;
+ }
+
+ public String getSecurityBindingTypeName() {
+ return securityBindingTypeName;
+ }
+
+ public AnnotationDefinition getSecurityBindingTypeDefinition() {
+ return securityBindingType;
+ }
+
+ public Set<IPath> getInvolvedTypes() {
+ return involvedResources;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityBindingConfiguration.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityDefinitionContext.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityDefinitionContext.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityDefinitionContext.java 2012-05-23
00:44:26 UTC (rev 41270)
@@ -0,0 +1,108 @@
+package org.jboss.tools.cdi.deltaspike.core;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.cdi.core.extension.AbstractDefinitionContextExtension;
+import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
+
+public class DeltaspikeSecurityDefinitionContext extends
AbstractDefinitionContextExtension implements DeltaspikeConstants {
+
+ Map<String, DeltaspikeSecurityBindingConfiguration> securityBindingConfigurations
= new HashMap<String, DeltaspikeSecurityBindingConfiguration>();
+ DeltaspikeSecurityBindingConfiguration allAuthorizerMethods = new
DeltaspikeSecurityBindingConfiguration(""); //$NON-NLS-1$
+
+ @Override
+ protected AbstractDefinitionContextExtension copy(boolean clean) {
+ DeltaspikeSecurityDefinitionContext copy = new DeltaspikeSecurityDefinitionContext();
+ copy.root = root;
+ if(!clean) {
+ copy.securityBindingConfigurations.putAll(securityBindingConfigurations);
+ allAuthorizerMethods = copy.allAuthorizerMethods;
+ }
+ return copy;
+ }
+
+ @Override
+ protected void doApplyWorkingCopy() {
+ DeltaspikeSecurityDefinitionContext copy =
(DeltaspikeSecurityDefinitionContext)workingCopy;
+ securityBindingConfigurations = copy.securityBindingConfigurations;
+ allAuthorizerMethods = copy.allAuthorizerMethods;
+
+ }
+
+ @Override
+ public void clean() {
+ securityBindingConfigurations.clear();
+ allAuthorizerMethods.getAuthorizerMembers().clear();
+ }
+
+ @Override
+ public void clean(IPath path) {
+ for (DeltaspikeSecurityBindingConfiguration c: securityBindingConfigurations.values())
{
+ c.clear(path);
+ }
+ allAuthorizerMethods.clear(path);
+ }
+
+ @Override
+ public void clean(String typeName) {
+ securityBindingConfigurations.remove(typeName);
+ for (DeltaspikeSecurityBindingConfiguration c: securityBindingConfigurations.values())
{
+ c.clear(typeName);
+ }
+ allAuthorizerMethods.clear(typeName);
+ }
+
+ @Override
+ public void computeAnnotationKind(AnnotationDefinition annotation) {
+ if(SECURES_ANNOTATION_TYPE_NAME.equals(annotation.getType().getFullyQualifiedName()))
{
+ annotation.setExtendedKind(SECURES_ANNOTATION_KIND);
+ } else if(annotation.isAnnotationPresent(SECURITY_BINDING_ANNOTATION_TYPE_NAME)) {
+ annotation.setExtendedKind(SECURITY_BINDING_ANNOTATION_KIND);
+ String qn = annotation.getType().getFullyQualifiedName();
+ DeltaspikeSecurityBindingConfiguration c = getConfiguration(qn);
+ c.setSecurityBundingTypeDefinition(annotation, this);
+ if(!annotation.getType().isBinary()) {
+ IPath newPath = annotation.getType().getResource().getFullPath();
+ Set<IPath> ps = c.getInvolvedTypes();
+ for (IPath p: ps) {
+ getRootContext().addDependency(p, newPath);
+ getRootContext().addDependency(newPath, p);
+ }
+ ps.add(newPath);
+ }
+ }
+ }
+
+ public boolean isSecurityBindingTypeAnnotation(IType type) {
+ return (securityBindingConfigurations.containsKey(type.getFullyQualifiedName()));
+ }
+
+ public Map<String, DeltaspikeSecurityBindingConfiguration> getConfigurations() {
+ return securityBindingConfigurations;
+ }
+
+ public DeltaspikeSecurityBindingConfiguration getConfiguration(String typeName) {
+ DeltaspikeSecurityBindingConfiguration result =
securityBindingConfigurations.get(typeName);
+ if(result == null) {
+ result = new DeltaspikeSecurityBindingConfiguration(typeName);
+ securityBindingConfigurations.put(typeName, result);
+ }
+ return result;
+ }
+
+ public Set<DeltaspikeAuthorityMethod> getAuthorityMethods(IPath path) {
+ Set<DeltaspikeAuthorityMethod> result = new
HashSet<DeltaspikeAuthorityMethod>();
+ for(DeltaspikeAuthorityMethod m: allAuthorizerMethods.getAuthorizerMembers()) {
+ if(path.equals(m.getPath())) {
+ result.add(m);
+ }
+ }
+ return result;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityDefinitionContext.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityExtension.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityExtension.java 2012-05-23
00:25:01 UTC (rev 41269)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityExtension.java 2012-05-23
00:44:26 UTC (rev 41270)
@@ -10,7 +10,37 @@
******************************************************************************/
package org.jboss.tools.cdi.deltaspike.core;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.cdi.core.IRootDefinitionContext;
import org.jboss.tools.cdi.core.extension.ICDIExtension;
+import org.jboss.tools.cdi.core.extension.IDefinitionContextExtension;
+import org.jboss.tools.cdi.core.extension.feature.IBuildParticipantFeature;
+import org.jboss.tools.cdi.core.extension.feature.IProcessAnnotatedMemberFeature;
+import org.jboss.tools.cdi.core.extension.feature.IProcessAnnotatedTypeFeature;
+import org.jboss.tools.cdi.core.extension.feature.IValidatorFeature;
+import org.jboss.tools.cdi.deltaspike.core.validation.DeltaspikeValidationMessages;
+import org.jboss.tools.cdi.internal.core.impl.CDIProject;
+import org.jboss.tools.cdi.internal.core.impl.definition.AbstractMemberDefinition;
+import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
+import org.jboss.tools.cdi.internal.core.impl.definition.BeanMemberDefinition;
+import org.jboss.tools.cdi.internal.core.impl.definition.MethodDefinition;
+import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
+import org.jboss.tools.cdi.internal.core.scanner.FileSet;
+import org.jboss.tools.cdi.internal.core.validation.CDICoreValidator;
+import org.jboss.tools.common.java.IAnnotationDeclaration;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.preferences.SeverityPreferences;
/**
* Runtime
@@ -18,6 +48,183 @@
*
* @author Viacheslav Kabanovich
*/
-public class DeltaspikeSecurityExtension implements ICDIExtension {
+public class DeltaspikeSecurityExtension implements ICDIExtension,
IBuildParticipantFeature, IProcessAnnotatedTypeFeature, IProcessAnnotatedMemberFeature,
IValidatorFeature, DeltaspikeConstants {
+ DeltaspikeSecurityDefinitionContext context = new
DeltaspikeSecurityDefinitionContext();
+ @Override
+ public IDefinitionContextExtension getContext() {
+ return context;
+ }
+
+ @Override
+ public void beginVisiting() {}
+
+ @Override
+ public void visitJar(IPath path, IPackageFragmentRoot root, XModelObject beansXML) {}
+
+ @Override
+ public void visit(IFile file, IPath src, IPath webinf) {}
+
+ @Override
+ public void buildDefinitions() {}
+
+ @Override
+ public void buildDefinitions(FileSet fileSet) {}
+
+ @Override
+ public void buildBeans(CDIProject target) {}
+
+ @Override
+ public void processAnnotatedMember(BeanMemberDefinition memberDefinition,
+ IRootDefinitionContext context) {
+ if(!(memberDefinition instanceof MethodDefinition)) {
+ return;
+ }
+ if(memberDefinition.isAnnotationPresent(SECURES_ANNOTATION_TYPE_NAME)) {
+ MethodDefinition method = (MethodDefinition)memberDefinition;
+ method.setCDIAnnotated(true);
+ DeltaspikeAuthorityMethod authorizer = new DeltaspikeAuthorityMethod(method);
+ ((DeltaspikeSecurityDefinitionContext)this.context.getWorkingCopy()).allAuthorizerMethods.getAuthorizerMembers().add(authorizer);
+ List<IAnnotationDeclaration> ds =
findAnnotationAnnotatedWithSecurityBindingType(memberDefinition);
+ for (IAnnotationDeclaration d: ds) {
+ DeltaspikeSecurityBindingConfiguration c =
((DeltaspikeSecurityDefinitionContext)this.context.getWorkingCopy()).getConfiguration(d.getTypeName());
+ authorizer.addBinding(d, c);
+ c.getAuthorizerMembers().add(authorizer);
+ addToDependencies(c, authorizer.getMethod(), context);
+ }
+ } else {
+ addSecurityMember(memberDefinition, context);
+ }
+ }
+
+ @Override
+ public void processAnnotatedType(TypeDefinition typeDefinition,
+ IRootDefinitionContext context) {
+ addSecurityMember(typeDefinition, context);
+ }
+
+ private void addSecurityMember(AbstractMemberDefinition def, IRootDefinitionContext
context) {
+ List<IAnnotationDeclaration> ds =
findAnnotationAnnotatedWithSecurityBindingType(def);
+ for (IAnnotationDeclaration d: ds) {
+ addBoundMember(def, d, context);
+ }
+ }
+
+ private void addBoundMember(AbstractMemberDefinition def, IAnnotationDeclaration d,
IRootDefinitionContext context) {
+ String securityBindingType = d.getTypeName();
+ if(def instanceof MethodDefinition) {
+ ((MethodDefinition)def).setCDIAnnotated(true);
+ }
+ DeltaspikeSecurityBindingConfiguration c =
((DeltaspikeSecurityDefinitionContext)this.context.getWorkingCopy()).getConfiguration(securityBindingType);
+
+ c.getBoundMembers().put(def, d);
+
+ addToDependencies(c, def, context);
+ }
+
+
+ private void addToDependencies(DeltaspikeSecurityBindingConfiguration c,
AbstractMemberDefinition def, IRootDefinitionContext context) {
+ IResource r = def.getResource();
+ if(r != null && r.exists() &&
!c.getInvolvedTypes().contains(r.getFullPath())) {
+ IPath newPath = r.getFullPath();
+ Set<IPath> ps = c.getInvolvedTypes();
+ for (IPath p: ps) {
+ context.addDependency(p, newPath);
+ context.addDependency(newPath, p);
+ }
+ ps.add(newPath);
+ }
+ }
+
+ static List<IAnnotationDeclaration> EMPTY =
Collections.<IAnnotationDeclaration>emptyList();
+
+ private List<IAnnotationDeclaration>
findAnnotationAnnotatedWithSecurityBindingType(AbstractMemberDefinition m) {
+ List<IAnnotationDeclaration> result = null;
+ List<IAnnotationDeclaration> ds = m.getAnnotations();
+ for (IAnnotationDeclaration d: ds) {
+ if(d.getTypeName() != null) {
+ AnnotationDefinition a = context.getRootContext().getAnnotation(d.getTypeName());
+ if(a != null && a.isAnnotationPresent(SECURITY_BINDING_ANNOTATION_TYPE_NAME))
{
+ if(result == null) {
+ result = new ArrayList<IAnnotationDeclaration>();
+ }
+ result.add(d);
+ }
+ }
+ }
+ return result == null ? EMPTY : result;
+ }
+
+ @Override
+ public void validateResource(IFile file, CDICoreValidator validator) {
+ Set<DeltaspikeAuthorityMethod> authorizers =
context.getAuthorityMethods(file.getFullPath());
+ for (DeltaspikeAuthorityMethod authorizer: authorizers) {
+ IAnnotationDeclaration a =
authorizer.getMethod().getAnnotation(SECURES_ANNOTATION_TYPE_NAME);
+ if(authorizer.getBindings().isEmpty()) {
+ validator.addError(DeltaspikeValidationMessages.INVALID_AUTHORIZER_NO_BINDINGS,
+ DeltaspikeSeverityPreferences.INVALID_AUTHORIZER,
+ new String[]{authorizer.getMethod().getMethod().getElementName()},
+ a, file);
+ } else if(authorizer.getBindings().size() > 1) {
+ validator.addError(DeltaspikeValidationMessages.INVALID_AUTHORIZER_MULTIPLE_BINDINGS,
+ DeltaspikeSeverityPreferences.INVALID_AUTHORIZER,
+ new String[]{authorizer.getMethod().getMethod().getElementName()},
+ a, file);
+ }
+ try {
+ String returnType = authorizer.getMethod().getMethod().getReturnType();
+ if(!"Z".equals(returnType)) { //$NON-NLS-1$
+ validator.addError(DeltaspikeValidationMessages.INVALID_AUTHORIZER_NOT_BOOLEAN,
+ DeltaspikeSeverityPreferences.INVALID_AUTHORIZER,
+ new String[]{authorizer.getMethod().getMethod().getElementName()},
+ a, file);
+ }
+
+ } catch (JavaModelException e) {
+ DeltaspikeCorePlugin.getDefault().logError(e);
+ }
+
+ }
+
+ for (DeltaspikeSecurityBindingConfiguration c: context.getConfigurations().values()) {
+ if(c.getInvolvedTypes().contains(file.getFullPath())) {
+ Set<DeltaspikeAuthorityMethod> authorizers2 = c.getAuthorizerMembers();
+ Map<AbstractMemberDefinition, IAnnotationDeclaration> bound =
c.getBoundMembers();
+ for (AbstractMemberDefinition d: bound.keySet()) {
+ String name = d instanceof MethodDefinition ?
((MethodDefinition)d).getMethod().getElementName()
+ : d instanceof TypeDefinition ? ((TypeDefinition)d).getQualifiedName() :
"";
+ if(file.getFullPath().equals(d.getTypeDefinition().getType().getPath())) {
+ IAnnotationDeclaration dc = bound.get(d);
+ int k = 0;
+ for (DeltaspikeAuthorityMethod a: authorizers2) {
+ try {
+ if(a.isMatching(dc)) k++;
+ } catch (CoreException e) {
+ DeltaspikeCorePlugin.getDefault().logError(e);
+ }
+ }
+ if(k == 0) {
+ validator.addError(DeltaspikeValidationMessages.UNRESOLVED_AUTHORIZER,
+ DeltaspikeSeverityPreferences.UNRESOLVED_AUTHORIZER,
+ new String[]{dc.getTypeName(), name},
+ dc, file);
+ } else if(k > 1) {
+ validator.addError(DeltaspikeValidationMessages.AMBIGUOUS_AUTHORIZER,
+ DeltaspikeSeverityPreferences.AMBIGUOUS_AUTHORIZER,
+ new String[]{dc.getTypeName(), name},
+ dc, file);
+ }
+
+ }
+ }
+ }
+ }
+ //
+ }
+
+ @Override
+ public SeverityPreferences getSeverityPreferences() {
+ return DeltaspikeSeverityPreferences.getInstance();
+ }
+
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSeverityPreferenceInitializer.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSeverityPreferenceInitializer.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSeverityPreferenceInitializer.java 2012-05-23
00:44:26 UTC (rev 41270)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.deltaspike.core;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.jboss.tools.common.preferences.SeverityPreferences;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class DeltaspikeSeverityPreferenceInitializer extends
AbstractPreferenceInitializer {
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
+ */
+ @Override
+ public void initializeDefaultPreferences() {
+ IEclipsePreferences defaultPreferences = ((IScopeContext) new
DefaultScope()).getNode(DeltaspikeCorePlugin.PLUGIN_ID);
+ for (String name : DeltaspikeSeverityPreferences.SEVERITY_OPTION_NAMES) {
+ defaultPreferences.put(name, SeverityPreferences.WARNING);
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSeverityPreferenceInitializer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSeverityPreferences.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSeverityPreferences.java 2012-05-23
00:25:01 UTC (rev 41269)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSeverityPreferences.java 2012-05-23
00:44:26 UTC (rev 41270)
@@ -27,6 +27,9 @@
public static final Set<String> SEVERITY_OPTION_NAMES = new
HashSet<String>();
public static final String WARNING_GROUP_ID = "deltaspike"; //$NON-NLS-1$
+ public static final String AMBIGUOUS_AUTHORIZER =
INSTANCE.createSeverityOption("ambiguousAuthorizer",
"ambiguous-authorizer"); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final String UNRESOLVED_AUTHORIZER =
INSTANCE.createSeverityOption("unresolvedAuthorizer",
"unresolved-authorizer"); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final String INVALID_AUTHORIZER =
INSTANCE.createSeverityOption("invalidAuthorizer",
"invalid-authorizer"); //$NON-NLS-1$ //$NON-NLS-2$
public static DeltaspikeSeverityPreferences getInstance() {
return INSTANCE;
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/DeltaspikeValidationMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/DeltaspikeValidationMessages.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/DeltaspikeValidationMessages.java 2012-05-23
00:44:26 UTC (rev 41270)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.deltaspike.core.validation;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class DeltaspikeValidationMessages extends NLS {
+ private static final String BUNDLE_NAME =
DeltaspikeValidationMessages.class.getPackage().getName() + ".messages";
//$NON-NLS-1$
+
+ public static String AMBIGUOUS_AUTHORIZER;
+ public static String UNRESOLVED_AUTHORIZER;
+ public static String INVALID_AUTHORIZER_MULTIPLE_BINDINGS;
+ public static String INVALID_AUTHORIZER_NO_BINDINGS;
+ public static String INVALID_AUTHORIZER_NOT_BOOLEAN;
+
+ public static String INVALID_AUTHORIZER;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, DeltaspikeValidationMessages.class);
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/DeltaspikeValidationMessages.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/messages.properties
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/messages.properties 2012-05-23
00:44:26 UTC (rev 41270)
@@ -0,0 +1,5 @@
+AMBIGUOUS_AUTHORIZER=Ambiguous authorizers found for security binding type {0} on method
{1}.
+UNRESOLVED_AUTHORIZER=No matching authorizer found for security binding type {0} on
method {1}.
+INVALID_AUTHORIZER_MULTIPLE_BINDINGS=Authorizer method {0} declares multiple security
binding types.
+INVALID_AUTHORIZER_NO_BINDINGS=Authorizer method {0} does not declare a security binding
type.
+INVALID_AUTHORIZER_NOT_BOOLEAN=Authorizer method {0} does not return a boolean.
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/validation/messages.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain