use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class SmsRequestHandler method createServices.
/**
* Creates a {@link Router} for all the registered services, and then assigns that router to the instance so that
* it will be used for all future requests.
* @throws SMSException From downstream service manager layer.
* @throws SSOException From downstream service manager layer.
*/
private synchronized void createServices() throws SSOException, SMSException {
Map<String, Map<SmsRouteTree, Set<RouteMatcher<Request>>>> serviceRoutes = new HashMap<>();
ServiceManager sm = getServiceManager();
Set<String> serviceNames = sm.getServiceNames();
for (String serviceName : serviceNames) {
Map<SmsRouteTree, Set<RouteMatcher<Request>>> routes = addService(sm, serviceName, DEFAULT_VERSION);
if (routes != null) {
serviceRoutes.put(serviceName, routes);
}
}
if (schemaType == SchemaType.GLOBAL) {
addServersRoutes(sm, serviceRoutes);
}
this.serviceRoutes = serviceRoutes;
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class AMStoreConnection method getServiceHierarchy.
/**
* Returns the service hierarchy for all registered services.
*
* @return the service hierarchy for all registered services.
* @throws AMException
* if an error is encountered in retrieving the service
* hierarchy. The return value is a Set of strings in slash
* format.
*/
public Set getServiceHierarchy() throws AMException {
try {
Set retSet = new HashSet();
ServiceManager sm = new ServiceManager(token);
Set serviceNames = sm.getServiceNames();
Iterator itr = serviceNames.iterator();
while (itr.hasNext()) {
String st = (String) itr.next();
ServiceSchemaManager scm = new ServiceSchemaManager(st, token);
String sh = scm.getServiceHierarchy();
if ((sh != null) && (sh.length() != 0)) {
retSet.add(sh);
}
}
return retSet;
} catch (SSOException so) {
AMCommonUtils.debug.error("AMStoreConnection.getServiceNames(): ", so);
throw new AMException(AMSDKBundle.getString("902", locale), "902");
} catch (SMSException se) {
AMCommonUtils.debug.error("AMStoreConnection.getServiceNames(): ", se);
throw new AMException(AMSDKBundle.getString("905", locale), "905");
}
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class IdUtils method getOrganization.
/**
* Returns an organization which maps to the identifier used by application
*
* @param orgIdentifier Organization identifier
* @return Organization mapping to that identifier.
*/
public static String getOrganization(SSOToken token, String orgIdentifier) throws IdRepoException, SSOException {
// Check in cache first
String id = null;
if ((id = (String) orgIdentifierToOrgName.get(orgIdentifier)) != null) {
return (id);
}
// Compute the organization name
if (debug.messageEnabled()) {
debug.message("IdUtils:getOrganization Input orgname: " + orgIdentifier);
}
if (orgIdentifier == null || orgIdentifier.length() == 0 || orgIdentifier.equals("/")) {
// Return base DN
id = DNMapper.orgNameToDN("/");
} else if (orgIdentifier.startsWith("/")) {
// If orgIdentifier is in "/" format covert to DN and return
id = DNMapper.orgNameToDN(orgIdentifier);
try {
new OrganizationConfigManager(token, orgIdentifier);
} catch (SMSException e) {
debug.message("IdUtils.getOrganization Exception in getting org name from SMS", e);
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
}
} else if (LDAPUtils.isDN(orgIdentifier)) {
id = orgIdentifier;
try {
// Search for realms with orgIdentifier name
OrganizationConfigManager ocm = new OrganizationConfigManager(token, orgIdentifier);
} catch (SMSException smse) {
// debug message here.
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization Exception in " + "getting org name from SMS", smse);
}
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
}
} else if (ServiceManager.isCoexistenceMode()) {
// Return the org DN as determined by AMStoreConnection
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization: getting from AMSDK");
}
try {
AMStoreConnection amsc = new AMStoreConnection(token);
id = amsc.getOrganizationDN(orgIdentifier, null);
} catch (AMException ame) {
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization Exception in " + "getting org name from AMSDK", ame);
}
throw convertAMException(ame);
}
} else {
// Get the realm name from SMS
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization: getting from " + "SMS realms");
}
try {
boolean foundOrg = false;
ServiceManager sm = new ServiceManager(token);
// First search for realms with orgIdentifier name
OrganizationConfigManager ocm = sm.getOrganizationConfigManager("/");
Set subOrgNames = ocm.getSubOrganizationNames(orgIdentifier, true);
if (subOrgNames != null && !subOrgNames.isEmpty()) {
if (subOrgNames.size() == 1) {
id = DNMapper.orgNameToDN((String) subOrgNames.iterator().next());
foundOrg = true;
} else {
for (Iterator items = subOrgNames.iterator(); items.hasNext(); ) {
// check for orgIdentifier
String subRealmName = (String) items.next();
StringTokenizer st = new StringTokenizer(subRealmName, "/");
// allowed
while (st.hasMoreTokens()) {
if (st.nextToken().equalsIgnoreCase(orgIdentifier)) {
if (!foundOrg) {
id = DNMapper.orgNameToDN(subRealmName);
foundOrg = true;
} else {
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.MULTIPLE_MAPPINGS_FOUND, args);
}
}
}
}
}
}
// Check if organization name has been determined
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization: getting from " + "SMS realms aliases");
}
// perform organization alias search
Set vals = new HashSet();
vals.add(orgIdentifier);
Set orgAliases = sm.searchOrganizationNames(IdConstants.REPO_SERVICE, IdConstants.ORGANIZATION_ALIAS_ATTR, vals);
if (!foundOrg && ((orgAliases == null) || orgAliases.isEmpty())) {
if (debug.warningEnabled()) {
debug.warning("IdUtils.getOrganization Unable" + " to find Org name for: " + orgIdentifier);
}
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
} else if ((orgAliases != null) && (orgAliases.size() > 0) && (foundOrg || orgAliases.size() > 1)) {
// Multiple realms should not have the same alias
if (debug.warningEnabled()) {
debug.warning("IdUtils.getOrganization Multiple " + " matching Orgs found for: " + orgIdentifier);
}
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.MULTIPLE_MAPPINGS_FOUND, args);
}
if (!foundOrg) {
String tmpS = (String) orgAliases.iterator().next();
id = DNMapper.orgNameToDN(tmpS);
}
} catch (SMSException smse) {
// debug message here.
if (debug.messageEnabled()) {
debug.message("IdUtils.getOrganization Exception in " + "getting org name from SMS", smse);
}
Object[] args = { orgIdentifier };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_MAPPING_FOUND, args);
}
}
if (debug.messageEnabled()) {
debug.message("IdUtils:getOrganization Search for OrgIdentifier:" + orgIdentifier + " returning realm DN: " + id);
}
// Add to cache and return id
orgIdentifierToOrgName.put(orgIdentifier, id);
return id;
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class ServiceTypeManager method getServiceTypeNames.
/**
* Returns a set of service names that have policy privileges.
*
* @return set of service type names that have policy privileges
*
* @exception SSOException single-sign-on token has either expired
* or is invalid
* @exception NoPermissionException user does not have privileges
* to access service names
*/
public Set getServiceTypeNames() throws SSOException, NoPermissionException {
SSOTokenManager.getInstance().validateToken(token);
try {
ServiceManager sm = new ServiceManager(token);
Iterator items = sm.getServiceNames().iterator();
// Check if the service names have policy schema
HashSet answer = new HashSet();
while (items.hasNext()) {
String serviceName = (String) items.next();
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
if (ssm.getPolicySchema() != null)
answer.add(serviceName);
} catch (Exception e) {
PolicyManager.debug.error("ServiceTypeManager.getServiceTypeNames:", e);
}
}
return (answer);
} catch (SMSException se) {
throw (new NoPermissionException(se));
}
}
use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.
the class UserIdRepo method registerService.
private void registerService(String xml, SSOToken adminSSOToken) throws SSOException, SMSException, IOException {
ServiceManager serviceManager = new ServiceManager(adminSSOToken);
InputStream serviceStream = null;
try {
serviceStream = (InputStream) new ByteArrayInputStream(xml.getBytes());
serviceManager.registerServices(serviceStream);
} finally {
if (serviceStream != null) {
serviceStream.close();
}
}
}
Aggregations