use of com.sun.identity.liberty.ws.disco.DiscoveryException in project OpenAM by OpenRock.
the class LibertyManagerClient method getDiscoveryResourceOffering.
/**
* Returns the discovery service bootstrap resource offering.
* @param token Single Sign On Token.
* @param hostProviderID Hosted <code>ProviderID</code>.
* @return <code>ResourceOffering</code> Discovery Service bootstrap
* resource offering.
* @exception FSException if any failure.
*/
public ResourceOffering getDiscoveryResourceOffering(Object token, String hostProviderID) throws FSException {
try {
SessionProvider sessionProvider = SessionManager.getProvider();
String tokenID = sessionProvider.getSessionID(token);
String cacheKey = tokenID + DISCO_RO;
ResourceOffering ro = (ResourceOffering) bootStrapCache.get(cacheKey);
if (ro != null) {
return ro;
}
String[] objs = { tokenID, hostProviderID };
String resourceOffering = (String) client.send("getDiscoveryResourceOffering", objs, null, null);
if ((resourceOffering == null) || (resourceOffering.length() == 0)) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ResourceOffering: ResouceOffering is null or empty");
}
return null;
}
Document doc = XMLUtils.toDOMDocument(resourceOffering, FSUtils.debug);
ro = new ResourceOffering(doc.getDocumentElement());
sessionProvider.addListener(token, new LibertyClientSSOTokenListener());
bootStrapCache.put(cacheKey, ro);
return ro;
} catch (SessionException se) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ResourceOffering: InvalidSessionToken", se);
}
throw new FSException(FSUtils.bundle.getString("invalidSSOToken"));
} catch (DiscoveryException de) {
FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ResourceOffering: Invalid ResourceOffering", de);
throw new FSException(FSUtils.bundle.getString("invalidResourceOffering"));
} catch (Exception ex) {
FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ResourceOffering: SOAPClient Exception", ex);
throw new FSException(FSUtils.bundle.getString("soapException"));
}
}
use of com.sun.identity.liberty.ws.disco.DiscoveryException in project OpenAM by OpenRock.
the class GlobalDiscoEntryHandler method modifyDiscoEntries.
/**
* Modify DiscoEntries for the default organization.
* @param userID This is not used in this implementation.
*
* @param removes List of
* com.sun.identity.liberty.ws.disco.jaxb.RemoveEntryType jaxb
* objects.
* @param inserts List of
* com.sun.identity.liberty.ws.disco.jaxb.InsertEntryType jaxb
* objects.
* @return Map which contains the following key value pairs:
* Key: <code>DiscoEntryHandler.STATUS_CODE</code>
* Value: status code String such as "OK", "Failed", etc.
* Key: <code>DiscoEntryHandler.NEW_ENTRY_IDS</code>
* Value: List of entryIds for the entries that were added.
* The second key/value pair will only exist when status code is
* "OK", and there are InsertEntry elements in the Modify request.
* When successful, all modification (removes and inserts) should
* be done. No partial changes should be done.
*/
public Map modifyDiscoEntries(String userID, List removes, List inserts) {
if (DiscoUtils.debug.messageEnabled()) {
DiscoUtils.debug.message("GlobalDiscoEntryHandler.modifyDisco" + "Entries: init ");
}
Map result = new HashMap();
result.put(STATUS_CODE, DiscoConstants.STATUS_FAILED);
Map discoEntries = new HashMap();
try {
// Try to register discovery service if not already registered
registerDiscoveryService();
AMIdentity amId = getRealmIdentity();
DiscoEntryHandlerImplUtils.getGlobalDiscoEntries(getRealmIdentity(), DYNAMIC_ATTR_NAME, discoEntries, userID);
if ((removes != null) && (removes.size() != 0)) {
if (!DiscoEntryHandlerImplUtils.handleRemoves(discoEntries, removes)) {
return result;
}
}
Set entries = new HashSet();
entries.addAll(discoEntries.values());
List newEntryIDs = null;
if ((inserts != null) && (inserts.size() != 0)) {
Map insertResults = DiscoEntryHandlerImplUtils.handleInserts(entries, inserts);
if (!((String) insertResults.get(STATUS_CODE)).equals(DiscoConstants.STATUS_OK)) {
return result;
}
newEntryIDs = (List) insertResults.get(NEW_ENTRY_IDS);
}
if (!DiscoEntryHandlerImplUtils.setGlobalDiscoEntries(amId, DYNAMIC_ATTR_NAME, entries)) {
return result;
} else {
result.put(STATUS_CODE, DiscoConstants.STATUS_OK);
if ((newEntryIDs != null) && (newEntryIDs.size() != 0)) {
result.put(NEW_ENTRY_IDS, newEntryIDs);
}
return result;
}
} catch (DiscoveryException de) {
DiscoUtils.debug.error("GlobalDiscoEntryHandler.modify" + "DiscoEntries: Exception", de);
return result;
} catch (Exception ex) {
DiscoUtils.debug.error("GlobalDiscoEntryHandler.modify" + "DiscoEntries: Exception", ex);
return result;
}
}
use of com.sun.identity.liberty.ws.disco.DiscoveryException in project OpenAM by OpenRock.
the class GlobalDiscoEntryHandler method getRealmIdentity.
/**
* Returns the default realm identity object.
*/
private static synchronized AMIdentity getRealmIdentity() throws DiscoveryException {
try {
SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
AMIdentityRepository idRepo = new AMIdentityRepository(adminToken, "/");
return idRepo.getRealmIdentity();
} catch (IdRepoException ire) {
DiscoUtils.debug.error("GlobalDiscoEntryHandler.getRealm" + "Identity: Initialization failed", ire);
throw new DiscoveryException(ire.getMessage());
} catch (SSOException se) {
DiscoUtils.debug.error("GlobalDiscoEntryHandler.getRealm" + "Identity: SSOException ", se);
throw new DiscoveryException(se.getMessage());
}
}
use of com.sun.identity.liberty.ws.disco.DiscoveryException in project OpenAM by OpenRock.
the class GlobalDiscoEntryHandler method registerDiscoveryService.
/**
* This method registers the Discovery Service to the root realm if
* the service is not already registered.
*/
private static void registerDiscoveryService() throws DiscoveryException {
try {
AMIdentity amId = getRealmIdentity();
Set assignedServices = amId.getAssignedServices();
if (assignedServices != null && assignedServices.contains(DISCO_SERVICE)) {
return;
}
amId.assignService(DISCO_SERVICE, null);
} catch (IdRepoException ire) {
DiscoUtils.debug.error("GlobalDiscoEntryHandler.register" + "DiscoveryService: Exception", ire);
throw new DiscoveryException(ire.getMessage());
} catch (SSOException se) {
DiscoUtils.debug.error("GlobalDiscoEntryHandler.register" + "DiscoveryService: Exception", se);
throw new DiscoveryException(se.getMessage());
}
}
use of com.sun.identity.liberty.ws.disco.DiscoveryException in project OpenAM by OpenRock.
the class DiscoSDKUtils method parseStatus.
/**
* Parses Status element.
* @param elem Status element.
* @return Status object.
* @exception DiscoveryException if error occurs.
*/
public static Status parseStatus(org.w3c.dom.Element elem) throws DiscoveryException {
if (elem == null) {
debug.message("DiscoUtils.parseStatus: nullInput");
throw new DiscoveryException(bundle.getString("nullInput"));
}
String nameSpaceURI = elem.getNamespaceURI();
String prefix = elem.getPrefix();
Status status = new Status(nameSpaceURI, prefix);
String code = elem.getAttribute("code");
if ((code == null) || (code.length() == 0)) {
debug.message("DiscoUtils.parseStatus: missing status code.");
throw new DiscoveryException(bundle.getString("missingStatusCode"));
}
String codeNS = nameSpaceURI;
String codePrefix = prefix;
String localPart = code;
if (code.indexOf(":") != -1) {
StringTokenizer st = new StringTokenizer(code, ":");
if (st.countTokens() != 2) {
debug.message("DiscoUtils.parseStatus: wrong status code.");
throw new DiscoveryException(bundle.getString("wrongInput"));
}
codePrefix = st.nextToken();
localPart = st.nextToken();
}
if ((codePrefix != null) && (prefix != null) && (!codePrefix.equals(prefix))) {
codeNS = elem.getAttribute("xmlns:" + codePrefix);
}
if ((codeNS != null) && (codeNS.length() != 0)) {
if ((codePrefix != null) && (codePrefix.length() != 0)) {
status.setCode(new QName(codeNS, localPart, codePrefix));
} else {
status.setCode(new QName(codeNS, localPart));
}
} else {
status.setCode(new QName(localPart));
}
status.setComment(elem.getAttribute("comment"));
status.setRef(elem.getAttribute("ref"));
List subStatusL = XMLUtils.getElementsByTagNameNS1(elem, DiscoConstants.DISCO_NS, "Status");
int num = subStatusL.size();
if (num != 0) {
if (num == 1) {
status.setSubStatus(parseStatus((Element) subStatusL.get(0)));
} else {
if (debug.messageEnabled()) {
debug.message("DiscoUtils.parseStatus: included more than " + "one sub status.");
}
throw new DiscoveryException(bundle.getString("moreElement"));
}
}
return status;
}
Aggregations