use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.
the class FactoryMethods method createArbitraryReferralPrivilege.
public static ReferralPrivilege createArbitraryReferralPrivilege(String name, long now) throws EntitlementException {
Map<String, Set<String>> appNameToResources = new HashMap<String, Set<String>>();
appNameToResources.put("arbitraryApplicationName", asSet("arbitraryResource1", "arbitraryResource2"));
ReferralPrivilege referralPrivilege = new ReferralPrivilege(name, appNameToResources, asSet("arbitraryRealm"));
referralPrivilege.setDescription("ReferralPrivilege " + name);
referralPrivilege.setCreatedBy("creatingAuthor");
referralPrivilege.setLastModifiedBy("modifyingAuthor");
referralPrivilege.setCreationDate(now);
referralPrivilege.setLastModifiedDate(now);
referralPrivilege.setActive(true);
return referralPrivilege;
}
use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.
the class XACMLPrivilegeUtilsTest method shouldReturnNullWhenGivenNullAsReferralPrivilege.
@Test
public void shouldReturnNullWhenGivenNullAsReferralPrivilege() throws JSONException {
//Given
ReferralPrivilege referralPrivilege = null;
//When
Policy policy = XACMLPrivilegeUtils.referralToPolicy(referralPrivilege);
//Then
assertNull(policy, "Expected Policy to be null.");
}
use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.
the class XACMLReaderWriterTest method canReadAndWritePrivilegesAsXACML.
@Test
public void canReadAndWritePrivilegesAsXACML() throws Exception {
// Given
Privilege privilege = createArbitraryPrivilege("Privilege", now);
ReferralPrivilege referralPrivilege = createArbitraryReferralPrivilege("ReferralPrivilege", now);
XACMLReaderWriter xacmlReaderWriter = new XACMLReaderWriter();
PrivilegeSet inputPrivilegeSet = new PrivilegeSet(asList(referralPrivilege), asList(privilege));
// When
PolicySet policySet = xacmlReaderWriter.toXACML(ROOT_REALM, inputPrivilegeSet);
PrivilegeSet outputPrivilegeSet = xacmlReaderWriter.fromXACML(policySet);
// Then
assertThat(outputPrivilegeSet.getPrivileges()).hasSize(1);
assertPrivilegesEquivalent(outputPrivilegeSet.getPrivileges().get(0), privilege);
assertThat(outputPrivilegeSet.getReferralPrivileges()).hasSize(1);
assertReferralPrivilegesEquivalent(outputPrivilegeSet.getReferralPrivileges().get(0), referralPrivilege);
}
use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.
the class OpenSSOIndexStore method getReferredResources.
/**
* Returns a set of resources that are referred to this realm.
*
* @param applicationTypeName Application type name,
* @return a set of resources that are referred to this realm.
* @throws EntitlementException if resources cannot be returned.
*/
@Override
public Set<String> getReferredResources(String applicationTypeName) throws EntitlementException {
String realm = getRealm();
if (realm.equals("/")) {
return Collections.EMPTY_SET;
}
if (LDAPUtils.isDN(realm)) {
realm = DNMapper.orgNameToRealmName(realm);
}
SSOToken adminToken = SubjectUtils.getSSOToken(superAdminSubject);
try {
Set<String> results = new HashSet<String>();
Set<String> realms = getPeerRealms(realm);
realms.addAll(getParentRealms(realm));
String filter = "(&(ou=" + DataStore.REFERRAL_APPLS + "=" + applicationTypeName + ")(ou=" + DataStore.REFERRAL_REALMS + "=" + realm + "))";
Map<String, Set<ReferralPrivilege>> referrals = new HashMap<String, Set<ReferralPrivilege>>();
for (String rlm : realms) {
referrals.put(rlm, dataStore.searchReferrals(adminToken, rlm, filter));
}
for (String rlm : referrals.keySet()) {
Set<ReferralPrivilege> rPrivileges = referrals.get(rlm);
String realmName = LDAPUtils.isDN(rlm) ? DNMapper.orgNameToRealmName(rlm) : rlm;
for (ReferralPrivilege r : rPrivileges) {
Map<String, Set<String>> map = r.getOriginalMapApplNameToResources();
for (String a : map.keySet()) {
Application appl = ApplicationManager.getApplication(PolicyConstants.SUPER_ADMIN_SUBJECT, realmName, a);
if (appl.getApplicationType().getName().equals(applicationTypeName)) {
results.addAll(map.get(a));
}
}
}
}
results.addAll(getOrgAliasMappingResources(realm, applicationTypeName));
return results;
} catch (SMSException ex) {
PolicyConstants.DEBUG.error("OpenSSOIndexStore.getReferredResources", ex);
Object[] param = { realm };
throw new EntitlementException(275, param);
}
}
use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.
the class OpenSSOIndexStore method getOrgAliasReferral.
private ReferralPrivilege getOrgAliasReferral(ResourceSearchIndexes indexes) throws EntitlementException {
ReferralPrivilege result = null;
SSOToken adminToken = SubjectUtils.getSSOToken(superAdminSubject);
//TOFIX check if it is webagent service
if (OpenSSOIndexStore.isOrgAliasMappingResourceEnabled(adminToken)) {
try {
Set<String> realms = getReferredRealmNames(adminToken, indexes);
if ((realms != null) && !realms.isEmpty()) {
Map<String, Set<String>> map = new HashMap<String, Set<String>>();
Set<String> res = new HashSet<String>();
res.add("http*://" + getReferralURL(indexes.getHostIndexes()) + ":*");
map.put(ApplicationTypeManager.URL_APPLICATION_TYPE_NAME, res);
result = new ReferralPrivilege("referralprivilege111", map, realms);
}
} catch (SSOException e) {
PolicyConstants.DEBUG.error("OpenSSOIndexStore.getOrgAliasReferral", e);
} catch (SMSException e) {
PolicyConstants.DEBUG.error("OpenSSOIndexStore.getOrgAliasReferral", e);
}
}
return result;
}
Aggregations