You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2006/11/07 07:46:35 UTC

svn commit: r472008 - in /myfaces/tobago/trunk: contrib/security/ contrib/security/src/main/java/org/apache/myfaces/tobago/security/ contrib/security/src/main/resources/META-INF/ core/src/main/java/org/apache/myfaces/tobago/component/

Author: bommel
Date: Mon Nov  6 22:46:34 2006
New Revision: 472008

URL: http://svn.apache.org/viewvc?view=rev&rev=472008
Log:
added secured command
added disabled method in UICommand

Added:
    myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/UISecuredCommand.java
Modified:
    myfaces/tobago/trunk/contrib/security/pom.xml
    myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/CheckAuthorisationMethodBinding.java
    myfaces/tobago/trunk/contrib/security/src/main/resources/META-INF/faces-config.xml
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java

Modified: myfaces/tobago/trunk/contrib/security/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/contrib/security/pom.xml?view=diff&rev=472008&r1=472007&r2=472008
==============================================================================
--- myfaces/tobago/trunk/contrib/security/pom.xml (original)
+++ myfaces/tobago/trunk/contrib/security/pom.xml Mon Nov  6 22:46:34 2006
@@ -31,6 +31,11 @@
   </scm>
   <dependencies>
     <dependency>
+      <groupId>org.apache.myfaces.tobago</groupId>
+      <artifactId>tobago-core</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <version>2.4</version>

Modified: myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/CheckAuthorisationMethodBinding.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/CheckAuthorisationMethodBinding.java?view=diff&rev=472008&r1=472007&r2=472008
==============================================================================
--- myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/CheckAuthorisationMethodBinding.java (original)
+++ myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/CheckAuthorisationMethodBinding.java Mon Nov  6 22:46:34 2006
@@ -79,7 +79,7 @@
     }
   }
 
-  private boolean isAuthorized(FacesContext facesContext) {
+  public boolean isAuthorized(FacesContext facesContext) {
 
     Annotation securityAnnotation = getSecurityAnnotation(facesContext);
     if (securityAnnotation == null) {

Added: myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/UISecuredCommand.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/UISecuredCommand.java?view=auto&rev=472008
==============================================================================
--- myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/UISecuredCommand.java (added)
+++ myfaces/tobago/trunk/contrib/security/src/main/java/org/apache/myfaces/tobago/security/UISecuredCommand.java Mon Nov  6 22:46:34 2006
@@ -0,0 +1,41 @@
+package org.apache.myfaces.tobago.security;
+
+/*
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import org.apache.myfaces.tobago.component.UICommand;
+
+import javax.faces.context.FacesContext;
+
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Nov 6, 2006
+ * Time: 10:14:09 PM
+ */
+public class UISecuredCommand extends UICommand {
+
+  public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.SecurityCommand";
+
+  public boolean isDisabled() {
+    if (getAction() instanceof CheckAuthorisationMethodBinding) {
+      return !((CheckAuthorisationMethodBinding) getAction()).isAuthorized(FacesContext.getCurrentInstance())
+          || super.isDisabled();
+    }
+    return super.isDisabled();
+  }
+}

Modified: myfaces/tobago/trunk/contrib/security/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/contrib/security/src/main/resources/META-INF/faces-config.xml?view=diff&rev=472008&r1=472007&r2=472008
==============================================================================
--- myfaces/tobago/trunk/contrib/security/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/contrib/security/src/main/resources/META-INF/faces-config.xml Mon Nov  6 22:46:34 2006
@@ -26,4 +26,9 @@
     <application-factory>org.apache.myfaces.tobago.security.ApplicationFactoryImpl</application-factory>
   </factory>
 
+  <component>
+    <component-type>org.apache.myfaces.tobago.Command</component-type>
+    <component-class>org.apache.myfaces.tobago.security.UISecuredCommand</component-class>
+  </component>
+
 </faces-config>

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java?view=diff&rev=472008&r1=472007&r2=472008
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java Mon Nov  6 22:46:34 2006
@@ -17,6 +17,7 @@
  */
 
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DEFAULT_COMMAND;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -34,6 +35,7 @@
   public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Command";
 
   private Boolean defaultCommand;
+  private Boolean disabled;
 
   public boolean isDefaultCommand() {
     if (defaultCommand != null) {
@@ -51,10 +53,27 @@
     this.defaultCommand = defaultCommand;
   }
 
+  public boolean isDisabled() {
+    if (disabled != null) {
+      return disabled;
+    }
+    ValueBinding vb = getValueBinding(ATTR_DISABLED);
+    if (vb != null) {
+      return Boolean.TRUE.equals(vb.getValue(getFacesContext()));
+    } else {
+      return false;
+    }
+  }
+
+  public void setDisabled(boolean disabled) {
+    this.disabled = disabled;
+  }
+
   public Object saveState(FacesContext context) {
-    Object[] saveState = new Object[2];
+    Object[] saveState = new Object[3];
     saveState[0] = super.saveState(context);
     saveState[1] = defaultCommand;
+    saveState[2] = disabled;
     return saveState;
   }
 
@@ -62,6 +81,7 @@
     Object[] values = (Object[]) savedState;
     super.restoreState(context, values[0]);
     defaultCommand = (Boolean) values[1];
+    disabled = (Boolean) values[2];
   }