use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.
the class SMDiscoveryServiceData method getEntries.
/**
* Returns resource offering entry stored in the Directory Server.
*
* @param set Set of entry data.
* @param type Type of offering entry, global, dynamic or user.
* @return resource offering entry stored in the Directory Server.
*/
public static SMDiscoveryServiceData getEntries(Set set, int type) throws AMConsoleException {
SMDiscoveryServiceData smEntry = new SMDiscoveryServiceData();
smEntry.setEntryType(type);
if (set != null && !set.isEmpty()) {
try {
JAXBContext jc = JAXBContext.newInstance(Utils.getJAXBPackages());
Unmarshaller u = jc.createUnmarshaller();
for (Iterator iter = set.iterator(); iter.hasNext(); ) {
String str = (String) iter.next();
SMDiscoEntryData smDisco = new SMDiscoEntryData();
smDisco.discoStr = str;
DiscoEntryElement entry = (DiscoEntryElement) u.unmarshal(XMLUtils.createSAXSource(new InputSource(new StringReader(str))));
setDiscoEntryData(entry, smDisco);
smEntry.addResourceData(smDisco);
}
} catch (JAXBException je) {
debug.error("SMDiscoveryServiceData.getEntries", je);
}
}
return smEntry;
}
use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.
the class DiscoEntryHandlerImplUtils method setGlobalDiscoEntries.
/**
* Registers the discovery service resource offerings to the AMIdentity
*
* This is used by the global disocvery service handler to register
* the resource offerings to the realm, org, role etc.
* @param amIdentity the idrepo object that the resource offerings are
* being set.
* @param attrName the discovery service attribute name where the disco
* entries are being stored.
* @param entries the list of discovery services that needs to be set.
* @return true if successfully set the entries.
*/
public static boolean setGlobalDiscoEntries(AMIdentity amIdentity, String attrName, Collection entries) {
try {
Iterator i = entries.iterator();
Set xmlStrings = new HashSet();
String entryId = null;
StringWriter sw = null;
while (i.hasNext()) {
sw = new StringWriter(1000);
DiscoUtils.getDiscoMarshaller().marshal(((DiscoEntryElement) i.next()), sw);
xmlStrings.add(sw.getBuffer().toString());
}
Map map = new HashMap();
map.put(attrName, xmlStrings);
amIdentity.modifyService("sunIdentityServerDiscoveryService", map);
amIdentity.store();
return true;
} catch (Exception e) {
debug.error("DiscoEntryHandlerImplUtils.setServiceDiscoEntries:" + " Exception", e);
return false;
}
}
use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.
the class AuthnSvcUtils method setResourceOfferingAndCredentials.
/**
* Sets resource offering and credentials to the SASL response based on
* provided sso token.
* @param saslResp a SASL response
* @param message a SOAP message containing a SASL request
* @param userDN Distinguished Name of the User.
* @return <code>true</code> if it sets correctly
*/
public static boolean setResourceOfferingAndCredentials(SASLResponse saslResp, Message message, String userDN) {
try {
DiscoEntryElement discoEntry = (DiscoEntryElement) DiscoServiceManager.getBootstrappingDiscoEntry();
ResourceOfferingType offering = discoEntry.getResourceOffering();
if (!DiscoServiceManager.useImpliedResource()) {
ServiceInstanceType serviceInstance = offering.getServiceInstance();
String providerID = serviceInstance.getProviderID();
ResourceIDMapper idMapper = DiscoServiceManager.getResourceIDMapper(providerID);
if (idMapper == null) {
idMapper = DiscoServiceManager.getDefaultResourceIDMapper();
}
ObjectFactory fac = new com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory();
ResourceIDType resourceID = fac.createResourceIDType();
String resourceIDValue = idMapper.getResourceID(providerID, userDN);
if (AuthnSvcUtils.debug.messageEnabled()) {
AuthnSvcUtils.debug.message("AuthnSvcUtils.setResourceOfferingAndCredentials" + "Offering: ResourceID Value:" + resourceIDValue);
}
resourceID.setValue(resourceIDValue);
offering.setResourceID(resourceID);
} else {
ObjectFactory fac = new com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory();
ResourceIDType resourceID = fac.createResourceIDType();
resourceID.setValue(DiscoConstants.IMPLIED_RESOURCE);
offering.setResourceID(resourceID);
}
List discoEntryList = new ArrayList();
discoEntryList.add(discoEntry);
Map map = DiscoUtils.checkPolicyAndHandleDirectives(userDN, message, discoEntryList, null, null, null, message.getToken());
List offerings = (List) map.get(DiscoUtils.OFFERINGS);
if (offerings.isEmpty()) {
if (AuthnSvcUtils.debug.messageEnabled()) {
AuthnSvcUtils.debug.message("AuthnSvcUtils.setResourceOfferingAndCredentials" + "no ResourceOffering");
}
return false;
}
ResourceOffering ro = (ResourceOffering) offerings.get(0);
saslResp.setResourceOffering(ro);
List assertions = (List) map.get(DiscoUtils.CREDENTIALS);
if ((assertions != null) && (!assertions.isEmpty())) {
Iterator iter = assertions.iterator();
List credentials = new ArrayList();
while (iter.hasNext()) {
SecurityAssertion assertion = (SecurityAssertion) iter.next();
Document doc = XMLUtils.toDOMDocument(assertion.toString(true, true), AuthnSvcUtils.debug);
credentials.add(doc.getDocumentElement());
}
saslResp.setCredentials(credentials);
}
return true;
} catch (Exception ex) {
debug.error("AuthnSvcUtils.setResourceOfferingAndCredentials:", ex);
return false;
}
}
use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.
the class DiscoEntryHandlerImplUtils method getGlobalDiscoEntries.
/**
* This is used by the global disocvery service handler to retrieve
* the resource offerings registered at the realm, org, role etc.
*/
public static void getGlobalDiscoEntries(AMIdentity amIdentity, String attrName, Map discoEntries, String userID) throws Exception {
Map map = amIdentity.getServiceAttributes("sunIdentityServerDiscoveryService");
Set attr = (Set) map.get(attrName);
if (attr == null || attr.isEmpty()) {
debug.error("DiscoEntryHandlerImplUtils.getServiceDiscoEntries: " + "The resource offerings are not available");
return;
}
if (debug.messageEnabled()) {
debug.message("DiscoEntryHandlerImplUtils.getServiceDiscoEntries: " + attr);
}
Iterator j = attr.iterator();
String entryStr = null;
String resIDValue = null;
DiscoEntryElement entry = null;
ResourceIDType resID = null;
ResourceOfferingType resOff = null;
String entryID = null;
String providerID = null;
while (j.hasNext()) {
entryStr = (String) j.next();
try {
entry = (DiscoEntryElement) DiscoUtils.getDiscoUnmarshaller().unmarshal(XMLUtils.createSAXSource(new InputSource(new StringReader(entryStr))));
resOff = entry.getResourceOffering();
entryID = resOff.getEntryID();
if (entryID == null) {
entryID = SAMLUtils.generateID();
resOff.setEntryID(entryID);
}
ResourceIDType rid = resOff.getResourceID();
if ((rid == null) || (rid.getValue() == null) || (rid.getValue().equals(""))) {
com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory discoFac = new com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory();
resID = discoFac.createResourceIDType();
resID.setValue(DiscoConstants.IMPLIED_RESOURCE);
resOff.setResourceID(resID);
}
entry.setResourceOffering(resOff);
discoEntries.put(entryID, entry);
} catch (Exception e) {
debug.error("DiscoEntryHandlerImplUtils.getServiceDiscoEntries:" + " Exception for getting entry: " + entryStr + ":", e);
continue;
}
}
}
use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.
the class DiscoEntryHandlerImplUtils method getQueryResults.
/*
* Finds the matching resource offering according to RequestedServiceType.
* Used by <code>DiscoEntryHandler</code>s.
*
* @param discoEntries all discovery entries
* @param reqServiceTypes List of requested service types
* @return Map of matching discovery entries. In this map,
* key is <code>entryId</code>, value is <code>DiscoEntryElement</code>.
*/
public static Map getQueryResults(Map discoEntries, List reqServiceTypes) {
Map results = null;
if ((reqServiceTypes == null) || (reqServiceTypes.size() == 0)) {
if (debug.messageEnabled()) {
debug.message("DiscoEntryHandlerImplUtils.getQueryResults: " + "no reqServiceTypes");
}
results = discoEntries;
} else {
results = new HashMap();
Iterator i = discoEntries.keySet().iterator();
while (i.hasNext()) {
String curKey = (String) i.next();
DiscoEntryElement cur = (DiscoEntryElement) discoEntries.get(curKey);
ResourceOfferingType offering = cur.getResourceOffering();
String serviceType = offering.getServiceInstance().getServiceType();
List options = null;
if (offering.getOptions() != null) {
options = offering.getOptions().getOption();
}
Iterator j = reqServiceTypes.iterator();
while (j.hasNext()) {
RequestedServiceTypeType curReqType = (RequestedServiceTypeType) j.next();
String requestedServiceType = curReqType.getServiceType();
if (!requestedServiceType.equals(serviceType)) {
continue;
}
List queryOptions = null;
if (curReqType.getOptions() != null) {
queryOptions = curReqType.getOptions().getOption();
}
if (evaluateOptionsRules(queryOptions, options)) {
/* code for proxy support
if (proxyServiceTypes.contains(serviceType)) {
if (this cur is that proxy) {
results.add(cur);
} else if (requester is the provider) {
results.add(cur);
}
} else {
results.add(cur);
}
*/
results.put(curKey, cur);
break;
}
}
}
}
return results;
}
Aggregations