JBoss Portal SVN: r13468 - in modules/common/trunk/common/src: test/java/org/jboss/portal/test/common/net and 1 other directory.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-06-17 17:22:49 -0400 (Wed, 17 Jun 2009)
New Revision: 13468
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLTools.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/URLToolsTestCase.java
Log:
JBPORTAL-2426: added archive to LINK URL detection pattern
Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLTools.java
===================================================================
--- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLTools.java 2009-06-17 15:04:30 UTC (rev 13467)
+++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLTools.java 2009-06-17 21:22:49 UTC (rev 13468)
@@ -50,7 +50,7 @@
public class URLTools
{
public static final String RE_EMAIL_VALIDATION = "^([a-zA-Z0-9]+(([\\.\\-\\_]?[a-zA-Z0-9]+)+)?)\\(a)(([a-zA-Z0-9]+[\\.\\-\\_])+[a-zA-Z]{2,4})$";
- private static final Pattern LINK = Pattern.compile("(?:href|action|src|location)\\s*=\\s*('|\")\\s*([^'\"]*)\\s*('|\")",
+ private static final Pattern LINK = Pattern.compile("(?:href|action|src|location|archive)\\s*=\\s*('|\")\\s*([^'\"]*)\\s*('|\")",
Pattern.CASE_INSENSITIVE);
public static final String HTTP_PREFIX = "http://";
Modified: modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/URLToolsTestCase.java
===================================================================
--- modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/URLToolsTestCase.java 2009-06-17 15:04:30 UTC (rev 13467)
+++ modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/URLToolsTestCase.java 2009-06-17 21:22:49 UTC (rev 13468)
@@ -83,6 +83,12 @@
assertEquals(url.length() + startIndex, link.getEnd());
assertEquals(url, markup.substring(link.getStart(), link.getEnd()));
assertEquals(url, link.getURLAsString());
+
+ markup = "<applet code=\"org.jboss.applet.hello.HelloApplet\" archive=\"wsrp_rewrite?wsrp-urlType=resource&" +
+ "wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite/helloapplet.jar" +
+ "\" width=\"1000\" height=\"50\">\n</applet>";
+ links = URLTools.extractURLsFrom(markup);
+ assertEquals("wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite/helloapplet.jar", links[0].getURLAsString());
}
public void testReplaceURLs()
16 years, 10 months
JBoss Portal SVN: r13467 - in branches/JBoss_Portal_Branch_2_7/core-cms/src: resources/portal-cms-war/WEB-INF/classes and 1 other directory.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-06-17 11:04:30 -0400 (Wed, 17 Jun 2009)
New Revision: 13467
Modified:
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties
branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource_fr.properties
Log:
- JBPORTAL-2417: hopefully fixed the incorrect saving of invalid data.
Modified: branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2009-06-17 02:39:53 UTC (rev 13466)
+++ branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2009-06-17 15:04:30 UTC (rev 13467)
@@ -920,7 +920,7 @@
String sFolderName = aReq.getParameter("newcollectionname");
String sFolderDescription = aReq.getParameter("newcollectiondescription");
sFolderDescription = ParameterValidation.sanitizeFromPattern(sFolderDescription, CHECK_FOR_XSS_PATTERN, "");
-
+
if (!"".equals(sCreatePath) && !"".equals(sFolderName) && !"".equals(sFolderDescription))
{
String sNewPath = FileUtil.cleanDoubleSlashes(sCreatePath + SLASH + sFolderName);
@@ -1518,21 +1518,17 @@
sLanguage = ParameterValidation.sanitizeFromPattern(sLanguage, CHECK_FOR_XSS_PATTERN, INVALID_LANG);
boolean invalidLang = INVALID_LANG.equals(sLanguage);
- if (invalidLang)
-
+ if (invalidTitle || invalidDesc || invalidLang)
{
- if (invalidTitle || invalidDesc || invalidLang)
- {
- aRes.setRenderParameter("op", CMSAdminConstants.OP_EDIT);
+ aRes.setRenderParameter("op", CMSAdminConstants.OP_EDIT);
- // output error message
- aRes.setRenderParameter(ERROR_MESSAGE, CMSAdminConstants.CMS_INVALID_PARAMETER);
+ // output error message
+ aRes.setRenderParameter(ERROR_MESSAGE, CMSAdminConstants.CMS_INVALID_PARAMETER);
- aRes.setRenderParameter("path", aReq.getParameter("savetopath"));
- aRes.setRenderParameter("language", aReq.getParameter("language"));
+ aRes.setRenderParameter("path", aReq.getParameter("savetopath"));
+ aRes.setRenderParameter("language", aReq.getParameter("language"));
- return;
- }
+ return;
}
Locale locale = new Locale(sLanguage);
Modified: branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties 2009-06-17 02:39:53 UTC (rev 13466)
+++ branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties 2009-06-17 15:04:30 UTC (rev 13467)
@@ -1,6 +1,6 @@
################################################################################
# JBoss, a division of Red Hat #
-# Copyright 2006, Red Hat Middleware, LLC, and individual #
+# Copyright 2009, Red Hat Middleware, LLC, and individual #
# contributors as indicated by the @authors tag. See the #
# copyright.txt in the distribution for a full listing of #
# individual contributors. #
@@ -143,7 +143,7 @@
CMS_FILENAME_INVALID=File Name is invalid. It may not contain illegal characters such as '.', '/', ':', '[', ']', '*', ''', '"', '|' or any whitespace character.
CMS_FOLDERNAME_INVALID=Folder Name is invalid. It may not contain illegal characters such as '.', '/', ':', '[', ']', '*', ''', '"', '|' or any whitespace character.
-CMS_INVALID_PARAMETER=A value below is invalid. It may not contain illegal characters such as '\\', '<', '>', '(', ')', '=' or '%5c'.
+CMS_INVALID_PARAMETER=A value below was invalid. It may not contain illegal characters such as '\\', '<', '>', '(', ')', '=' or '%5c'.
CMS_MSG_DESTINATION_ALREADY_EXISTS=The command was not performed, because the destination already exists.
CMS_CANT_MOVE_SAME_DESTINATION=You cannot move a folder to the same location
Modified: branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource_fr.properties
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource_fr.properties 2009-06-17 02:39:53 UTC (rev 13466)
+++ branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource_fr.properties 2009-06-17 15:04:30 UTC (rev 13467)
@@ -1,7 +1,6 @@
-#Generated by ResourceBundle Editor (http://eclipse-rbe.sourceforge.net)
################################################################################
# JBoss, a division of Red Hat #
-# Copyright 2006, Red Hat Middleware, LLC, and individual #
+# Copyright 2009, Red Hat Middleware, LLC, and individual #
# contributors as indicated by the @authors tag. See the #
# copyright.txt in the distribution for a full listing of #
# individual contributors. #
@@ -160,4 +159,4 @@
CMS_MISSING_DOCUMENT=404 - Page non trouv\u00e9e
CMS_MISSING_DOCUMENT_DESCRIPTION=Le document auquel vous avez tent\u00e9 d'acc\u00e9der est introuvable
-CMS_INVALID_PARAMETER=Une valeur ci-dessous est invalide car elle contient des caract\u00e8rs invalides '\\', '<', '>', '(', ')', '=' ou '%5c'.
\ No newline at end of file
+CMS_INVALID_PARAMETER=Une valeur ci-dessous \u00e9tait invalide car elle contenait des caract\u00e8rs invalides '\\', '<', '>', '(', ')', '=' ou '%5c'.
\ No newline at end of file
16 years, 10 months
JBoss Portal SVN: r13466 - in branches/JBoss_Portal_Branch_2_7: core-admin/src/resources/portal-admin-war/WEB-INF/classes and 2 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-06-16 22:39:53 -0400 (Tue, 16 Jun 2009)
New Revision: 13466
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/classes/Resource.properties
branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/test/wsrp/other/ConsumerBeanTestCase.java
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java
Log:
- Use bean context to output messages in PortalObjectManagerBean, improving localization.
- Made getErrorSeverity, getInfoSeverity and createLocalizedMessage methods public on BeanContext.
Modified: branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2009-06-16 23:27:47 UTC (rev 13465)
+++ branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2009-06-17 02:39:53 UTC (rev 13466)
@@ -58,7 +58,6 @@
import org.jboss.portal.theme.LayoutService;
import org.jboss.portal.theme.ThemeService;
-import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
@@ -128,9 +127,6 @@
private String selectedContentURI;
/** . */
-// private Map selectedContentParameters = new HashMap();
-
- /** . */
private Map<String, String[]> renderParameters;
// Runtime state
@@ -340,16 +336,6 @@
this.renderParameters = renderParameters;
}
- /*public Map getSelectedContentParameters()
- {
- return selectedContentParameters;
- }
-
- public void setSelectedContentParameters(Map selectedContentParameters)
- {
- this.selectedContentParameters = selectedContentParameters;
- }*/
-
public DomainConfigurator getDomainConfigurator()
{
return domainConfigurator;
@@ -480,10 +466,7 @@
String name = object.getName();
parent.setDeclaredProperty(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME, name);
-
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Success",
- "'" + name + "' " + typeName + " was successfully set as default " + typeName);
- FacesContext.getCurrentInstance().addMessage("status", message);
+ beanContext.createLocalizedMessage(BeanContext.STATUS, "MAKE_DEFAULT_SUCCESS", beanContext.getInfoSeverity(), name, typeName);
}
}
@@ -619,22 +602,17 @@
{
selectObject(object.getParent());
- String stringMessage = object.getName() + " has successfully been destroyed";
+ String name = object.getName();
- //
- object.getParent().destroyChild(object.getName());
+ object.getParent().destroyChild(name);
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, stringMessage, stringMessage);
- FacesContext.getCurrentInstance().addMessage("status", message);
+ beanContext.createLocalizedMessage(BeanContext.STATUS, "DESTROY_SUCCESS", beanContext.getInfoSeverity(), name);
selectedDeletingObject = null;
}
else
{
- String stringMessage = "Cannot delete this already deleted object";
-
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, stringMessage, stringMessage);
- FacesContext.getCurrentInstance().addMessage("status", message);
+ beanContext.createLocalizedMessage(BeanContext.STATUS, "DESTROY_FAILURE", beanContext.getInfoSeverity(), id);
}
}
}
@@ -784,9 +762,7 @@
public String submit()
{
- String stringMessage = "Security has been correctly updated on the page";
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, stringMessage, stringMessage);
- FacesContext.getCurrentInstance().addMessage("status", message);
+ beanContext.createInfoMessage("SECURITY_UPDATED");
//
return "objects";
Modified: branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/classes/Resource.properties
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/classes/Resource.properties 2009-06-16 23:27:47 UTC (rev 13465)
+++ branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/classes/Resource.properties 2009-06-17 02:39:53 UTC (rev 13466)
@@ -340,3 +340,8 @@
PROPERTY_TYPE=property
PORTAL_OBJECT_TYPE=portal object
WINDOW_TYPE=window
+
+MAKE_DEFAULT_SUCCESS= ''{0}'' {1} was successfully set as default {1}
+DESTROY_SUCCESS=''{0}'' has successfully been destroyed
+DESTROY_FAILURE=Couldn''t delete inexisting object with id ''{0}''
+SECURITY_UPDATED=Security has been correctly updated on the page
Modified: branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/test/wsrp/other/ConsumerBeanTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/test/wsrp/other/ConsumerBeanTestCase.java 2009-06-16 23:27:47 UTC (rev 13465)
+++ branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/test/wsrp/other/ConsumerBeanTestCase.java 2009-06-17 02:39:53 UTC (rev 13466)
@@ -85,12 +85,12 @@
// ignore for tests
}
- protected Object getErrorSeverity()
+ public Object getErrorSeverity()
{
return null;
}
- protected Object getInfoSeverity()
+ public Object getInfoSeverity()
{
return null;
}
Modified: branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java 2009-06-16 23:27:47 UTC (rev 13465)
+++ branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java 2009-06-17 02:39:53 UTC (rev 13466)
@@ -74,9 +74,9 @@
*/
protected abstract void createMessage(String target, String message, Object severity);
- protected abstract Object getErrorSeverity();
+ public abstract Object getErrorSeverity();
- protected abstract Object getInfoSeverity();
+ public abstract Object getInfoSeverity();
protected abstract Locale getLocale();
@@ -99,7 +99,7 @@
* @param severity an object representing the severity of the message (typically FacesMessage.Severity)
* @param params additional parameters to be passed to replace tokens in localized strings
*/
- protected void createLocalizedMessage(String target, String localizedMessageId, Object severity, Object... params)
+ public void createLocalizedMessage(String target, String localizedMessageId, Object severity, Object... params)
{
createMessage(target, getMessageFromBundle(localizedMessageId, params), severity);
}
Modified: branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java 2009-06-16 23:27:47 UTC (rev 13465)
+++ branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java 2009-06-17 02:39:53 UTC (rev 13466)
@@ -85,7 +85,7 @@
// Get the component id from the target
FacesContext facesContext = FacesContext.getCurrentInstance();
target = resolveTargetId(target, facesContext);
- if(target == null)
+ if (target == null)
{
// if we couldn't find the component, default to STATUS
log.info("Couldn't resolve component target: " + target + ". Using '" + STATUS + "' instead.");
@@ -120,20 +120,20 @@
public static void outputLocalizedMessage(String target, String localizationKey, Object severity, String resourceName, Object... params)
{
- if(severity == null)
+ if (severity == null)
{
severity = FacesMessage.SEVERITY_ERROR;
}
-
+
outputMessage(target, getLocalizedMessage(localizationKey, getRequestLocale(), resourceName, params), severity);
}
- protected Object getErrorSeverity()
+ public Object getErrorSeverity()
{
return FacesMessage.SEVERITY_ERROR;
}
- protected Object getInfoSeverity()
+ public Object getInfoSeverity()
{
return FacesMessage.SEVERITY_INFO;
}
16 years, 10 months
JBoss Portal SVN: r13465 - in branches/JBoss_Portal_Branch_2_7: core-admin/src/resources/portal-admin-war/jsf and 2 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-06-16 19:27:47 -0400 (Tue, 16 Jun 2009)
New Revision: 13465
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/DisplayNameAction.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/jsf/displayNameObject.xhtml
branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/test/wsrp/other/ConsumerBeanTestCase.java
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java
Log:
- Added isTargetResolved to BeanContext to be able to check that a given target String can be used to display error message.
- JBPORTAL-2419:
+ DisplayNameAction now switches the error target as it varies on context (defaults to status if cannot be resolved)
+ Added missing message in displayNameObject.xhtml
Modified: branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/DisplayNameAction.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/DisplayNameAction.java 2009-06-16 21:00:24 UTC (rev 13464)
+++ branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/DisplayNameAction.java 2009-06-16 23:27:47 UTC (rev 13465)
@@ -29,6 +29,7 @@
import org.jboss.portal.core.admin.ui.DisplayNameBean;
import org.jboss.portal.core.model.HasDisplayName;
import org.jboss.portal.faces.gui.ManagedBean;
+import org.jboss.portal.faces.gui.BeanContext;
import java.util.Collection;
import java.util.HashMap;
@@ -49,6 +50,8 @@
protected DisplayNameBean displayNameBean;
protected HasDisplayName target;
protected static final String DISPLAY_NAME_TYPE = "DISPLAY_NAME_TYPE";
+ private static final String DISPLAY_NAME_DIRECT = "display-name-form:newName";
+ private static final String DISPLAY_NAME_IN_VIEW = "display-names-view:add-display-name-form:newName";
public Object getManagerBean()
{
@@ -102,7 +105,24 @@
public void addDisplayName() throws ConversionException
{
- newText = checkNameValidity(newText, "display-names-view:add-display-name-form:newName");
+ String errorMessageTarget;
+ boolean directResolved = beanContext.isTargetResolved(DISPLAY_NAME_DIRECT);
+ boolean inViewResolved = beanContext.isTargetResolved(DISPLAY_NAME_IN_VIEW);
+
+ if(directResolved)
+ {
+ errorMessageTarget = DISPLAY_NAME_DIRECT;
+ }
+ else if (inViewResolved)
+ {
+ errorMessageTarget = DISPLAY_NAME_IN_VIEW;
+ }
+ else
+ {
+ errorMessageTarget = BeanContext.STATUS;
+ }
+
+ newText = checkNameValidity(newText, errorMessageTarget);
if (newText != null)
{
HasDisplayName hasDisplayName = getTarget();
Modified: branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/jsf/displayNameObject.xhtml
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/jsf/displayNameObject.xhtml 2009-06-16 21:00:24 UTC (rev 13464)
+++ branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/jsf/displayNameObject.xhtml 2009-06-16 23:27:47 UTC (rev 13465)
@@ -20,6 +20,7 @@
</h:selectOneMenu>
<h:commandButton id="add-display" value="#{addDisplayNameAction.newText ne null ? 'Modify' : 'Add'} Name" action="#{addDisplayNameAction.addDisplayName}"
styleClass="portlet-form-button"/>
+ <h:message for="newName" errorClass="portlet-msg-error"/>
</div>
</h:form>
</div>
Modified: branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/test/wsrp/other/ConsumerBeanTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/test/wsrp/other/ConsumerBeanTestCase.java 2009-06-16 21:00:24 UTC (rev 13464)
+++ branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/test/wsrp/other/ConsumerBeanTestCase.java 2009-06-16 23:27:47 UTC (rev 13465)
@@ -104,5 +104,11 @@
{
throw new NotYetImplemented();
}
+
+ @Override
+ public boolean isTargetResolved(String target)
+ {
+ throw new NotYetImplemented();
+ }
}
}
Modified: branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java 2009-06-16 21:00:24 UTC (rev 13464)
+++ branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java 2009-06-16 23:27:47 UTC (rev 13465)
@@ -284,4 +284,6 @@
return expectedClass.cast(result);
}
+
+ public abstract boolean isTargetResolved(String target);
}
Modified: branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java 2009-06-16 21:00:24 UTC (rev 13464)
+++ branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java 2009-06-16 23:27:47 UTC (rev 13465)
@@ -84,6 +84,20 @@
// Get the component id from the target
FacesContext facesContext = FacesContext.getCurrentInstance();
+ target = resolveTargetId(target, facesContext);
+ if(target == null)
+ {
+ // if we couldn't find the component, default to STATUS
+ log.info("Couldn't resolve component target: " + target + ". Using '" + STATUS + "' instead.");
+ target = STATUS;
+ }
+
+ FacesMessage msg = new FacesMessage(jsfSeverity, message, message);
+ facesContext.addMessage(target, msg);
+ }
+
+ protected static String resolveTargetId(String target, FacesContext facesContext)
+ {
UIViewRoot viewRoot = facesContext.getViewRoot();
UIComponent component = viewRoot.findComponent(target);
if (component != null)
@@ -92,12 +106,16 @@
}
else
{
- // todo: do something better here
- log.info("Couldn't resolve component target: " + target);
+ target = null;
}
+ return target;
+ }
- FacesMessage msg = new FacesMessage(jsfSeverity, message, message);
- facesContext.addMessage(target, msg);
+ @Override
+ public boolean isTargetResolved(String target)
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ return resolveTargetId(target, facesContext) != null;
}
public static void outputLocalizedMessage(String target, String localizationKey, Object severity, String resourceName, Object... params)
16 years, 10 months
JBoss Portal SVN: r13464 - in branches/JBoss_Portal_Branch_2_7/core-cms/src: resources/portal-cms-war/WEB-INF/jsp/cms/admin and 1 other directory.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-06-16 17:00:24 -0400 (Tue, 16 Jun 2009)
New Revision: 13464
Modified:
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/confirmcreatecollection.jsp
Log:
- JBPORTAL-2416: validate folder description and output correct error message.
Modified: branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2009-06-16 20:16:50 UTC (rev 13463)
+++ branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2009-06-16 21:00:24 UTC (rev 13464)
@@ -919,7 +919,9 @@
String sCreatePath = aReq.getParameter("destination");
String sFolderName = aReq.getParameter("newcollectionname");
String sFolderDescription = aReq.getParameter("newcollectiondescription");
- if (!"".equals(sCreatePath) && !"".equals(sFolderName))
+ sFolderDescription = ParameterValidation.sanitizeFromPattern(sFolderDescription, CHECK_FOR_XSS_PATTERN, "");
+
+ if (!"".equals(sCreatePath) && !"".equals(sFolderName) && !"".equals(sFolderDescription))
{
String sNewPath = FileUtil.cleanDoubleSlashes(sCreatePath + SLASH + sFolderName);
@@ -968,7 +970,7 @@
aRes.setRenderParameter("path", aReq.getParameter("destination"));
//used to remember the data already submitted by the user
- aRes.setRenderParameter(ERROR_MESSAGE, CMSAdminConstants.CMS_FOLDERNAME_INVALID);
+ aRes.setRenderParameter(ERROR_MESSAGE, CMSAdminConstants.CMS_INVALID_PARAMETER);
aRes.setRenderParameter("error:newcollectionname", aReq.getParameter("newcollectionname"));
aRes.setRenderParameter("error:newcollectiondescription", aReq.getParameter("newcollectiondescription"));
}
Modified: branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/confirmcreatecollection.jsp
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/confirmcreatecollection.jsp 2009-06-16 20:16:50 UTC (rev 13463)
+++ branches/JBoss_Portal_Branch_2_7/core-cms/src/resources/portal-cms-war/WEB-INF/jsp/cms/admin/confirmcreatecollection.jsp 2009-06-16 21:00:24 UTC (rev 13464)
@@ -1,3 +1,4 @@
+<%@ page import="org.jboss.portal.core.cms.CMSConstants" %>
<%@ page language="java" extends="org.jboss.portal.core.servlet.jsp.PortalJsp" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="/WEB-INF/portal-lib.tld" prefix="n" %>
@@ -27,15 +28,32 @@
<h3 class="sectionTitle-blue">${n:i18n("TITLE_CREATECOLLCONFIRM")}</h3>
<div class=" cms-tab-container">
<table width="100%">
- <%if(errorMessage != null){%>
- <tr>
- <td colspan="2">
- <font color="red">${n:i18n("CMS_FOLDERNAME_INVALID")}</font>
- </td>
- </tr>
- <%}%>
-
+ <%
+ if (CMSAdminConstants.CMS_FOLDERNAME_INVALID.equals(errorMessage))
+ {
+ %>
<tr>
+ <td colspan="2">
+ <span style="color: red">${n:i18n("CMS_FOLDERNAME_INVALID")}</span>
+ </td>
+ </tr>
+ <%
+ }
+ %>
+ <%
+ if (CMSAdminConstants.CMS_INVALID_PARAMETER.equals(errorMessage))
+ {
+ %>
+ <tr>
+ <td colspan="2">
+ <span style="color: red">${n:i18n("CMS_INVALID_PARAMETER")}</span>
+ </td>
+ </tr>
+ <%
+ }
+ %>
+
+ <tr>
<td valign="top" width="250" class="portlet-section-alternate">
<%@ include file="folderlist.jsp" %>
</td>
16 years, 10 months
JBoss Portal SVN: r13463 - branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-06-16 16:16:50 -0400 (Tue, 16 Jun 2009)
New Revision: 13463
Modified:
branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
Log:
JBPORTAL-2415: properly handle the empty search string (it really should be done at the search level though).
Modified: branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2009-06-16 16:48:45 UTC (rev 13462)
+++ branches/JBoss_Portal_Branch_2_7/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2009-06-16 20:16:50 UTC (rev 13463)
@@ -82,6 +82,7 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
@@ -439,26 +440,27 @@
rRes.setContentType("text/html");
String textQuery = rReq.getParameter("search");
- FederatedQuery query = new FederatedQuery(textQuery);
+ List files = Collections.emptyList();
+ if (!ParameterValidation.isNullOrEmpty(textQuery))
+ {
+ FederatedQuery query = new FederatedQuery(textQuery);
- JCRQueryConverter converter = new JCRQueryConverter();
+ JCRQueryConverter converter = new JCRQueryConverter();
- List files;
- try
- {
- Command searchCommand = CMSService.getCommandFactory().createSearchCommand((JCRQuery)converter.convert(query));
- files = (List)CMSService.execute(searchCommand);
+ try
+ {
+ Command searchCommand = CMSService.getCommandFactory().createSearchCommand((JCRQuery)converter.convert(query));
+ files = (List)CMSService.execute(searchCommand);
+ }
+ catch (CMSException e)
+ {
+ e.printStackTrace();
+ }
+ catch (QueryConversionException e)
+ {
+ rReq.setAttribute("conversionError", Boolean.TRUE);
+ }
}
- catch (CMSException e)
- {
- e.printStackTrace();
- files = new ArrayList();
- }
- catch (QueryConversionException e)
- {
- files = new ArrayList();
- rReq.setAttribute("conversionError", Boolean.TRUE);
- }
rReq.setAttribute("files", files);
rReq.setAttribute("textQuery", textQuery);
@@ -1508,25 +1510,27 @@
// check title and description for XSS injection... If one found, re-display page with old values
sTitle = ParameterValidation.sanitizeFromPattern(sTitle, CHECK_FOR_XSS_PATTERN, INVALID_TITLE);
boolean invalidTitle = INVALID_TITLE.equals(sTitle);
-
+
sDescription = ParameterValidation.sanitizeFromPattern(sDescription, CHECK_FOR_XSS_PATTERN, INVALID_DESCRIPTION);
boolean invalidDesc = INVALID_DESCRIPTION.equals(sDescription);
sLanguage = ParameterValidation.sanitizeFromPattern(sLanguage, CHECK_FOR_XSS_PATTERN, INVALID_LANG);
boolean invalidLang = INVALID_LANG.equals(sLanguage);
- if(invalidLang)
+ if (invalidLang)
- if (invalidTitle || invalidDesc || invalidLang)
{
- aRes.setRenderParameter("op", CMSAdminConstants.OP_EDIT);
+ if (invalidTitle || invalidDesc || invalidLang)
+ {
+ aRes.setRenderParameter("op", CMSAdminConstants.OP_EDIT);
- // output error message
- aRes.setRenderParameter(ERROR_MESSAGE, CMSAdminConstants.CMS_INVALID_PARAMETER);
+ // output error message
+ aRes.setRenderParameter(ERROR_MESSAGE, CMSAdminConstants.CMS_INVALID_PARAMETER);
- aRes.setRenderParameter("path", aReq.getParameter("savetopath"));
- aRes.setRenderParameter("language", aReq.getParameter("language"));
+ aRes.setRenderParameter("path", aReq.getParameter("savetopath"));
+ aRes.setRenderParameter("language", aReq.getParameter("language"));
- return;
+ return;
+ }
}
Locale locale = new Locale(sLanguage);
16 years, 10 months
JBoss Portal SVN: r13462 - modules/authorization/trunk/agent.
by portal-commits@lists.jboss.org
Author: sohil.shah(a)jboss.com
Date: 2009-06-16 12:48:45 -0400 (Tue, 16 Jun 2009)
New Revision: 13462
Modified:
modules/authorization/trunk/agent/
Log:
target ignores
Property changes on: modules/authorization/trunk/agent
___________________________________________________________________
Name: svn:ignore
+ target
16 years, 10 months
JBoss Portal SVN: r13461 - in modules/authorization/trunk: agent and 27 other directories.
by portal-commits@lists.jboss.org
Author: sohil.shah(a)jboss.com
Date: 2009-06-16 12:47:34 -0400 (Tue, 16 Jun 2009)
New Revision: 13461
Added:
modules/authorization/trunk/agent/
modules/authorization/trunk/agent/pom.xml
modules/authorization/trunk/agent/src/
modules/authorization/trunk/agent/src/main/
modules/authorization/trunk/agent/src/main/java/
modules/authorization/trunk/agent/src/main/java/org/
modules/authorization/trunk/agent/src/main/java/org/jboss/
modules/authorization/trunk/agent/src/main/java/org/jboss/security/
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/ComponentRepository.java
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/PolicyComposer.java
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposer.java
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposition.java
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleDeclarationRepository.java
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/TargetComposition.java
modules/authorization/trunk/agent/src/main/resources/
modules/authorization/trunk/agent/src/main/resources/META-INF/
modules/authorization/trunk/agent/src/main/resources/authz-components.xml
modules/authorization/trunk/agent/src/test/
modules/authorization/trunk/agent/src/test/java/
modules/authorization/trunk/agent/src/test/java/org/
modules/authorization/trunk/agent/src/test/java/org/jboss/
modules/authorization/trunk/agent/src/test/java/org/jboss/security/
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/test/
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/test/MockPolicy.java
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/test/NoPermitMeansDeniedAlg.java
modules/authorization/trunk/agent/src/test/resources/
modules/authorization/trunk/agent/src/test/resources/log4j.properties
Removed:
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/agent/
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentRepository.java
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/PolicyComposer.java
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposer.java
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposition.java
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleDeclarationRepository.java
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/TargetComposition.java
modules/authorization/trunk/core-components-api/src/main/resources/META-INF/
modules/authorization/trunk/core-components-api/src/main/resources/authz-components.xml
modules/authorization/trunk/core-components-api/src/test/java/org/jboss/security/authz/components/repository/
Modified:
modules/authorization/trunk/.classpath
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestConfiguration.java
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestPolicyComposition.java
modules/authorization/trunk/common-api/pom.xml
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentCategory.java
modules/authorization/trunk/core-components-api/pom.xml
modules/authorization/trunk/pom.xml
Log:
refactoring
Modified: modules/authorization/trunk/.classpath
===================================================================
--- modules/authorization/trunk/.classpath 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/.classpath 2009-06-16 16:47:34 UTC (rev 13461)
@@ -7,7 +7,11 @@
<classpathentry kind="src" path="core-components-api/src/main/java"/>
<classpathentry kind="src" path="core-components-api/src/main/resources"/>
<classpathentry kind="src" path="core-components-api/src/test/java"/>
- <classpathentry kind="src" path="core-components-api/src/test/resources"/>
+ <classpathentry kind="src" path="core-components-api/src/test/resources"/>
+ <classpathentry kind="src" path="agent/src/main/java"/>
+ <classpathentry kind="src" path="agent/src/main/resources"/>
+ <classpathentry kind="src" path="agent/src/test/java"/>
+ <classpathentry kind="src" path="agent/src/test/resources"/>
<classpathentry kind="src" path="policy-server/src/main/java"/>
<classpathentry kind="src" path="policy-server/src/main/resources"/>
<classpathentry kind="src" path="policy-server/src/test/java"/>
Added: modules/authorization/trunk/agent/pom.xml
===================================================================
--- modules/authorization/trunk/agent/pom.xml (rev 0)
+++ modules/authorization/trunk/agent/pom.xml 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,38 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.security.authz</groupId>
+ <artifactId>jboss-authz-parent</artifactId>
+ <version>trunk-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>agent</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Authorization Client Side Agent</name>
+ <url>http://www.jboss.org</url>
+ <description>Represents the Agent that lives on the Client Side along with the Application being secured</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.security.authz</groupId>
+ <artifactId>common-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.security.authz</groupId>
+ <artifactId>core-components-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- jboss microcontainer -->
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </dependency>
+ <!-- jboss xacml -->
+ <dependency>
+ <groupId>org.jboss.security</groupId>
+ <artifactId>jboss-xacml</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Copied: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent (from rev 13459, modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/agent)
Property changes on: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/ComponentRepository.java (from rev 13459, modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentRepository.java)
===================================================================
--- modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/ComponentRepository.java (rev 0)
+++ modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/ComponentRepository.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,64 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.security.authz.agent.services;
+
+import java.util.Map;
+
+import org.jboss.security.authz.component.Component;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class ComponentRepository
+{
+ private Map<String, Component> registeredComponents;
+
+ public ComponentRepository()
+ {
+
+ }
+
+ public void start()
+ {
+
+ }
+
+ public void stop()
+ {
+
+ }
+ //-----------Repository Access related services----------------------------------------------------------------------------------------------------------------------------------------------------------
+ public void register(String name, Component component)
+ {
+ this.registeredComponents.put(name, component);
+ }
+
+ public Component getComponent(String name)
+ {
+ return this.registeredComponents.get(name);
+ }
+
+ public void unregister(String name)
+ {
+ this.registeredComponents.remove(name);
+ }
+}
Property changes on: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/ComponentRepository.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/PolicyComposer.java (from rev 13459, modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/PolicyComposer.java)
===================================================================
--- modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/PolicyComposer.java (rev 0)
+++ modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/PolicyComposer.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,30 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.security.authz.agent.services;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class PolicyComposer
+{
+
+}
Property changes on: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/PolicyComposer.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposer.java (from rev 13459, modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposer.java)
===================================================================
--- modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposer.java (rev 0)
+++ modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposer.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,30 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.security.authz.agent.services;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class RuleComposer
+{
+
+}
Property changes on: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposer.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposition.java (from rev 13459, modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposition.java)
===================================================================
--- modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposition.java (rev 0)
+++ modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposition.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,210 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.security.authz.agent.services;
+
+import java.lang.reflect.Method;
+import java.lang.annotation.Annotation;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.apache.log4j.Logger;
+
+import org.jboss.security.authz.component.LogicExpression;
+import org.jboss.security.authz.model.Rule;
+import org.jboss.security.authz.model.Expression;
+import org.jboss.security.authz.model.Effect;
+import org.jboss.security.authz.model.Target;
+import org.jboss.security.authz.model.DroolsRuleExpression;
+import org.jboss.security.authz.tools.GeneralTool;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class RuleComposition
+{
+ private static Logger log = Logger.getLogger(RuleComposition.class);
+
+ private Object targetComponent;
+ private Object logicComponent;
+ private String expressionName;
+ private Effect effect;
+
+ public RuleComposition()
+ {
+
+ }
+
+ public Object getTargetComponent()
+ {
+ return targetComponent;
+ }
+
+ public void setTargetComponent(Object targetComponent)
+ {
+ this.targetComponent = targetComponent;
+ }
+
+ public Object getLogicComponent()
+ {
+ return logicComponent;
+ }
+
+ public void setLogicComponent(Object logicComponent)
+ {
+ this.logicComponent = logicComponent;
+ }
+
+ public Effect getEffect()
+ {
+ return effect;
+ }
+
+ public void setEffect(Effect effect)
+ {
+ this.effect = effect;
+ }
+
+ public String getExpressionName()
+ {
+ return expressionName;
+ }
+
+ public void setExpressionName(String expressionName)
+ {
+ this.expressionName = expressionName;
+ }
+ //----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ public Set<Rule> compose()
+ {
+ if(this.effect == null)
+ {
+ throw new IllegalStateException("Effect is missing!!");
+ }
+
+ if(this.expressionName != null)
+ {
+ if(this.logicComponent == null)
+ {
+ throw new IllegalStateException("Logic Component is missing!!");
+ }
+ }
+
+ try
+ {
+ Set<Rule> rules = new HashSet<Rule>();
+
+ Rule rule = new Rule();
+
+ rule.setRuleId(GeneralTool.generateUniqueId());
+ rule.setEffect(this.effect);
+
+ //Generate the Target for this rule
+ Set<Target> impliedActions = new HashSet<Target>();
+ if(this.targetComponent != null)
+ {
+ TargetComposition targetComposition = new TargetComposition();
+ targetComposition.setTargetComponent(this.targetComponent);
+ rule.setTarget(targetComposition.compose());
+
+ Set<Target> cour = targetComposition.composeImpliedTargets();
+ if(cour != null && !cour.isEmpty())
+ {
+ impliedActions.addAll(cour);
+ }
+ }
+
+ //Generate the Logic Expression of this rule
+ if(this.expressionName != null)
+ {
+ rule.setExpression(this.generateExpression());
+ }
+
+ rules.add(rule);
+
+ //Add any implied actions
+ if(impliedActions != null && !impliedActions.isEmpty())
+ {
+ for(Target impliedAction: impliedActions)
+ {
+ Rule impliedRule = new Rule();
+
+ impliedRule.setRuleId(GeneralTool.generateUniqueId());
+ impliedRule.setEffect(rule.getEffect());
+ impliedRule.setExpression(rule.getExpression());
+ impliedRule.setTarget(impliedAction);
+
+ rules.add(impliedRule);
+ }
+ }
+
+ return rules;
+ }
+ catch(Exception e)
+ {
+ //TODO: handle this properly
+ log.error(this, e);
+ throw new RuntimeException(e);
+ }
+ }
+ //----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ private Expression generateExpression() throws Exception
+ {
+ DroolsRuleExpression expression = new DroolsRuleExpression();
+
+ //Read the LogicExpression of the Logic Component
+ Method expressionMethod = this.findExpression(this.logicComponent.getClass(), this.expressionName);
+ expressionMethod.setAccessible(true);
+
+ String[] expressionMetaData = (String[])expressionMethod.invoke(this.logicComponent, null);
+
+ expression.setRuleReference(expressionMetaData[0]);
+ expression.setRule(expressionMetaData[1]);
+
+ return expression;
+ }
+
+ private Method findExpression(Class targetClass, String expressionName)
+ {
+ Method[] declaredMethods = targetClass.getDeclaredMethods();
+ if(declaredMethods != null)
+ {
+ for(Method declaredMethod: declaredMethods)
+ {
+ Annotation logicExpression = declaredMethod.getAnnotation(LogicExpression.class);
+ if(logicExpression != null)
+ {
+ if(declaredMethod.getName().equals(expressionName))
+ {
+ return declaredMethod;
+ }
+ }
+ }
+ }
+
+ if(targetClass.getSuperclass() != null)
+ {
+ return this.findExpression(targetClass.getSuperclass(), expressionName);
+ }
+
+ return null;
+ }
+}
Property changes on: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposition.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleDeclarationRepository.java (from rev 13459, modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleDeclarationRepository.java)
===================================================================
--- modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleDeclarationRepository.java (rev 0)
+++ modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleDeclarationRepository.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,65 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.security.authz.agent.services;
+
+import java.util.Set;
+import java.util.HashSet;
+
+import org.apache.log4j.Logger;
+import org.jboss.security.authz.component.ComponentMarker;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class RuleDeclarationRepository
+{
+ private static Logger log = Logger.getLogger(RuleDeclarationRepository.class);
+
+ private Set<ComponentMarker> components;
+
+ public RuleDeclarationRepository()
+ {
+ }
+
+ public void start()
+ {
+ this.components = new HashSet<ComponentMarker>();
+ log.info("-------------------------------------------------------------------");
+ log.info("RuleDeclarationRepository successfully started.....................");
+ log.info("-------------------------------------------------------------------");
+ }
+
+ public void stop()
+ {
+
+ }
+
+ public void register(ComponentMarker component)
+ {
+ this.components.add(component);
+
+ log.debug("--------------------------------------------------------------");
+ log.debug(component.getClass()+" was successfully registered.............");
+ log.debug("--------------------------------------------------------------");
+ }
+ //---------------------------------------------------------------------------------------------------------------------------------------------------------------
+}
Property changes on: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleDeclarationRepository.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/TargetComposition.java (from rev 13459, modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/TargetComposition.java)
===================================================================
--- modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/TargetComposition.java (rev 0)
+++ modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/TargetComposition.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,222 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.security.authz.agent.services;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.apache.log4j.Logger;
+
+import org.jboss.security.authz.component.Component;
+import org.jboss.security.authz.component.ComponentCategory;
+import org.jboss.security.authz.component.ImpliedActions;
+import org.jboss.security.authz.component.TargetUri;
+import org.jboss.security.authz.model.Target;
+import org.jboss.security.authz.model.Attribute;
+import org.jboss.security.authz.model.AttributeExpression;
+import org.jboss.security.xacml.interfaces.XACMLConstants;
+import org.jboss.security.xacml.interfaces.XMLSchemaConstants;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class TargetComposition
+{
+ private static Logger log = Logger.getLogger(TargetComposition.class);
+
+ private Object targetComponent;
+
+ public TargetComposition()
+ {
+
+ }
+
+ public Object getTargetComponent()
+ {
+ return targetComponent;
+ }
+
+ public void setTargetComponent(Object targetComponent)
+ {
+ this.targetComponent = targetComponent;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ public Target compose()
+ {
+ if(this.targetComponent == null)
+ {
+ throw new IllegalStateException("Target Component is null!!");
+ }
+
+ try
+ {
+ Target mainTarget = this.generateTarget();
+ return mainTarget;
+ }
+ catch(Exception e)
+ {
+ //TODO: handle this properly
+ log.error(this, e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Set<Target> composeImpliedTargets()
+ {
+ try
+ {
+ Set<Target> impliedTargets = new HashSet<Target>();
+
+ String[] impliedActions = this.findImpliedActions(this.targetComponent.getClass());
+ if(impliedActions != null)
+ {
+ for(String impliedAction: impliedActions)
+ {
+ //TODO: Find the Action Component from the repository
+ Object impliedActionComponent = null;
+ if(impliedAction.equals("read"))
+ {
+ impliedActionComponent = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.authz.components.action.Read").newInstance();
+ }
+ else if(impliedAction.equals("write"))
+ {
+ impliedActionComponent = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.authz.components.action.Write").newInstance();
+ }
+
+ //Compose this action target
+ TargetComposition comp = new TargetComposition();
+ comp.setTargetComponent(impliedActionComponent);
+ impliedTargets.add(comp.compose());
+ }
+ }
+
+ return impliedTargets;
+ }
+ catch(Exception e)
+ {
+ //TODO: handle this properly
+ log.error(this, e);
+ throw new RuntimeException(e);
+ }
+ }
+ //----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ private Target generateTarget() throws Exception
+ {
+ Target target = new Target();
+
+ //Read the TargetUri
+ Field targetField = this.findTargetField(this.targetComponent.getClass());
+ targetField.setAccessible(true);
+ Object targetUriObj = targetField.get(this.targetComponent);
+
+ //Get a String representation of this URI
+ String uriStr = targetUriObj.toString();
+
+ //use the proper category for the data
+ ComponentCategory category = this.findComponentCategory(this.targetComponent.getClass());
+ String attributeCategory = category.getAttributeCategory();
+
+ AttributeExpression urlExpression = new AttributeExpression();
+ if (uriStr.charAt(0) == '/' && uriStr.endsWith("/*"))
+ {
+ // If URL starts with '/' and ends with "/*", use a regular
+ // expression to match it (In consistency with the servlet spec)
+ urlExpression
+ .setFunctionId(XACMLConstants.FUNCTION_REGEXP_STRING_MATCH);
+
+ String uriexp = uriStr.substring(1, uriStr.length() - 2);
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("^/" + uriexp + "$|");
+ buffer.append("^" + uriexp + "$|");
+ buffer.append("^/" + uriexp + "/.*|");
+ buffer.append("^" + uriexp + "/.*");
+
+ Attribute attribute = new Attribute(
+ attributeCategory,
+ XMLSchemaConstants.DATATYPE_STRING, buffer.toString());
+ urlExpression.setAttribute(attribute);
+ }
+ else
+ {
+ // use an exact match
+ urlExpression.setFunctionId(XACMLConstants.FUNCTION_STRING_EQUAL);
+
+ Attribute attribute = new Attribute(
+ attributeCategory,
+ XMLSchemaConstants.DATATYPE_STRING, uriStr);
+ urlExpression.setAttribute(attribute);
+ }
+
+ //Depending up the data category add the appropriate match expression
+ category.setExpression(target, urlExpression);
+
+ return target;
+ }
+
+ private ComponentCategory findComponentCategory(Class targetClass)
+ {
+ Annotation component = targetClass.getAnnotation(Component.class);
+ if(component != null)
+ {
+ return ((Component)component).category();
+ }
+
+ return null;
+ }
+
+ private String[] findImpliedActions(Class targetClass)
+ {
+ Annotation impliedActions = targetClass.getAnnotation(ImpliedActions.class);
+ if(impliedActions != null)
+ {
+ return ((ImpliedActions)impliedActions).value();
+ }
+
+ return null;
+ }
+
+ private Field findTargetField(Class targetClass)
+ {
+ Field[] declaredFields = targetClass.getDeclaredFields();
+ if(declaredFields != null)
+ {
+ for(Field declaredField: declaredFields)
+ {
+ Annotation targetUri = declaredField.getAnnotation(TargetUri.class);
+ if(targetUri != null)
+ {
+ return declaredField;
+ }
+ }
+ }
+
+ //If I get here, query the super class
+ if(targetClass.getSuperclass() != null)
+ {
+ return this.findTargetField(targetClass.getSuperclass());
+ }
+
+ return null;
+ }
+}
Property changes on: modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/TargetComposition.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: modules/authorization/trunk/agent/src/main/resources/META-INF (from rev 13459, modules/authorization/trunk/core-components-api/src/main/resources/META-INF)
Property changes on: modules/authorization/trunk/agent/src/main/resources/META-INF
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: modules/authorization/trunk/agent/src/main/resources/authz-components.xml (from rev 13459, modules/authorization/trunk/core-components-api/src/main/resources/authz-components.xml)
===================================================================
--- modules/authorization/trunk/agent/src/main/resources/authz-components.xml (rev 0)
+++ modules/authorization/trunk/agent/src/main/resources/authz-components.xml 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components>
+ <!--
+ TODO: Just for prototyping the Component Contract. Eventually the method of configuration will be POJO components with Annotations
+ -->
+ <target-component name="uri" category="resource" class="org.jboss.security.authz.components.resource.URIResource">
+ <target-uri>uniqueUri</target-uri>
+ </target-component>
+
+ <target-component name="operation" category="action" class="org.jboss.security.authz.components.action.Operation">
+ <target-uri>name</target-uri>
+ </target-component>
+
+ <target-component name="read" category="action" class="org.jboss.security.authz.components.action.Read">
+ <target-uri>name</target-uri>
+ </target-component>
+
+ <target-component name="write" category="action" class="org.jboss.security.authz.components.action.Write">
+ <target-uri>name</target-uri>
+ </target-component>
+
+ <target-component name="manage" category="action" class="org.jboss.security.authz.components.action.Manage">
+ <target-uri>name</target-uri>
+ </target-component>
+
+ <logic-component name="identity" category="subject" class="org.jboss.security.authz.components.subject.Identity">
+ <target-uri>uri</target-uri>
+ <logic-data>
+ <data>name</data>
+ </logic-data>
+ </logic-component>
+
+ <logic-component name="roles" category="subject" class="org.jboss.security.authz.components.subject.Roles">
+ <target-uri></target-uri>
+ <logic-data>
+ <data>names</data>
+ </logic-data>
+ <logic-expressions>
+ <expression>allowExpression</expression>
+ <expression>denyExpression</expression>
+ </logic-expressions>
+ </logic-component>
+
+
+ <!--
+ Core Rule Compositions shipped with the framework. These can be re-used and more compositions can be added
+ depending upon Application/Profile Requirements
+ -->
+ <rule-composition name="permitIdentity" outcome="permit">
+ <target-component>identity</target-component>
+ </rule-composition>
+
+ <rule-composition name="denyIdentity" outcome="deny">
+ <target-component>identity</target-component>
+ </rule-composition>
+
+ <rule-composition name="permitRole" outcome="permit">
+ <target-component>operation</target-component>
+ <logic-component expression="allowExpression">roles</logic-component>
+ </rule-composition>
+
+ <rule-composition name="denyRole" outcome="deny">
+ <target-component>operation</target-component>
+ <logic-component expression="denyExpression">roles</logic-component>
+ </rule-composition>
+</components>
\ No newline at end of file
Property changes on: modules/authorization/trunk/agent/src/main/resources/authz-components.xml
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services (from rev 13459, modules/authorization/trunk/core-components-api/src/test/java/org/jboss/security/authz/components/repository)
Property changes on: modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestConfiguration.java
===================================================================
--- modules/authorization/trunk/core-components-api/src/test/java/org/jboss/security/authz/components/repository/TestConfiguration.java 2009-06-16 11:32:25 UTC (rev 13459)
+++ modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestConfiguration.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-package org.jboss.security.authz.components.repository;
+package org.jboss.security.authz.agent.services;
import java.io.InputStream;
@@ -28,8 +28,8 @@
import org.apache.log4j.Logger;
import org.jboss.security.authz.tools.GeneralTool;
-import org.jboss.security.authz.component.ComponentRepository;
import org.jboss.security.authz.agent.Agent;
+import org.jboss.security.authz.agent.services.ComponentRepository;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
Modified: modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestPolicyComposition.java
===================================================================
--- modules/authorization/trunk/core-components-api/src/test/java/org/jboss/security/authz/components/repository/TestPolicyComposition.java 2009-06-16 11:32:25 UTC (rev 13459)
+++ modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestPolicyComposition.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-package org.jboss.security.authz.components.repository;
+package org.jboss.security.authz.agent.services;
import java.util.Set;
import java.util.HashSet;
@@ -35,15 +35,15 @@
import org.jboss.security.authz.model.Target;
import org.jboss.security.authz.model.Rule;
+import org.jboss.security.authz.agent.services.RuleComposition;
+import org.jboss.security.authz.agent.services.TargetComposition;
import org.jboss.security.authz.components.subject.Identity;
import org.jboss.security.authz.components.subject.Roles;
import org.jboss.security.authz.components.action.Read;
import org.jboss.security.authz.components.action.Manage;
import org.jboss.security.authz.components.resource.URIResource;
-import org.jboss.security.authz.component.RuleComposition;
-import org.jboss.security.authz.component.TargetComposition;
-import org.jboss.security.authz.test.MockPolicy;
+import org.jboss.security.authz.agent.test.MockPolicy;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
Added: modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/test/MockPolicy.java
===================================================================
--- modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/test/MockPolicy.java (rev 0)
+++ modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/test/MockPolicy.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,276 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.security.authz.agent.test;
+
+import java.util.List;
+import java.util.Set;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.UUID;
+
+import javax.xml.bind.JAXBElement;
+
+import org.jboss.security.authz.model.Policy;
+import org.jboss.security.authz.model.PolicyMetaData;
+import org.jboss.security.authz.model.Rule;
+import org.jboss.security.authz.model.Effect;
+import org.jboss.security.authz.model.PolicyException;
+import org.jboss.security.authz.model.AttributeExpression;
+import org.jboss.security.authz.model.DroolsRuleExpression;
+import org.jboss.security.authz.model.Expression;
+import org.jboss.security.authz.xacml.AttributeDesignatorUtil;
+import org.jboss.security.authz.xacml.PolicyUtil;
+
+import org.jboss.security.xacml.core.model.policy.ActionMatchType;
+import org.jboss.security.xacml.core.model.policy.SubjectMatchType;
+import org.jboss.security.xacml.core.model.policy.ApplyType;
+import org.jboss.security.xacml.core.model.policy.VariableReferenceType;
+import org.jboss.security.xacml.core.model.policy.EffectType;
+import org.jboss.security.xacml.core.model.policy.PolicyType;
+import org.jboss.security.xacml.core.model.policy.ResourceMatchType;
+import org.jboss.security.xacml.core.model.policy.ResourcesType;
+import org.jboss.security.xacml.core.model.policy.ResourceType;
+import org.jboss.security.xacml.core.model.policy.ActionsType;
+import org.jboss.security.xacml.core.model.policy.ActionType;
+import org.jboss.security.xacml.core.model.policy.SubjectsType;
+import org.jboss.security.xacml.core.model.policy.SubjectType;
+import org.jboss.security.xacml.core.model.policy.RuleType;
+import org.jboss.security.xacml.core.model.policy.TargetType;
+import org.jboss.security.xacml.core.model.policy.ConditionType;
+import org.jboss.security.xacml.core.model.policy.ObjectFactory;
+import org.jboss.security.xacml.core.model.policy.AttributeValueType;
+import org.jboss.security.xacml.core.model.policy.SubjectAttributeDesignatorType;
+import org.jboss.security.xacml.factories.PolicyAttributeFactory;
+
+/**
+ * Used for specifying policies for Resources represented by unique URIs, sometimes forming a tree like relationship with other Resources in the system
+ *
+ * An example of such resources would be tree of resources/nodes in a Content Management System
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class MockPolicy extends Policy
+{
+
+ public MockPolicy(String policyUri, PolicyMetaData metaData) throws PolicyException
+ {
+ super(policyUri, metaData);
+ }
+
+
+ @Override
+ public String generateSystemPolicy() throws PolicyException
+ {
+ ByteArrayOutputStream bos = null;
+ try
+ {
+ String xacmlXml = null;
+
+ //SetUp the Policy Header
+ ObjectFactory objectFactory = new ObjectFactory();
+ PolicyType policyType = new PolicyType();
+ policyType.setPolicyId(this.policyUri);
+ policyType.setVersion("2.0");
+ policyType.setRuleCombiningAlgId(new NoPermitMeansDeniedAlg().getIdentifier().toString());
+
+ TargetType targetType = new TargetType();
+ policyType.setTarget(targetType);
+
+ //Process Resource Matches as Targets for the Policy
+ List<AttributeExpression> resourceMatches = this.metaData.getTarget().getResourceMatches();
+ if(resourceMatches != null && !resourceMatches.isEmpty())
+ {
+ ResourcesType resourcesType = new ResourcesType();
+ targetType.setResources(resourcesType);
+ ResourceType resourceType = new ResourceType();
+
+ for(AttributeExpression resourceMatch: resourceMatches)
+ {
+ ResourceMatchType rmt = new ResourceMatchType();
+
+ rmt.setMatchId(resourceMatch.getFunctionId());
+ rmt.setResourceAttributeDesignator(AttributeDesignatorUtil.getAttributeDesignator(resourceMatch.getAttribute(), true));
+ rmt.setAttributeValue(PolicyAttributeFactory
+ .createStringAttributeType(resourceMatch.getAttribute().getValue()));
+
+ resourceType.getResourceMatch().add(rmt);
+ }
+
+ resourcesType.getResource().add(resourceType);
+ }
+
+ //Process the Policy Rules
+ Set<Rule> rules = this.metaData.getRules();
+ if(rules != null && !rules.isEmpty())
+ {
+ for(Rule rule: rules)
+ {
+ RuleType ruleType = new RuleType();
+ ruleType.setRuleId(rule.getRuleId());
+ if(rule.getEffect() == Effect.PERMIT)
+ {
+ ruleType.setEffect(EffectType.PERMIT);
+ }
+ else
+ {
+ ruleType.setEffect(EffectType.DENY);
+ }
+
+ //Process the Rule Target
+ if(rule.getTarget() != null)
+ {
+ List<AttributeExpression> actionMatches = rule.getTarget().getActionMatches();
+ List<AttributeExpression> subjectMatches = rule.getTarget().getSubjectMatches();
+ TargetType ruleTarget = new TargetType();
+
+ if(actionMatches != null && !actionMatches.isEmpty())
+ {
+ ruleTarget.setActions(this.generateRuleActions(actionMatches));
+ }
+
+ if(subjectMatches != null && !subjectMatches.isEmpty())
+ {
+ ruleTarget.setSubjects(this.generateRuleSubjects(subjectMatches));
+ }
+
+ ruleType.setTarget(ruleTarget);
+ }
+
+ //Process the Rule Expression/Condition
+ ConditionType condition = this.generateCondition(objectFactory, rule.getExpression());
+ ruleType.setCondition(condition);
+
+ policyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(ruleType);
+ }
+ }
+
+ bos = new ByteArrayOutputStream();
+ PolicyUtil.marshall(bos, policyType);
+ xacmlXml = new String(bos.toByteArray());
+
+ return xacmlXml;
+ }
+ catch(Exception e)
+ {
+ throw new PolicyException(e);
+ }
+ finally
+ {
+ if(bos != null)
+ {
+ try{bos.close();}catch(IOException ioe){}
+ }
+ }
+ }
+
+ private ActionsType generateRuleActions(List<AttributeExpression> actionMatches)
+ {
+ ActionsType actions = new ActionsType();
+
+ for(AttributeExpression action: actionMatches)
+ {
+ ActionType actionType = new ActionType();
+ ActionMatchType amct = new ActionMatchType();
+ amct.setMatchId(action.getFunctionId());
+ amct.setAttributeValue(PolicyAttributeFactory.createStringAttributeType(action.getAttribute().getValue()));
+ amct.setActionAttributeDesignator(AttributeDesignatorUtil.getAttributeDesignator(action.getAttribute(), true));
+ actionType.getActionMatch().add(amct);
+ actions.getAction().add(actionType);
+ }
+
+ return actions;
+ }
+
+ private SubjectsType generateRuleSubjects(List<AttributeExpression> subjectMatches)
+ {
+ SubjectsType subjects = new SubjectsType();
+
+ for(AttributeExpression subject: subjectMatches)
+ {
+ SubjectType subjectType = new SubjectType();
+ SubjectMatchType match = new SubjectMatchType();
+ match.setMatchId(subject.getFunctionId());
+ match.setAttributeValue(PolicyAttributeFactory.createStringAttributeType(subject.getAttribute().getValue()));
+ match.setSubjectAttributeDesignator((SubjectAttributeDesignatorType)AttributeDesignatorUtil.getAttributeDesignator(subject.getAttribute(), true));
+ subjectType.getSubjectMatch().add(match);
+ subjects.getSubject().add(subjectType);
+ }
+
+ return subjects;
+ }
+
+ /**
+ *
+ * @param expression
+ * @return
+ */
+ private ConditionType generateCondition(ObjectFactory objectFactory, Expression expression)
+ {
+ ConditionType condition = new ConditionType();
+
+ if(expression instanceof AttributeExpression)
+ {
+ AttributeExpression attributeExpression = (AttributeExpression)expression;
+
+ //Function to be applied
+ ApplyType apply = new ApplyType();
+ apply.setFunctionId(attributeExpression.getFunctionId());
+
+ //Value to check against
+ AttributeValueType attrValue = PolicyAttributeFactory.createStringAttributeType(attributeExpression.getAttribute().getValue());
+ JAXBElement<AttributeValueType> jaxbAttrValue = objectFactory.createAttributeValue(attrValue);
+ apply.getExpression().add(jaxbAttrValue);
+
+ //Place within the Context where this Value should exist during an Authorization Request
+ apply.getExpression().add(AttributeDesignatorUtil.getAttributeDesignatorXml(attributeExpression.getAttribute(), true));
+
+
+ condition.setExpression(objectFactory.createApply(apply));
+ }
+ else if(expression instanceof DroolsRuleExpression)
+ {
+ DroolsRuleExpression ruleExpression = (DroolsRuleExpression)expression;
+
+ //Function to be applied
+ ApplyType apply = new ApplyType();
+ apply.setFunctionId(ruleExpression.getFunctionId());
+
+
+ VariableReferenceType ruleReference = new VariableReferenceType();
+ ruleReference.setVariableId(ruleExpression.getRuleReference());
+ JAXBElement<VariableReferenceType> jaxbRuleReference = objectFactory.createVariableReference(ruleReference);
+ apply.getExpression().add(jaxbRuleReference);
+
+
+ condition.setExpression(objectFactory.createApply(apply));
+ }
+
+ return condition;
+ }
+
+ private String generateUniqueId()
+ {
+ return UUID.randomUUID().toString();
+ }
+}
Added: modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/test/NoPermitMeansDeniedAlg.java
===================================================================
--- modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/test/NoPermitMeansDeniedAlg.java (rev 0)
+++ modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/test/NoPermitMeansDeniedAlg.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,83 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.security.authz.agent.test;
+
+import java.util.List;
+import java.util.Iterator;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.security.xacml.sunxacml.combine.RuleCombiningAlgorithm;
+import org.jboss.security.xacml.sunxacml.EvaluationCtx;
+import org.jboss.security.xacml.sunxacml.ctx.Result;
+import org.jboss.security.xacml.sunxacml.Rule;
+import org.jboss.security.xacml.sunxacml.combine.RuleCombinerElement;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class NoPermitMeansDeniedAlg extends RuleCombiningAlgorithm
+{
+ /**
+ *
+ * @throws URISyntaxException
+ */
+ public NoPermitMeansDeniedAlg() throws URISyntaxException
+ {
+ super(new URI("rule-combining-alg:nopermit-means-denied"));
+ }
+
+ /**
+ *
+ * @param context
+ * @param rules
+ * @return
+ */
+ public Result combine(EvaluationCtx context, List parameters, List ruleElements)
+ {
+ Result result = new Result(Result.DECISION_PERMIT);
+
+ Iterator rules = ruleElements.iterator();
+ boolean permitFound = false;
+ while(rules.hasNext())
+ {
+ RuleCombinerElement ruleCombinerElement = (RuleCombinerElement)rules.next();
+ Rule rule = ruleCombinerElement.getRule();
+ Result currentResult = rule.evaluate(context);
+
+ if(currentResult.getDecision() == Result.DECISION_PERMIT)
+ {
+ permitFound = true;
+ break;
+ }
+ }
+
+ if(!permitFound)
+ {
+ result = new Result(Result.DECISION_DENY);
+ }
+
+ return result;
+ }
+}
Added: modules/authorization/trunk/agent/src/test/resources/log4j.properties
===================================================================
--- modules/authorization/trunk/agent/src/test/resources/log4j.properties (rev 0)
+++ modules/authorization/trunk/agent/src/test/resources/log4j.properties 2009-06-16 16:47:34 UTC (rev 13461)
@@ -0,0 +1,8 @@
+# Set root category priority to INFO and its only appender to CONSOLE.
+log4j.rootCategory=DEBUG, CONSOLE
+
+# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
+log4j.appender.CONSOLE.Threshold=DEBUG
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
Modified: modules/authorization/trunk/common-api/pom.xml
===================================================================
--- modules/authorization/trunk/common-api/pom.xml 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/common-api/pom.xml 2009-06-16 16:47:34 UTC (rev 13461)
@@ -18,12 +18,6 @@
<dependency>
<groupId>org.jboss.security</groupId>
<artifactId>jboss-xacml</artifactId>
- </dependency>
-
- <!-- jboss microcontainer -->
- <dependency>
- <groupId>org.jboss.microcontainer</groupId>
- <artifactId>jboss-kernel</artifactId>
- </dependency>
+ </dependency>
</dependencies>
</project>
Modified: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentCategory.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentCategory.java 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentCategory.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -32,12 +32,12 @@
{
RESOURCE
{
- String getAttributeCategory()
+ public String getAttributeCategory()
{
return XACMLConstants.ATTRIBUTEID_RESOURCE_ID;
}
- void setExpression(Target target,AttributeExpression expression)
+ public void setExpression(Target target,AttributeExpression expression)
{
target.addResourceMatch(expression);
}
@@ -46,12 +46,12 @@
SUBJECT
{
- String getAttributeCategory()
+ public String getAttributeCategory()
{
return XACMLConstants.ATTRIBUTEID_SUBJECT_ID;
}
- void setExpression(Target target, AttributeExpression expression)
+ public void setExpression(Target target, AttributeExpression expression)
{
target.addSubjectMatch(expression);
}
@@ -60,18 +60,18 @@
ACTION
{
- String getAttributeCategory()
+ public String getAttributeCategory()
{
return XACMLConstants.ATTRIBUTEID_ACTION_ID;
}
- void setExpression(Target target, AttributeExpression expression)
+ public void setExpression(Target target, AttributeExpression expression)
{
target.addActionMatch(expression);
}
};
//Define the enum behavior
- abstract String getAttributeCategory();
- abstract void setExpression(Target target, AttributeExpression expression);
+ public abstract String getAttributeCategory();
+ public abstract void setExpression(Target target, AttributeExpression expression);
}
Deleted: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentRepository.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentRepository.java 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentRepository.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -1,62 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security.authz.component;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class ComponentRepository
-{
- private Map<String, Component> registeredComponents;
-
- public ComponentRepository()
- {
-
- }
-
- public void start()
- {
-
- }
-
- public void stop()
- {
-
- }
- //-----------Repository Access related services----------------------------------------------------------------------------------------------------------------------------------------------------------
- public void register(String name, Component component)
- {
- this.registeredComponents.put(name, component);
- }
-
- public Component getComponent(String name)
- {
- return this.registeredComponents.get(name);
- }
-
- public void unregister(String name)
- {
- this.registeredComponents.remove(name);
- }
-}
Deleted: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/PolicyComposer.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/PolicyComposer.java 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/PolicyComposer.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -1,30 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security.authz.component;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class PolicyComposer
-{
-
-}
Deleted: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposer.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposer.java 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposer.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -1,30 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security.authz.component;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class RuleComposer
-{
-
-}
Deleted: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposition.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposition.java 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposition.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -1,209 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security.authz.component;
-
-import java.lang.reflect.Method;
-import java.lang.annotation.Annotation;
-import java.util.Set;
-import java.util.HashSet;
-
-import org.apache.log4j.Logger;
-
-import org.jboss.security.authz.model.Rule;
-import org.jboss.security.authz.model.Expression;
-import org.jboss.security.authz.model.Effect;
-import org.jboss.security.authz.model.Target;
-import org.jboss.security.authz.model.DroolsRuleExpression;
-import org.jboss.security.authz.tools.GeneralTool;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class RuleComposition
-{
- private static Logger log = Logger.getLogger(RuleComposition.class);
-
- private Object targetComponent;
- private Object logicComponent;
- private String expressionName;
- private Effect effect;
-
- public RuleComposition()
- {
-
- }
-
- public Object getTargetComponent()
- {
- return targetComponent;
- }
-
- public void setTargetComponent(Object targetComponent)
- {
- this.targetComponent = targetComponent;
- }
-
- public Object getLogicComponent()
- {
- return logicComponent;
- }
-
- public void setLogicComponent(Object logicComponent)
- {
- this.logicComponent = logicComponent;
- }
-
- public Effect getEffect()
- {
- return effect;
- }
-
- public void setEffect(Effect effect)
- {
- this.effect = effect;
- }
-
- public String getExpressionName()
- {
- return expressionName;
- }
-
- public void setExpressionName(String expressionName)
- {
- this.expressionName = expressionName;
- }
- //----------------------------------------------------------------------------------------------------------------------------------------------------------------
- public Set<Rule> compose()
- {
- if(this.effect == null)
- {
- throw new IllegalStateException("Effect is missing!!");
- }
-
- if(this.expressionName != null)
- {
- if(this.logicComponent == null)
- {
- throw new IllegalStateException("Logic Component is missing!!");
- }
- }
-
- try
- {
- Set<Rule> rules = new HashSet<Rule>();
-
- Rule rule = new Rule();
-
- rule.setRuleId(GeneralTool.generateUniqueId());
- rule.setEffect(this.effect);
-
- //Generate the Target for this rule
- Set<Target> impliedActions = new HashSet<Target>();
- if(this.targetComponent != null)
- {
- TargetComposition targetComposition = new TargetComposition();
- targetComposition.setTargetComponent(this.targetComponent);
- rule.setTarget(targetComposition.compose());
-
- Set<Target> cour = targetComposition.composeImpliedTargets();
- if(cour != null && !cour.isEmpty())
- {
- impliedActions.addAll(cour);
- }
- }
-
- //Generate the Logic Expression of this rule
- if(this.expressionName != null)
- {
- rule.setExpression(this.generateExpression());
- }
-
- rules.add(rule);
-
- //Add any implied actions
- if(impliedActions != null && !impliedActions.isEmpty())
- {
- for(Target impliedAction: impliedActions)
- {
- Rule impliedRule = new Rule();
-
- impliedRule.setRuleId(GeneralTool.generateUniqueId());
- impliedRule.setEffect(rule.getEffect());
- impliedRule.setExpression(rule.getExpression());
- impliedRule.setTarget(impliedAction);
-
- rules.add(impliedRule);
- }
- }
-
- return rules;
- }
- catch(Exception e)
- {
- //TODO: handle this properly
- log.error(this, e);
- throw new RuntimeException(e);
- }
- }
- //----------------------------------------------------------------------------------------------------------------------------------------------------------------
- private Expression generateExpression() throws Exception
- {
- DroolsRuleExpression expression = new DroolsRuleExpression();
-
- //Read the LogicExpression of the Logic Component
- Method expressionMethod = this.findExpression(this.logicComponent.getClass(), this.expressionName);
- expressionMethod.setAccessible(true);
-
- String[] expressionMetaData = (String[])expressionMethod.invoke(this.logicComponent, null);
-
- expression.setRuleReference(expressionMetaData[0]);
- expression.setRule(expressionMetaData[1]);
-
- return expression;
- }
-
- private Method findExpression(Class targetClass, String expressionName)
- {
- Method[] declaredMethods = targetClass.getDeclaredMethods();
- if(declaredMethods != null)
- {
- for(Method declaredMethod: declaredMethods)
- {
- Annotation logicExpression = declaredMethod.getAnnotation(LogicExpression.class);
- if(logicExpression != null)
- {
- if(declaredMethod.getName().equals(expressionName))
- {
- return declaredMethod;
- }
- }
- }
- }
-
- if(targetClass.getSuperclass() != null)
- {
- return this.findExpression(targetClass.getSuperclass(), expressionName);
- }
-
- return null;
- }
-}
Deleted: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleDeclarationRepository.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleDeclarationRepository.java 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleDeclarationRepository.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -1,64 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security.authz.component;
-
-import java.util.Set;
-import java.util.HashSet;
-
-import org.apache.log4j.Logger;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class RuleDeclarationRepository
-{
- private static Logger log = Logger.getLogger(RuleDeclarationRepository.class);
-
- private Set<ComponentMarker> components;
-
- public RuleDeclarationRepository()
- {
- }
-
- public void start()
- {
- this.components = new HashSet<ComponentMarker>();
- log.info("-------------------------------------------------------------------");
- log.info("RuleDeclarationRepository successfully started.....................");
- log.info("-------------------------------------------------------------------");
- }
-
- public void stop()
- {
-
- }
-
- public void register(ComponentMarker component)
- {
- this.components.add(component);
-
- log.debug("--------------------------------------------------------------");
- log.debug(component.getClass()+" was successfully registered.............");
- log.debug("--------------------------------------------------------------");
- }
- //---------------------------------------------------------------------------------------------------------------------------------------------------------------
-}
Deleted: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/TargetComposition.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/TargetComposition.java 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/TargetComposition.java 2009-06-16 16:47:34 UTC (rev 13461)
@@ -1,218 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security.authz.component;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.util.Set;
-import java.util.HashSet;
-
-import org.apache.log4j.Logger;
-
-import org.jboss.security.authz.model.Target;
-import org.jboss.security.authz.model.Attribute;
-import org.jboss.security.authz.model.AttributeExpression;
-import org.jboss.security.xacml.interfaces.XACMLConstants;
-import org.jboss.security.xacml.interfaces.XMLSchemaConstants;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class TargetComposition
-{
- private static Logger log = Logger.getLogger(TargetComposition.class);
-
- private Object targetComponent;
-
- public TargetComposition()
- {
-
- }
-
- public Object getTargetComponent()
- {
- return targetComponent;
- }
-
- public void setTargetComponent(Object targetComponent)
- {
- this.targetComponent = targetComponent;
- }
- //------------------------------------------------------------------------------------------------------------------------------------------------------------------
- public Target compose()
- {
- if(this.targetComponent == null)
- {
- throw new IllegalStateException("Target Component is null!!");
- }
-
- try
- {
- Target mainTarget = this.generateTarget();
- return mainTarget;
- }
- catch(Exception e)
- {
- //TODO: handle this properly
- log.error(this, e);
- throw new RuntimeException(e);
- }
- }
-
- public Set<Target> composeImpliedTargets()
- {
- try
- {
- Set<Target> impliedTargets = new HashSet<Target>();
-
- String[] impliedActions = this.findImpliedActions(this.targetComponent.getClass());
- if(impliedActions != null)
- {
- for(String impliedAction: impliedActions)
- {
- //TODO: Find the Action Component from the repository
- Object impliedActionComponent = null;
- if(impliedAction.equals("read"))
- {
- impliedActionComponent = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.authz.components.action.Read").newInstance();
- }
- else if(impliedAction.equals("write"))
- {
- impliedActionComponent = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.authz.components.action.Write").newInstance();
- }
-
- //Compose this action target
- TargetComposition comp = new TargetComposition();
- comp.setTargetComponent(impliedActionComponent);
- impliedTargets.add(comp.compose());
- }
- }
-
- return impliedTargets;
- }
- catch(Exception e)
- {
- //TODO: handle this properly
- log.error(this, e);
- throw new RuntimeException(e);
- }
- }
- //----------------------------------------------------------------------------------------------------------------------------------------------------------------
- private Target generateTarget() throws Exception
- {
- Target target = new Target();
-
- //Read the TargetUri
- Field targetField = this.findTargetField(this.targetComponent.getClass());
- targetField.setAccessible(true);
- Object targetUriObj = targetField.get(this.targetComponent);
-
- //Get a String representation of this URI
- String uriStr = targetUriObj.toString();
-
- //use the proper category for the data
- ComponentCategory category = this.findComponentCategory(this.targetComponent.getClass());
- String attributeCategory = category.getAttributeCategory();
-
- AttributeExpression urlExpression = new AttributeExpression();
- if (uriStr.charAt(0) == '/' && uriStr.endsWith("/*"))
- {
- // If URL starts with '/' and ends with "/*", use a regular
- // expression to match it (In consistency with the servlet spec)
- urlExpression
- .setFunctionId(XACMLConstants.FUNCTION_REGEXP_STRING_MATCH);
-
- String uriexp = uriStr.substring(1, uriStr.length() - 2);
- StringBuilder buffer = new StringBuilder();
- buffer.append("^/" + uriexp + "$|");
- buffer.append("^" + uriexp + "$|");
- buffer.append("^/" + uriexp + "/.*|");
- buffer.append("^" + uriexp + "/.*");
-
- Attribute attribute = new Attribute(
- attributeCategory,
- XMLSchemaConstants.DATATYPE_STRING, buffer.toString());
- urlExpression.setAttribute(attribute);
- }
- else
- {
- // use an exact match
- urlExpression.setFunctionId(XACMLConstants.FUNCTION_STRING_EQUAL);
-
- Attribute attribute = new Attribute(
- attributeCategory,
- XMLSchemaConstants.DATATYPE_STRING, uriStr);
- urlExpression.setAttribute(attribute);
- }
-
- //Depending up the data category add the appropriate match expression
- category.setExpression(target, urlExpression);
-
- return target;
- }
-
- private ComponentCategory findComponentCategory(Class targetClass)
- {
- Annotation component = targetClass.getAnnotation(Component.class);
- if(component != null)
- {
- return ((Component)component).category();
- }
-
- return null;
- }
-
- private String[] findImpliedActions(Class targetClass)
- {
- Annotation impliedActions = targetClass.getAnnotation(ImpliedActions.class);
- if(impliedActions != null)
- {
- return ((ImpliedActions)impliedActions).value();
- }
-
- return null;
- }
-
- private Field findTargetField(Class targetClass)
- {
- Field[] declaredFields = targetClass.getDeclaredFields();
- if(declaredFields != null)
- {
- for(Field declaredField: declaredFields)
- {
- Annotation targetUri = declaredField.getAnnotation(TargetUri.class);
- if(targetUri != null)
- {
- return declaredField;
- }
- }
- }
-
- //If I get here, query the super class
- if(targetClass.getSuperclass() != null)
- {
- return this.findTargetField(targetClass.getSuperclass());
- }
-
- return null;
- }
-}
Modified: modules/authorization/trunk/core-components-api/pom.xml
===================================================================
--- modules/authorization/trunk/core-components-api/pom.xml 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/core-components-api/pom.xml 2009-06-16 16:47:34 UTC (rev 13461)
@@ -34,14 +34,6 @@
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
- </dependency>
-
- <!-- Test Dependencies -->
- <!-- jboss microcontainer -->
- <dependency>
- <groupId>org.jboss.microcontainer</groupId>
- <artifactId>jboss-kernel</artifactId>
- <scope>test</scope>
- </dependency>
+ </dependency>
</dependencies>
</project>
Deleted: modules/authorization/trunk/core-components-api/src/main/resources/authz-components.xml
===================================================================
--- modules/authorization/trunk/core-components-api/src/main/resources/authz-components.xml 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/core-components-api/src/main/resources/authz-components.xml 2009-06-16 16:47:34 UTC (rev 13461)
@@ -1,66 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<components>
- <!--
- TODO: Just for prototyping the Component Contract. Eventually the method of configuration will be POJO components with Annotations
- -->
- <target-component name="uri" category="resource" class="org.jboss.security.authz.components.resource.URIResource">
- <target-uri>uniqueUri</target-uri>
- </target-component>
-
- <target-component name="operation" category="action" class="org.jboss.security.authz.components.action.Operation">
- <target-uri>name</target-uri>
- </target-component>
-
- <target-component name="read" category="action" class="org.jboss.security.authz.components.action.Read">
- <target-uri>name</target-uri>
- </target-component>
-
- <target-component name="write" category="action" class="org.jboss.security.authz.components.action.Write">
- <target-uri>name</target-uri>
- </target-component>
-
- <target-component name="manage" category="action" class="org.jboss.security.authz.components.action.Manage">
- <target-uri>name</target-uri>
- </target-component>
-
- <logic-component name="identity" category="subject" class="org.jboss.security.authz.components.subject.Identity">
- <target-uri>uri</target-uri>
- <logic-data>
- <data>name</data>
- </logic-data>
- </logic-component>
-
- <logic-component name="roles" category="subject" class="org.jboss.security.authz.components.subject.Roles">
- <target-uri></target-uri>
- <logic-data>
- <data>names</data>
- </logic-data>
- <logic-expressions>
- <expression>allowExpression</expression>
- <expression>denyExpression</expression>
- </logic-expressions>
- </logic-component>
-
-
- <!--
- Core Rule Compositions shipped with the framework. These can be re-used and more compositions can be added
- depending upon Application/Profile Requirements
- -->
- <rule-composition name="permitIdentity" outcome="permit">
- <target-component>identity</target-component>
- </rule-composition>
-
- <rule-composition name="denyIdentity" outcome="deny">
- <target-component>identity</target-component>
- </rule-composition>
-
- <rule-composition name="permitRole" outcome="permit">
- <target-component>operation</target-component>
- <logic-component expression="allowExpression">roles</logic-component>
- </rule-composition>
-
- <rule-composition name="denyRole" outcome="deny">
- <target-component>operation</target-component>
- <logic-component expression="denyExpression">roles</logic-component>
- </rule-composition>
-</components>
\ No newline at end of file
Modified: modules/authorization/trunk/pom.xml
===================================================================
--- modules/authorization/trunk/pom.xml 2009-06-16 15:03:53 UTC (rev 13460)
+++ modules/authorization/trunk/pom.xml 2009-06-16 16:47:34 UTC (rev 13461)
@@ -12,6 +12,7 @@
<modules>
<module>common-api</module>
<module>core-components-api</module>
+ <module>agent</module>
<module>policy-server</module>
<module>http-profile</module>
<module>portal-profile</module>
16 years, 10 months
JBoss Portal SVN: r13460 - branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-06-16 11:03:53 -0400 (Tue, 16 Jun 2009)
New Revision: 13460
Modified:
branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ProducerBean.java
Log:
- JBPORTAL-2410: report error instead of saving configuration with old values (which is correct but confusing for users).
Modified: branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ProducerBean.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ProducerBean.java 2009-06-16 11:32:25 UTC (rev 13459)
+++ branches/JBoss_Portal_Branch_2_7/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ProducerBean.java 2009-06-16 15:03:53 UTC (rev 13460)
@@ -55,9 +55,12 @@
private static final String PROPERTY = "property";
private static final String PRODUCER = "producer";
private String selectedProp;
+ private boolean invalidPolicy;
+ private boolean invalidValidator;
// todo: use ParameterValidation.VALID_ASCII_CLASS_NAME when available...
public final static Pattern VALID_ASCII_CLASS_NAME = Pattern.compile("([a-z][a-z0-9_]*\\.)*[A-Z][A-Za-z0-9_$]*");
+ private static final String INVALID_CLASS_NAME_ERROR = "INVALID_CLASS_NAME_ERROR";
public ProducerBean()
{
@@ -84,7 +87,7 @@
@Override
public String getErrorMessageKey()
{
- return "INVALID_CLASS_NAME_ERROR";
+ return INVALID_CLASS_NAME_ERROR;
}
});
@@ -149,7 +152,12 @@
if (className != null)
{
policyClassName = className;
+ invalidPolicy = false;
}
+ else
+ {
+ invalidPolicy = true;
+ }
}
public boolean isDefaultRegistrationPolicy()
@@ -172,7 +180,12 @@
if (className != null)
{
validatorClassName = className;
+ invalidValidator = false;
}
+ else
+ {
+ invalidValidator = true;
+ }
}
public boolean isStrictMode()
@@ -215,12 +228,19 @@
{
try
{
- if (!ProducerRegistrationRequirements.DEFAULT_POLICY_CLASS_NAME.equals(policyClassName))
+ if (!invalidPolicy && !invalidValidator)
{
- getRegRequirements().reloadPolicyFrom(policyClassName, validatorClassName);
+ if (!ProducerRegistrationRequirements.DEFAULT_POLICY_CLASS_NAME.equals(policyClassName))
+ {
+ getRegRequirements().reloadPolicyFrom(policyClassName, validatorClassName);
+ }
+ configurationService.saveConfiguration();
+ beanContext.createInfoMessage("bean_producer_save_success");
}
- configurationService.saveConfiguration();
- beanContext.createInfoMessage("bean_producer_save_success");
+ else
+ {
+ beanContext.createErrorMessage("bean_producer_cannot_save", "Invalid class name.");
+ }
}
catch (Exception e)
{
16 years, 10 months
JBoss Portal SVN: r13459 - in modules/authorization/trunk: core-components-api/src/main/java/org/jboss/security/authz/components/action and 1 other directories.
by portal-commits@lists.jboss.org
Author: sohil.shah(a)jboss.com
Date: 2009-06-16 07:32:25 -0400 (Tue, 16 Jun 2009)
New Revision: 13459
Added:
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ImpliedActions.java
Modified:
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposition.java
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/TargetComposition.java
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Manage.java
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Write.java
modules/authorization/trunk/core-components-api/src/test/java/org/jboss/security/authz/components/repository/TestPolicyComposition.java
Log:
backing up code. establishing a stable baseline before starting some refactoring
Added: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ImpliedActions.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ImpliedActions.java (rev 0)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ImpliedActions.java 2009-06-16 11:32:25 UTC (rev 13459)
@@ -0,0 +1,37 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.security.authz.component;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+(a)Target(ElementType.TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface ImpliedActions
+{
+ String[] value();
+}
Modified: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposition.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposition.java 2009-06-15 21:56:01 UTC (rev 13458)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/RuleComposition.java 2009-06-16 11:32:25 UTC (rev 13459)
@@ -23,12 +23,15 @@
import java.lang.reflect.Method;
import java.lang.annotation.Annotation;
+import java.util.Set;
+import java.util.HashSet;
import org.apache.log4j.Logger;
import org.jboss.security.authz.model.Rule;
import org.jboss.security.authz.model.Expression;
import org.jboss.security.authz.model.Effect;
+import org.jboss.security.authz.model.Target;
import org.jboss.security.authz.model.DroolsRuleExpression;
import org.jboss.security.authz.tools.GeneralTool;
@@ -89,7 +92,7 @@
this.expressionName = expressionName;
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
- public Rule compose()
+ public Set<Rule> compose()
{
if(this.effect == null)
{
@@ -106,17 +109,26 @@
try
{
+ Set<Rule> rules = new HashSet<Rule>();
+
Rule rule = new Rule();
rule.setRuleId(GeneralTool.generateUniqueId());
rule.setEffect(this.effect);
//Generate the Target for this rule
+ Set<Target> impliedActions = new HashSet<Target>();
if(this.targetComponent != null)
{
TargetComposition targetComposition = new TargetComposition();
targetComposition.setTargetComponent(this.targetComponent);
rule.setTarget(targetComposition.compose());
+
+ Set<Target> cour = targetComposition.composeImpliedTargets();
+ if(cour != null && !cour.isEmpty())
+ {
+ impliedActions.addAll(cour);
+ }
}
//Generate the Logic Expression of this rule
@@ -125,7 +137,25 @@
rule.setExpression(this.generateExpression());
}
- return rule;
+ rules.add(rule);
+
+ //Add any implied actions
+ if(impliedActions != null && !impliedActions.isEmpty())
+ {
+ for(Target impliedAction: impliedActions)
+ {
+ Rule impliedRule = new Rule();
+
+ impliedRule.setRuleId(GeneralTool.generateUniqueId());
+ impliedRule.setEffect(rule.getEffect());
+ impliedRule.setExpression(rule.getExpression());
+ impliedRule.setTarget(impliedAction);
+
+ rules.add(impliedRule);
+ }
+ }
+
+ return rules;
}
catch(Exception e)
{
@@ -169,6 +199,11 @@
}
}
+ if(targetClass.getSuperclass() != null)
+ {
+ return this.findExpression(targetClass.getSuperclass(), expressionName);
+ }
+
return null;
}
}
Modified: modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/TargetComposition.java
===================================================================
--- modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/TargetComposition.java 2009-06-15 21:56:01 UTC (rev 13458)
+++ modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/TargetComposition.java 2009-06-16 11:32:25 UTC (rev 13459)
@@ -23,6 +23,8 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import java.util.Set;
+import java.util.HashSet;
import org.apache.log4j.Logger;
@@ -65,7 +67,8 @@
try
{
- return this.generateTarget();
+ Target mainTarget = this.generateTarget();
+ return mainTarget;
}
catch(Exception e)
{
@@ -74,8 +77,46 @@
throw new RuntimeException(e);
}
}
- //----------------------------------------------------------------------------------------------------------------------------------------------------------------
- //TODO: Add TargetUri annotation inheritance
+
+ public Set<Target> composeImpliedTargets()
+ {
+ try
+ {
+ Set<Target> impliedTargets = new HashSet<Target>();
+
+ String[] impliedActions = this.findImpliedActions(this.targetComponent.getClass());
+ if(impliedActions != null)
+ {
+ for(String impliedAction: impliedActions)
+ {
+ //TODO: Find the Action Component from the repository
+ Object impliedActionComponent = null;
+ if(impliedAction.equals("read"))
+ {
+ impliedActionComponent = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.authz.components.action.Read").newInstance();
+ }
+ else if(impliedAction.equals("write"))
+ {
+ impliedActionComponent = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.authz.components.action.Write").newInstance();
+ }
+
+ //Compose this action target
+ TargetComposition comp = new TargetComposition();
+ comp.setTargetComponent(impliedActionComponent);
+ impliedTargets.add(comp.compose());
+ }
+ }
+
+ return impliedTargets;
+ }
+ catch(Exception e)
+ {
+ //TODO: handle this properly
+ log.error(this, e);
+ throw new RuntimeException(e);
+ }
+ }
+ //----------------------------------------------------------------------------------------------------------------------------------------------------------------
private Target generateTarget() throws Exception
{
Target target = new Target();
@@ -140,6 +181,17 @@
return null;
}
+ private String[] findImpliedActions(Class targetClass)
+ {
+ Annotation impliedActions = targetClass.getAnnotation(ImpliedActions.class);
+ if(impliedActions != null)
+ {
+ return ((ImpliedActions)impliedActions).value();
+ }
+
+ return null;
+ }
+
private Field findTargetField(Class targetClass)
{
Field[] declaredFields = targetClass.getDeclaredFields();
@@ -155,6 +207,12 @@
}
}
+ //If I get here, query the super class
+ if(targetClass.getSuperclass() != null)
+ {
+ return this.findTargetField(targetClass.getSuperclass());
+ }
+
return null;
}
}
Modified: modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Manage.java
===================================================================
--- modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Manage.java 2009-06-15 21:56:01 UTC (rev 13458)
+++ modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Manage.java 2009-06-16 11:32:25 UTC (rev 13459)
@@ -27,6 +27,7 @@
import org.jboss.security.authz.component.Component;
import org.jboss.security.authz.component.ComponentType;
import org.jboss.security.authz.component.ComponentCategory;
+import org.jboss.security.authz.component.ImpliedActions;
import org.jboss.security.authz.model.Target;
@@ -42,6 +43,7 @@
type=ComponentType.TARGET,
category=ComponentCategory.ACTION
)
+@ImpliedActions({"read", "write"})
public class Manage extends Operation
{
public Manage()
Modified: modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Write.java
===================================================================
--- modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Write.java 2009-06-15 21:56:01 UTC (rev 13458)
+++ modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Write.java 2009-06-16 11:32:25 UTC (rev 13459)
@@ -27,6 +27,7 @@
import org.jboss.security.authz.component.Component;
import org.jboss.security.authz.component.ComponentType;
import org.jboss.security.authz.component.ComponentCategory;
+import org.jboss.security.authz.component.ImpliedActions;
import org.jboss.security.authz.model.Target;
@@ -42,6 +43,7 @@
type=ComponentType.TARGET,
category=ComponentCategory.ACTION
)
+@ImpliedActions({"read"})
public class Write extends Operation
{
public Write()
Modified: modules/authorization/trunk/core-components-api/src/test/java/org/jboss/security/authz/components/repository/TestPolicyComposition.java
===================================================================
--- modules/authorization/trunk/core-components-api/src/test/java/org/jboss/security/authz/components/repository/TestPolicyComposition.java 2009-06-15 21:56:01 UTC (rev 13458)
+++ modules/authorization/trunk/core-components-api/src/test/java/org/jboss/security/authz/components/repository/TestPolicyComposition.java 2009-06-16 11:32:25 UTC (rev 13459)
@@ -38,6 +38,7 @@
import org.jboss.security.authz.components.subject.Identity;
import org.jboss.security.authz.components.subject.Roles;
import org.jboss.security.authz.components.action.Read;
+import org.jboss.security.authz.components.action.Manage;
import org.jboss.security.authz.components.resource.URIResource;
import org.jboss.security.authz.component.RuleComposition;
import org.jboss.security.authz.component.TargetComposition;
@@ -72,7 +73,7 @@
Target policyTarget = targetComposition.compose();
- Rule policyRule = ruleComposition.compose();
+ Set<Rule> policyRule = ruleComposition.compose();
//Assert the State
assertNotNull("Target must not be null!!", policyTarget);
@@ -80,7 +81,7 @@
PolicyMetaData metadata = new PolicyMetaData();
metadata.setTarget(policyTarget);
- metadata.addRule(policyRule);
+ metadata.setRules(policyRule);
Policy policy = new MockPolicy("testComposePermitIdentity", metadata);
log.info("----------------------------------------------------------------");
@@ -109,7 +110,7 @@
Target policyTarget = targetComposition.compose();
- Rule policyRule = ruleComposition.compose();
+ Set<Rule> policyRule = ruleComposition.compose();
//Assert the State
assertNotNull("Target must not be null!!", policyTarget);
@@ -117,10 +118,47 @@
PolicyMetaData metadata = new PolicyMetaData();
metadata.setTarget(policyTarget);
- metadata.addRule(policyRule);
+ metadata.setRules(policyRule);
Policy policy = new MockPolicy("testComposePermitRole", metadata);
log.info("----------------------------------------------------------------");
log.info(policy.generateSystemPolicy());
}
+
+ public void testImpliedTarget() throws Exception
+ {
+ Roles roles = new Roles();
+ Set<String> names = new HashSet<String>();
+ names.add("admin");
+ names.add("user");
+ roles.setNames(names);
+
+ URIResource uriResource = new URIResource();
+ uriResource.setUri(new URI("/portal/admin-tool/modifyLayout"));
+
+ TargetComposition targetComposition = new TargetComposition();
+ targetComposition.setTargetComponent(uriResource);
+
+ RuleComposition ruleComposition = new RuleComposition();
+ ruleComposition.setEffect(Effect.PERMIT);
+ ruleComposition.setLogicComponent(roles);
+ ruleComposition.setExpressionName("allowExpression");
+ ruleComposition.setTargetComponent(new Manage());
+
+
+ Target policyTarget = targetComposition.compose();
+ Set<Rule> policyRule = ruleComposition.compose();
+
+ //Assert the State
+ assertNotNull("Target must not be null!!", policyTarget);
+ assertNotNull("Rule must not be null!!", policyRule);
+
+ PolicyMetaData metadata = new PolicyMetaData();
+ metadata.setTarget(policyTarget);
+ metadata.setRules(policyRule);
+ Policy policy = new MockPolicy("testComposePermitRole", metadata);
+
+ log.info("----------------------------------------------------------------");
+ log.info(policy.generateSystemPolicy());
+ }
}
16 years, 10 months