use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldNotAllowSettingLastModifiedDate.
@Test
public void shouldNotAllowSettingLastModifiedDate() throws Exception {
// Given
JsonValue content = buildJson(field("lastModifiedDate", "2014-01-01T00:00:00.000Z"));
// When
Privilege result = parser.parsePolicy(POLICY_NAME, content);
// Then
assertThat(result.getLastModifiedDate()).isEqualTo(0);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PrivilegePolicyStoreTest method shouldSendAllMatchingPoliciesToQueryHandler.
@Test
public void shouldSendAllMatchingPoliciesToQueryHandler() throws Exception {
// Given
QueryRequest request = mockQueryRequest(QueryFilter.alwaysTrue());
List<Privilege> policies = Arrays.<Privilege>asList(new StubPrivilege("one"), new StubPrivilege("two"), new StubPrivilege("three"));
given(mockManager.search(anySetOf(SearchFilter.class))).willReturn(policies);
// When
List<Privilege> result = testStore.query(request);
// Then
assertThat(result).isEqualTo(policies);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PrivilegePolicyStoreTest method shouldAddPoliciesToPrivilegeManager.
@Test
public void shouldAddPoliciesToPrivilegeManager() throws Exception {
// Given
Privilege policy = new StubPrivilege();
// When
Privilege response = testStore.create(policy);
// Then
verify(mockManager).add(policy);
assertThat(response).isSameAs(policy);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PrivilegeUtilsTest method testPrivilegeToXACMLPolicy.
@Test
public void testPrivilegeToXACMLPolicy() throws Exception {
try {
UnittestLog.logMessage("PrivilegeUtils.testPrivilegeToXACMLPolicy():" + " entered");
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("GET", Boolean.TRUE);
actionValues.put("POST", Boolean.FALSE);
// The port is required for passing equals test
// opensso policy would add default port if port not specified
String resourceName = "http://www.sun.com:80";
Entitlement entitlement = new Entitlement(SERVICE_NAME, resourceName, actionValues);
entitlement.setName("ent1");
String user11 = "id=user11,ou=user," + ServiceManager.getBaseDN();
String user12 = "id=user12,ou=user," + ServiceManager.getBaseDN();
UserSubject ua1 = new OpenSSOUserSubject();
ua1.setID(user11);
UserSubject ua2 = new OpenSSOUserSubject();
ua2.setID(user12);
Set<EntitlementSubject> subjects = new HashSet<EntitlementSubject>();
subjects.add(ua1);
subjects.add(ua2);
OrSubject os = new OrSubject(subjects);
Set<EntitlementCondition> conditions = new HashSet<EntitlementCondition>();
String startIp = "100.100.100.100";
String endIp = "200.200.200.200";
IPv4Condition ipc = new IPv4Condition();
ipc.setStartIpAndEndIp(startIp, endIp);
conditions.add(ipc);
OrCondition oc = new OrCondition(conditions);
AndCondition ac = new AndCondition(conditions);
StaticAttributes sa1 = new StaticAttributes();
Set<String> aValues = new HashSet<String>();
aValues.add("a10");
aValues.add("a20");
sa1.setPropertyName("a");
sa1.setPropertyValues(aValues);
sa1.setPResponseProviderName("sa");
StaticAttributes sa2 = new StaticAttributes();
Set<String> bValues = new HashSet<String>();
bValues.add("b10");
bValues.add("b20");
sa2.setPropertyName("b");
sa2.setPropertyValues(bValues);
sa2.setPResponseProviderName("sa");
UserAttributes uat1 = new UserAttributes();
uat1.setPropertyName("email");
uat1.setPResponseProviderName("ua");
UserAttributes uat2 = new UserAttributes();
uat2.setPropertyName("uid");
uat2.setPResponseProviderName("ua");
Set<ResourceAttribute> ra = new HashSet<ResourceAttribute>();
ra.add(sa1);
ra.add(sa2);
ra.add(uat1);
ra.add(uat2);
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME);
privilege.setEntitlement(entitlement);
privilege.setSubject(ua1);
privilege.setCondition(ipc);
privilege.setResourceAttributes(ra);
privilege.setCreatedBy("amadmin");
privilege.setLastModifiedBy("amadmin");
privilege.setCreationDate(System.currentTimeMillis());
privilege.setLastModifiedDate(System.currentTimeMillis());
UnittestLog.logMessage("PrivilegeUtils.testPrivilegeToXACMLPolicy():" + "Privilege=" + privilege.toString());
UnittestLog.logMessage("PrivilegeUtils.testPrivilegeToXACMLPolicy():" + "converting to xacml policy");
// TODO(jtb): not compiling
String xacmlString = XACMLPrivilegeUtils.toXACML(privilege);
UnittestLog.logMessage("xacml policy=" + xacmlString);
} catch (Throwable t) {
UnittestLog.logError("Throwable:", t);
UnittestLog.logMessage("Throwable:" + t.getMessage());
t.printStackTrace();
}
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class RestTest method setup.
@BeforeClass
public void setup() throws Exception {
try {
PrivilegeManager pm = PrivilegeManager.getInstance(REALM, adminSubject);
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME);
Map<String, Boolean> actions = new HashMap<String, Boolean>();
actions.put("GET", true);
Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/*", actions);
privilege.setEntitlement(entitlement);
EntitlementSubject sbj = new AuthenticatedUsers();
privilege.setSubject(sbj);
NumericAttributeCondition cond = new NumericAttributeCondition();
cond.setAttributeName(ATTR_NAME);
cond.setOperator(NumericAttributeCondition.Operator.EQUAL);
cond.setValue(ATTR_VAL);
privilege.setCondition(cond);
pm.add(privilege);
user = IdRepoUtils.createAgent(REALM, AGENT_NAME);
SSOToken ssoToken = AuthUtils.authenticate(REALM, AGENT_NAME, AGENT_NAME);
String userTokenId = ssoToken.getTokenID().toString();
hashedUserTokenId = Hash.hash(userTokenId);
userTokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + userTokenId;
String cookieValue = userTokenId;
if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
cookieValue = URLEncoder.encode(userTokenId, "UTF-8");
}
cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
String serverURL = SystemProperties.getServerInstanceName();
decisionClient = Client.create().resource(serverURL + "/ws/1/entitlement/decision");
decisionsClient = Client.create().resource(serverURL + "/ws/1/entitlement/decisions");
entitlementClient = Client.create().resource(serverURL + "/ws/1/entitlement/entitlement");
entitlementsClient = Client.create().resource(serverURL + "/ws/1/entitlement/entitlements");
} catch (Exception e) {
UnittestLog.logError("RestTest.setup() failed:", e);
throw e;
}
}
Aggregations