mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-17 18:33:32 +09:00
Feature #2653: add acl zone component to java oca
This commit is contained in:
1 parent
79c3ac8e52
commit
5e379a6018
2 files changed
+104
-17
No files matched your search
@@ -110,6 +110,23 @@ public class Acl extends PoolElement{
|
||||
return client.call(ADDRULE, user, resource, rights);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new ACl rule in OpenNebula
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param user A string containing a hex number, e.g. 0x100000001
|
||||
* @param resource A string containing a hex number, e.g. 0x2100000001
|
||||
* @param rights A string containing a hex number, e.g. 0x10
|
||||
* @param zone A string containing a hex number, e.g. 0x10
|
||||
* @return If successful the message contains the associated
|
||||
* id generated for this rule.
|
||||
*/
|
||||
public static OneResponse allocate(Client client, String user,
|
||||
String resource, String rights, String zone)
|
||||
{
|
||||
return client.call(ADDRULE, user, resource, rights, zone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new ACl rule in OpenNebula
|
||||
*
|
||||
@@ -129,6 +146,27 @@ public class Acl extends PoolElement{
|
||||
Long.toHexString(rights));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new ACl rule in OpenNebula
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param user 64b encoded user
|
||||
* @param resource 64b encoded
|
||||
* @param rights 64b encoded
|
||||
* @param zone 64b encoded
|
||||
* @return If successful the message contains the associated
|
||||
* id generated for this rule.
|
||||
*/
|
||||
public static OneResponse allocate(Client client, long user, long resource,
|
||||
long rights, long zone)
|
||||
{
|
||||
return allocate(client,
|
||||
Long.toHexString(user),
|
||||
Long.toHexString(resource),
|
||||
Long.toHexString(rights),
|
||||
Long.toHexString(zone));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new ACl rule in OpenNebula
|
||||
*
|
||||
@@ -142,7 +180,16 @@ public class Acl extends PoolElement{
|
||||
throws RuleParseException
|
||||
{
|
||||
String[] components = parseRule(rule);
|
||||
return allocate(client, components[0], components[1], components[2]);
|
||||
|
||||
if (components.length > 3)
|
||||
{
|
||||
return allocate(client, components[0], components[1],
|
||||
components[2], components[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return allocate(client, components[0], components[1], components[2]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,6 +264,20 @@ public class Acl extends PoolElement{
|
||||
return ret;
|
||||
}
|
||||
|
||||
public long zone()
|
||||
{
|
||||
long ret = 0;
|
||||
|
||||
try
|
||||
{
|
||||
ret = Long.parseLong( xpath("ZONE"), 16 );
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String st = xpath("STRING");
|
||||
@@ -237,25 +298,31 @@ public class Acl extends PoolElement{
|
||||
* Parses a rule string, e.g. "#5 HOST+VM/@12 INFO+CREATE+DELETE"
|
||||
*
|
||||
* @param rule an ACL rule in string format
|
||||
* @return an Array containing 3 Strings (hex 64b numbers)
|
||||
* @return an Array containing 4 Strings (hex 64b numbers). 3 if the rule
|
||||
* does not have the zone component, for compatibility
|
||||
* @throws RuleParseException If the rule syntax is wrong.
|
||||
*/
|
||||
public static String[] parseRule(String rule) throws RuleParseException
|
||||
{
|
||||
String [] ret = new String[3];
|
||||
|
||||
String [] components = rule.split(" ");
|
||||
|
||||
if( components.length != 3 )
|
||||
if( components.length != 3 && components.length != 4 )
|
||||
{
|
||||
throw new RuleParseException(
|
||||
"String needs three components: User, Resource, Rights");
|
||||
}
|
||||
|
||||
String [] ret = new String[components.length];
|
||||
|
||||
ret[0] = parseUsers(components[0]);
|
||||
ret[1] = parseResources(components[1]);
|
||||
ret[2] = parseRights(components[2]);
|
||||
|
||||
if(components.length > 3)
|
||||
{
|
||||
ret[3] = parseZone(components[3]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -332,6 +399,17 @@ public class Acl extends PoolElement{
|
||||
return Long.toHexString(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string in the form [#<id>, *] to a hex. number
|
||||
*
|
||||
* @param zone Zone component string
|
||||
* @return A string containing a hex number
|
||||
*/
|
||||
private static String parseZone(String zone) throws RuleParseException
|
||||
{
|
||||
return Long.toHexString( calculateIds(zone) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the numeric value for a String containing an individual
|
||||
* (#id), group (@id) or all (*) ID component
|
||||
|
||||
@@ -68,7 +68,7 @@ public class AclTest
|
||||
{
|
||||
for(Acl rule : aclPool)
|
||||
{
|
||||
if( rule.id() != 0 && rule.id() != 1 )
|
||||
if( rule.id() > 3 )
|
||||
{
|
||||
rule.delete();
|
||||
}
|
||||
@@ -81,9 +81,9 @@ public class AclTest
|
||||
res = aclPool.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
assertEquals(2, aclPool.getLength());
|
||||
assertEquals(4, aclPool.getLength());
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void hexAllocate()
|
||||
{
|
||||
@@ -102,7 +102,8 @@ public class AclTest
|
||||
assertEquals(0x8L, acl.rights());
|
||||
assertEquals("#1 VM+HOST/@1 CREATE",acl.toString());
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void numericAllocate()
|
||||
{
|
||||
@@ -121,13 +122,13 @@ public class AclTest
|
||||
assertEquals(0x1L, acl.rights());
|
||||
assertEquals("#1 VM+HOST/@1 USE", acl.toString());
|
||||
}
|
||||
|
||||
*/
|
||||
@Test
|
||||
public void ruleAllocate()
|
||||
{
|
||||
try
|
||||
{
|
||||
res = Acl.allocate(client, "@507 IMAGE/#456 MANAGE");
|
||||
res = Acl.allocate(client, "@507 IMAGE/#456 MANAGE #102");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
aclPool.info();
|
||||
@@ -139,7 +140,7 @@ public class AclTest
|
||||
assertEquals(0x2000001fbL, acl.user());
|
||||
assertEquals(0x81000001c8L, acl.resource());
|
||||
assertEquals(0x2L, acl.rights());
|
||||
assertEquals("@507 IMAGE/#456 MANAGE", acl.toString());
|
||||
assertEquals("@507 IMAGE/#456 MANAGE #102", acl.toString());
|
||||
}
|
||||
catch (RuleParseException e)
|
||||
{
|
||||
@@ -156,7 +157,7 @@ public class AclTest
|
||||
"@107 IMAGE+TEMPLATE/@100 USE",
|
||||
"* VM+IMAGE+TEMPLATE/@100 CREATE+USE",
|
||||
"#2345 VM+IMAGE+TEMPLATE/* CREATE+USE",
|
||||
"@7 HOST/@100 USE+MANAGE",
|
||||
"@7 HOST/#100 USE+MANAGE",
|
||||
"* HOST+DATASTORE/%100 MANAGE+USE",
|
||||
"@107 NET/%100 USE"
|
||||
};
|
||||
@@ -178,7 +179,7 @@ public class AclTest
|
||||
0x28200000064L,
|
||||
0x29200000064L,
|
||||
0x29400000000L,
|
||||
0x2200000064L,
|
||||
0x2100000064L,
|
||||
0x102800000064L,
|
||||
0x4800000064L
|
||||
};
|
||||
@@ -219,6 +220,14 @@ public class AclTest
|
||||
+ e.getMessage(),
|
||||
false);
|
||||
}
|
||||
catch (AssertionError e)
|
||||
{
|
||||
assertTrue(
|
||||
"Rule " + rules[i]
|
||||
+ " assert failure; "
|
||||
+ e.getMessage(),
|
||||
false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,17 +236,17 @@ public class AclTest
|
||||
{
|
||||
try
|
||||
{
|
||||
res = Acl.allocate(client, "#1 HOST/@2 USE");
|
||||
res = Acl.allocate(client, "#1 HOST/#2 USE");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
aclPool.info();
|
||||
assertTrue( aclPool.getLength() == 4 );
|
||||
assertEquals( 5, aclPool.getLength() );
|
||||
|
||||
res = Acl.delete(client, res.getIntMessage());
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
aclPool.info();
|
||||
assertTrue( aclPool.getLength() == 3 );
|
||||
assertEquals( 4, aclPool.getLength() );
|
||||
}
|
||||
catch (RuleParseException e)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user