use of com.sun.identity.policy.interfaces.Referral in project OpenAM by OpenRock.
the class PolicyModelImpl method getActiveReferralTypes.
/**
* Returns a map of active referral types for a realm to its display name.
*
* @param realmName Name of Realm.
* @return a map of active referral types for a realm to its display name.
*/
public Map getActiveReferralTypes(String realmName) {
Map referralTypes = null;
try {
PolicyManager policyMgr = getPolicyManager(realmName);
if (policyMgr != null) {
ReferralTypeManager referralTypeMgr = policyMgr.getReferralTypeManager();
if (referralTypeMgr != null) {
Set types = referralTypeMgr.getSelectedReferralTypeNames();
referralTypes = new HashMap(types.size() * 2);
for (Iterator iter = types.iterator(); iter.hasNext(); ) {
String rName = (String) iter.next();
Referral referral = referralTypeMgr.getReferral(rName);
if (referral != null) {
Syntax syntax = referral.getValueSyntax(getUserSSOToken());
if (!syntax.equals(Syntax.NONE)) {
referralTypes.put(rName, referralTypeMgr.getDisplayName(rName));
}
}
}
}
}
} catch (AMConsoleException e) {
debug.warning("PolicyModelImpl.getActiveReferralTypes", e);
} catch (SSOException e) {
debug.warning("PolicyModelImpl.getActiveReferralTypes", e);
} catch (NameNotFoundException e) {
debug.warning("PolicyModelImpl.getActiveReferralTypes", e);
} catch (PolicyException e) {
debug.warning("PolicyModelImpl.getActiveReferralTypes", e);
}
return (referralTypes == null) ? Collections.EMPTY_MAP : referralTypes;
}
use of com.sun.identity.policy.interfaces.Referral in project OpenAM by OpenRock.
the class Referrals method getPolicyDecision.
/**
* Returns policy deicision
* @param token sso token identifying the user for who the Referrals has to
* be evaluated.
* @param resourceType resourceType
* @param resourceName resourceName
* @param actionNames a set of action names for which policy results
* are to be evaluated. Each element of the set should be a
* String
* @param envParameters a map of environment parameters
* Each key of the map is a String valued parameter name
* Each value of the map is a set of String values
* @return policy decision
* @throws NameNotFoundException if the action name or resource name
* is not found
* @throws SSOException if token is invalid
* @throws PolicyException for any other exception condition
*/
PolicyDecision getPolicyDecision(SSOToken token, String resourceType, String resourceName, Set actionNames, Map envParameters) throws SSOException, NameNotFoundException, PolicyException {
PolicyDecision mergedPolicyDecision = null;
ServiceType serviceType = ServiceTypeManager.getServiceTypeManager().getServiceType(resourceType);
Set referralNames = getReferralNames();
Iterator referralIter = referralNames.iterator();
while (referralIter.hasNext()) {
String referralName = (String) referralIter.next();
Referral referral = getReferral(referralName);
if (referral instanceof OrgReferral) {
//specially evaluated by PolicyEvaluator
continue;
}
PolicyDecision policyDecision = referral.getPolicyDecision(token, resourceType, resourceName, actionNames, envParameters);
if (mergedPolicyDecision == null) {
mergedPolicyDecision = policyDecision;
} else {
PolicyEvaluator.mergePolicyDecisions(serviceType, policyDecision, mergedPolicyDecision);
}
actionNames.removeAll(PolicyEvaluator.getFinalizedActions(serviceType, mergedPolicyDecision));
if (actionNames.isEmpty()) {
break;
}
}
return (mergedPolicyDecision);
}
use of com.sun.identity.policy.interfaces.Referral in project OpenAM by OpenRock.
the class Referrals method toXML.
/**
* Returns an XML representaion of this <code>Referrals</code> object
*/
protected String toXML() {
StringBuilder sb = new StringBuilder(100);
sb.append("\n").append(REFERRALS_ELEMENT_BEGIN).append(XMLUtils.escapeSpecialCharacters(name)).append(REFERRALS_DESCRIPTION).append(XMLUtils.escapeSpecialCharacters(description)).append("\">");
Iterator items = referrals.keySet().iterator();
while (items.hasNext()) {
String referralName = (String) items.next();
Referral referral = (Referral) referrals.get(referralName);
sb.append("\n").append(REFERRAL_ELEMENT).append(XMLUtils.escapeSpecialCharacters(referralName)).append(REFERRAL_TYPE).append(XMLUtils.escapeSpecialCharacters(ReferralTypeManager.referralTypeName(referral))).append("\">");
// Add attribute values pairs
Set v = referral.getValues();
if ((v != null) && !v.isEmpty()) {
sb.append("\n").append(ATTR_VALUE_BEGIN);
Iterator values = v.iterator();
while (values.hasNext()) {
sb.append("\n").append(VALUE_BEGIN).append(XMLUtils.escapeSpecialCharacters((String) values.next())).append(VALUE_END);
}
sb.append("\n").append(ATTR_VALUE_END);
}
sb.append("\n").append(REFERRAL_ELEMENT_END);
}
sb.append("\n").append(REFERRALS_ELEMENT_END);
return (sb.toString());
}
use of com.sun.identity.policy.interfaces.Referral in project OpenAM by OpenRock.
the class ResourceManager method removePolicyFromResourceTree.
/**
* Removes the resource names of the policy from the resource tree.
*
* @param policy the policy to be removed
*
* @exception PolicyException if unable to get the policy services,
* and will contain the exception thrown by SMS.
* @exception SSOException single-sign-on token invalid or expired
*/
void removePolicyFromResourceTree(Policy policy) throws PolicyException, SSOException {
Set ruleNames = policy.getRuleNames();
Iterator i = ruleNames.iterator();
// iterating through each rule
String ruleName = null;
Rule rule = null;
while (i.hasNext()) {
ruleName = (String) i.next();
rule = policy.getRule(ruleName);
removeRuleFromResourceTree(policy.getName(), rule.getResourceName(), rule.getServiceTypeName(), rule.getServiceType());
}
//Process Referrals
Referrals referrals = policy.getReferrals();
if (referrals != null) {
Set referralNames = referrals.getReferralNames();
if ((referralNames != null) && (!referralNames.isEmpty())) {
Iterator referralIter = referralNames.iterator();
while (referralIter.hasNext()) {
String referralName = (String) referralIter.next();
Referral referral = referrals.getReferral(referralName);
if (referral instanceof OrgReferral) {
Set values = referral.getValues();
if ((values != null) && (!values.isEmpty())) {
Iterator valueIter = values.iterator();
while (valueIter.hasNext()) {
String value = (String) valueIter.next();
PolicyManager pm = new PolicyManager(token, value);
ResourceManager rm = pm.getResourceManager();
Iterator ruleIter = policy.getRuleNames().iterator();
while (ruleIter.hasNext()) {
String ruleName1 = (String) ruleIter.next();
Rule rule1 = policy.getRule(ruleName);
String resourceName = rule1.getResourceName();
if (resourceName != null) {
String serviceTypeName = rule1.getServiceTypeName();
Set resourceNames = new HashSet();
resourceNames.add(resourceName);
rm.removeResourcePrefixes(serviceTypeName, resourceNames);
}
}
}
}
}
}
}
}
}
use of com.sun.identity.policy.interfaces.Referral in project OpenAM by OpenRock.
the class ResourceIndexManager method removePolicyFromResourceTree.
/**
* Removes a policy's relevant content from the resource tree.
*
* @param svtm service type manager
* @param token sso token
* @param policy the policy to be removed
*
* @exception PolicyException if unable to get the policy services,
* and will contain the exception thrown by SMS.
* @exception SSOException single-sign-on token invalid or expired
*/
void removePolicyFromResourceTree(ServiceTypeManager svtm, SSOToken token, Policy policy) throws PolicyException, SSOException {
Set ruleNames = policy.getRuleNames();
Iterator iter = ruleNames.iterator();
// iterating through each rule
String ruleName = null;
Rule rule = null;
Set serviceNames = new HashSet();
while (iter.hasNext()) {
ruleName = (String) iter.next();
rule = policy.getRule(ruleName);
String serviceName = rule.getServiceTypeName();
serviceNames.add(serviceName);
ServiceType resourceType = svtm.getServiceType(serviceName);
removeIndexEntry(resourceType, rule.getResourceName(), policy.getName());
}
iter = serviceNames.iterator();
while (iter.hasNext()) {
String serviceName = (String) iter.next();
saveResourceIndex(serviceName);
}
//Process Referrals
Referrals referrals = policy.getReferrals();
if (referrals != null) {
Set referralNames = referrals.getReferralNames();
if ((referralNames != null) && (!referralNames.isEmpty())) {
Iterator referralIter = referralNames.iterator();
while (referralIter.hasNext()) {
String referralName = (String) referralIter.next();
Referral referral = referrals.getReferral(referralName);
if (referral instanceof OrgReferral) {
Set values = referral.getValues();
if ((values != null) && (!values.isEmpty())) {
Iterator valueIter = values.iterator();
while (valueIter.hasNext()) {
Map servicePrefixMap = new HashMap();
String value = (String) valueIter.next();
try {
PolicyManager pm = new PolicyManager(token, value);
ResourceManager rm = pm.getResourceManager();
Iterator ruleIter = policy.getRuleNames().iterator();
while (ruleIter.hasNext()) {
String ruleName1 = (String) ruleIter.next();
Rule rule1 = policy.getRule(ruleName1);
String resourceName = rule1.getResourceName();
if (resourceName != null) {
String service = rule1.getServiceTypeName();
Set resourceNames = (Set) servicePrefixMap.get(service);
if (resourceNames == null) {
resourceNames = new HashSet();
servicePrefixMap.put(service, resourceNames);
}
resourceNames.add(resourceName);
}
}
Iterator serviceIter = servicePrefixMap.keySet().iterator();
while (serviceIter.hasNext()) {
String service = (String) serviceIter.next();
Set resourceNames = (Set) servicePrefixMap.get(service);
rm.removeResourcePrefixes(service, resourceNames);
}
} catch (PolicyException e) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("Could not clean up resource " + " prefixes in referrred to org :" + value + "-" + e.getMessage());
}
}
}
// processed referral value
}
}
}
}
}
}
Aggregations