use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.
the class EntitlementService method getApplicationConfiguration.
/**
* Get the service config for registered applications.
* @param token The admin token for access to the Service Config.
* @param realm The realm from which to retrieve the service config.
* @return The application Service Config.
*/
private ServiceConfig getApplicationConfiguration(SSOToken token, String realm) {
try {
if (token != null) {
if (realm.startsWith(SMSEntry.SUN_INTERNAL_REALM_PREFIX) || realm.startsWith(SMSEntry.SUN_INTERNAL_REALM_PREFIX2)) {
realm = "/";
}
// TODO. Since applications for the hidden realms have to be
// the same as root realm mainly for delegation without any
// referrals, the hack is to use root realm for hidden realm.
String hackRealm = LDAPUtils.isDN(realm) ? DNMapper.orgNameToRealmName(realm) : realm;
ServiceConfigManager mgr = new ServiceConfigManager(SERVICE_NAME, token);
ServiceConfig orgConfig = mgr.getOrganizationConfig(hackRealm, null);
if (orgConfig != null) {
return orgConfig.getSubConfig(EntitlementUtils.REGISTERED_APPLICATIONS);
}
} else {
PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration, admin token is missing");
}
} catch (ClassCastException ex) {
PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration", ex);
} catch (SMSException ex) {
PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration", ex);
} catch (SSOException ex) {
PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration", ex);
}
return null;
}
use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.
the class EntitlementService method addApplicationAction.
/**
* Adds a new action.
*
* @param appName application name.
* @param name Action name.
* @param defVal Default value.
* @throws EntitlementException if action cannot be added.
*/
public void addApplicationAction(String appName, String name, Boolean defVal) throws EntitlementException {
try {
SSOToken token = SubjectUtils.getSSOToken(getAdminSubject());
if (token == null) {
throw new EntitlementException(226);
}
ServiceConfig applConf = getApplicationSubConfig(token, realm, appName);
if (applConf != null) {
Map<String, Set<String>> data = applConf.getAttributes();
Map<String, Set<String>> result = addAction(data, name, defVal);
if (result != null) {
applConf.setAttributes(result);
}
}
} catch (SMSException ex) {
throw new EntitlementException(221, ex);
} catch (SSOException ex) {
throw new EntitlementException(221, ex);
}
}
use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.
the class EntitlementService method setConfiguration.
private static void setConfiguration(SSOToken token, String attrName, Set<String> values) {
try {
if (token != null) {
ServiceSchemaManager smgr = new ServiceSchemaManager(SERVICE_NAME, token);
AttributeSchema as = smgr.getGlobalSchema().getAttributeSchema(attrName);
if (as != null) {
as.setDefaultValues(values);
}
} else {
PolicyConstants.DEBUG.error("EntitlementService.getAttributeValues: " + "admin token is missing");
}
} catch (SMSException ex) {
PolicyConstants.DEBUG.error("EntitlementService.setAttributeValues", ex);
} catch (SSOException ex) {
PolicyConstants.DEBUG.error("EntitlementService.setAttributeValues", ex);
}
}
use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.
the class DataStore method findPolicies.
private List<Privilege> findPolicies(String realm, String ldapFilter) throws EntitlementException {
List<Privilege> results = new ArrayList<>();
String baseDN = getSearchBaseDN(realm, null);
SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
if (SMSEntry.checkIfEntryExists(baseDN, token)) {
try {
@SuppressWarnings("unchecked") Iterator<SMSDataEntry> iterator = SMSEntry.search(token, baseDN, ldapFilter, NO_LIMIT, NO_LIMIT, NOT_SORTED, NOT_SORTED, emptySet());
while (iterator.hasNext()) {
SMSDataEntry entry = iterator.next();
String policyJson = entry.getAttributeValue(SERIALIZABLE_INDEX_KEY);
results.add(Privilege.getInstance(new JSONObject(policyJson)));
}
} catch (JSONException | SMSException e) {
throw new EntitlementException(EntitlementException.UNABLE_SEARCH_PRIVILEGES, e);
}
}
return results;
}
use of com.sun.identity.sm.SMSException in project OpenAM by OpenRock.
the class DataStore method searchReferral.
/**
* Returns a set of referral privilege that satifies the resource and
* subject indexes.
*
* @param adminToken Subject who has the rights to read datastore.
* @param realm Realm name
* @param iterator Buffered iterator to have the result fed to it.
* @param indexes Resource search indexes.
* @param bSubTree <code>true</code> to do sub tree search
* @param excludeDNs Set of DN to be excluded from the search results.
* @return a set of privilege that satifies the resource and subject
* indexes.
*/
public Set<ReferralPrivilege> searchReferral(SSOToken adminToken, String realm, BufferedIterator iterator, ResourceSearchIndexes indexes, boolean bSubTree, Set<String> excludeDNs) throws EntitlementException {
Set<ReferralPrivilege> results = new HashSet<ReferralPrivilege>();
String filter = getFilter(indexes, null, bSubTree);
String baseDN = getSearchBaseDN(realm, REFERRAL_STORE);
if (PolicyConstants.DEBUG.messageEnabled()) {
PolicyConstants.DEBUG.message("[PolicyEval] DataStore.searchReferral");
PolicyConstants.DEBUG.message("[PolicyEval] search filter: " + filter);
PolicyConstants.DEBUG.message("[PolicyEval] search DN: " + baseDN);
}
if (filter != null) {
SSOToken token = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
long start = DB_MONITOR_REFERRAL.start();
if (SMSEntry.checkIfEntryExists(baseDN, token)) {
try {
Iterator i = SMSEntry.search(token, baseDN, filter, NO_LIMIT, NO_LIMIT, NOT_SORTED, NOT_SORTED, excludeDNs);
while (i.hasNext()) {
SMSDataEntry e = (SMSDataEntry) i.next();
ReferralPrivilege referral = ReferralPrivilege.getInstance(new JSONObject(e.getAttributeValue(SERIALIZABLE_INDEX_KEY)));
iterator.add(referral);
results.add(referral);
}
iterator.isDone();
} catch (JSONException e) {
Object[] arg = { baseDN };
throw new EntitlementException(52, arg, e);
} catch (SMSException e) {
Object[] arg = { baseDN };
throw new EntitlementException(52, arg, e);
}
}
DB_MONITOR_REFERRAL.end(start);
}
return results;
}
Aggregations