Author: sohil.shah(a)jboss.com
Date: 2009-08-10 16:21:18 -0400 (Mon, 10 Aug 2009)
New Revision: 13727
Modified:
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/META-INF/exo-roles-component-mustmatchall.properties
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/META-INF/exo-roles-component.properties
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/org/exoplatform/portal/jboss/security/components/ExoRoles.java
Log:
Integrating the custom ExoRoles Security Component
Modified:
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/META-INF/exo-roles-component-mustmatchall.properties
===================================================================
---
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/META-INF/exo-roles-component-mustmatchall.properties 2009-08-10
20:16:28 UTC (rev 13726)
+++
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/META-INF/exo-roles-component-mustmatchall.properties 2009-08-10
20:21:18 UTC (rev 13727)
@@ -1,7 +1,7 @@
import java.util.Set
import java.util.HashSet
-function boolean <evaluateMembership>(Set userRoles)
+function boolean <function>(Set userRoles)
{
String[] allowedRoles = new String[]{<roleList>};
@@ -64,7 +64,7 @@
$ruleName: String()
$roles: HashSet()
eval($ruleName.contains("<ruleReference>"))
-eval(<evaluateMembership>($roles))
+eval(<function>($roles))
then
insert(Boolean.TRUE);
Modified:
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/META-INF/exo-roles-component.properties
===================================================================
---
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/META-INF/exo-roles-component.properties 2009-08-10
20:16:28 UTC (rev 13726)
+++
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/META-INF/exo-roles-component.properties 2009-08-10
20:21:18 UTC (rev 13727)
@@ -1,7 +1,7 @@
import java.util.Set
import java.util.HashSet
-function boolean <evaluateMembership>(Set userRoles)
+function boolean <function>(Set userRoles)
{
String[] allowedRoles = new String[]{<roleList>};
@@ -64,7 +64,7 @@
$ruleName: String()
$roles: HashSet()
eval($ruleName.contains("<ruleReference>"))
-eval(<evaluateMembership>($roles))
+eval(<function>($roles))
then
insert(Boolean.TRUE);
Modified:
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/org/exoplatform/portal/jboss/security/components/ExoRoles.java
===================================================================
---
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/org/exoplatform/portal/jboss/security/components/ExoRoles.java 2009-08-10
20:16:28 UTC (rev 13726)
+++
jbossexo/branches/security-integration-sandbox/portal/trunk/component/portal/src/main/java/org/exoplatform/portal/jboss/security/components/ExoRoles.java 2009-08-10
20:21:18 UTC (rev 13727)
@@ -40,97 +40,142 @@
@Component(name = "exo-roles", type = ComponentType.LOGIC, category =
ComponentCategory.SUBJECT)
public class ExoRoles extends Roles
{
- private String logicExpression;
- private String logicExpressionMustMatchAll;
-
+ private static String logicExpression;
+ private static String logicExpressionMustMatchAll;
+
+ static
+ {
+ ExoRoles.loadLogicExpression();
+ ExoRoles.loadLogicExpressionMustMatchAll();
+ }
+
public ExoRoles()
{
+ }
+
+ @LogicExpression
+ public String[] allowExpression()
+ {
+ String ruleReference = "roles://allowRule/"
+ + GeneralTool.generateUniqueId();
+
+ // Generate a Drools Rule Expression
+ String ruleLogic = this.generateRuleLogic();
+ ruleLogic = ruleLogic.replaceAll("<ruleReference>", ruleReference);
+
+ return new String[] { ruleReference, ruleLogic };
+ }
+
+ @LogicExpression
+ public String[] denyExpression()
+ {
+ String ruleReference = "roles://denyRule/"
+ + GeneralTool.generateUniqueId();
+
+ // Generate a Drools Rule Expression
+ String ruleLogic = this.generateRuleLogic();
+ ruleLogic = ruleLogic.replaceAll("<ruleReference>", ruleReference);
+
+ return new String[] { ruleReference, ruleLogic };
+ }
+
+ private String generateRuleLogic()
+ {
+ // Generate a Drools Rule Expression
+ StringBuilder buffer = new StringBuilder();
+ for (String role : this.getNames())
+ {
+ buffer.append("\"" + role.toLowerCase() + "\"");
+ buffer.append(",");
+ }
+ String roleList = buffer.toString().trim();
+ roleList = roleList.substring(0, roleList.lastIndexOf(','));
+
+ String ruleLogic = null;
+ if (!this.mustMatchAll)
+ {
+ ruleLogic = this.logicExpression.replaceAll("<roleList>", roleList);
+ }
+ else
+ {
+ ruleLogic = this.logicExpressionMustMatchAll.replaceAll("<roleList>",
+ roleList);
+ }
+ return ruleLogic;
+ }
+
+ //
-------------------------------------------------------------------------------------------------------------------------------------------
+ private static void loadLogicExpression()
+ {
BufferedReader reader = null;
try
{
reader = new BufferedReader(new InputStreamReader(Thread.currentThread()
- .getContextClassLoader().getSystemResourceAsStream(
- "META-INF/exo-roles-component.properties")));
+ .getContextClassLoader().getSystemResourceAsStream(
+ "META-INF/exo-roles-component.properties")));
String buffer = null;
StringBuilder builder = new StringBuilder();
- while((buffer=reader.readLine()) != null)
+ while ((buffer = reader.readLine()) != null)
{
builder.append(buffer);
builder.append("\n");
}
-
- this.logicExpression = builder.toString().trim();
+
+ logicExpression = builder.toString().trim();
}
- catch(IOException ioe)
+ catch (IOException ioe)
{
throw new RuntimeException(ioe);
}
finally
{
- if(reader != null)
+ if (reader != null)
{
- try{reader.close();}catch(IOException ioe){}
+ try
+ {
+ reader.close();
+ }
+ catch (IOException ioe)
+ {
+ }
}
}
-
+ }
+
+ private static void loadLogicExpressionMustMatchAll()
+ {
+ BufferedReader reader = null;
try
{
reader = new BufferedReader(new InputStreamReader(Thread.currentThread()
- .getContextClassLoader().getSystemResourceAsStream(
- "META-INF/exo-roles-component-mustmatchall.properties")));
+ .getContextClassLoader().getSystemResourceAsStream(
+ "META-INF/exo-roles-component-mustmatchall.properties")));
String buffer = null;
StringBuilder builder = new StringBuilder();
- while((buffer=reader.readLine()) != null)
+ while ((buffer = reader.readLine()) != null)
{
builder.append(buffer);
builder.append("\n");
}
-
- this.logicExpressionMustMatchAll = builder.toString().trim();
+
+ logicExpressionMustMatchAll = builder.toString().trim();
}
- catch(IOException ioe)
+ catch (IOException ioe)
{
throw new RuntimeException(ioe);
}
finally
{
- if(reader != null)
+ if (reader != null)
{
- try{reader.close();}catch(IOException ioe){}
+ try
+ {
+ reader.close();
+ }
+ catch (IOException ioe)
+ {
+ }
}
}
}
-
- @LogicExpression
- public String[] allowExpression()
- {
- String ruleReference = "roles://allowRule/"
- + GeneralTool.generateUniqueId();
-
- // Generate a Drools Rule Expression
- StringBuilder buffer = new StringBuilder();
- for (String role : this.getNames())
- {
- buffer.append("\""+role.toLowerCase()+"\"");
- buffer.append(",");
- }
- String roleList = buffer.toString().trim();
- roleList = roleList.substring(0, roleList.lastIndexOf(','));
-
- try{Thread.currentThread().sleep(10);}catch(Exception e){}
-
- String ruleLogic = null;
- if(!this.mustMatchAll)
- {
- ruleLogic = this.logicExpression.replaceAll("<roleList>", roleList);
- }
- else
- {
- ruleLogic = this.logicExpressionMustMatchAll.replaceAll("<roleList>",
roleList);
- }
- ruleLogic = ruleLogic.replaceAll("<ruleReference>", ruleReference);
- ruleLogic = ruleLogic.replaceAll("<evaluateMembership>",
"evaluateMembership"+System.currentTimeMillis());
-
- return new String[] { ruleReference, ruleLogic };
- }
}
Show replies by date