use of com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType in project OpenAM by OpenRock.
the class SMDiscoEntryData method setDiscoStr.
public void setDiscoStr(boolean isUserView) throws AMConsoleException {
try {
ResourceOfferingType res = discoFac.createResourceOfferingType();
ResourceIDType rid = discoFac.createResourceIDType();
// if user resource offering then set resource id type.
if (isUserView) {
if ((resourceIdAttribute != null) && resourceIdAttribute.length() > 0) {
rid.setId(resourceIdAttribute);
}
rid.setValue(resourceIdValue);
res.setEntryID(entryId);
} else {
/*
* jaxb api requires that we set resource id value to empty
* string if there is no value so that it will create empty tag
* for Resource ID.
*/
rid.setValue("");
}
ServiceInstanceType svc = createServiceInstanceEntry();
List descriptionTypeList = (List) svc.getDescription();
res.setServiceInstance(svc);
res.setResourceID(rid);
if (abstractValue != null && abstractValue.length() > 0) {
res.setAbstract(abstractValue);
}
if (!noOption) {
res.setOptions(createOptionsEntry());
}
DiscoEntryElement de = entryFac.createDiscoEntryElement();
de.setResourceOffering(res);
createDirectivesEntry(de, descriptionTypeList);
String str = convertDiscoEntryToXmlStr(de);
if (str == null || str.length() == 0) {
throw new AMConsoleException("discoEntryFailed.message");
} else {
discoStr = str;
}
} catch (JAXBException e) {
Throwable t = e.getLinkedException();
String str = (t != null) ? t.getMessage() : e.toString();
throw new AMConsoleException(str);
}
}
use of com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType in project OpenAM by OpenRock.
the class DiscoEntryHandlerImplUtils method handleInserts.
/*
* Adds discovery entries.
* Used by implementations of SPI <code>DiscoEntryHandler</code>:
* <code>UserDiscoEntryHandler</code> and
* <code>UserDynamicEntryHandler</code>.
*
* @param discoEntriesMap Discovery Entries Map.
* @param removes List of entries to be added.
* @return true if the operation is successful; false otherwise.
*/
public static Map handleInserts(Set discoEntries, List inserts) {
/*
* if support proxy:
* look through discoEntries and find all the serviceTypes that have
* proxy proxyServiceTypes
*/
Map insertResults = new HashMap();
insertResults.put(DiscoEntryHandler.STATUS_CODE, DiscoConstants.STATUS_FAILED);
Set supportedDirectives = DiscoServiceManager.getSupportedDirectives();
if (debug.messageEnabled()) {
debug.message("DiscoEntryHandlerImplUtils.handleInserts: " + "size of supportedDirective is " + supportedDirectives.size());
}
Iterator i = inserts.iterator();
InsertEntryType insertEntry = null;
DiscoEntryElement de = null;
ResourceOfferingType resOff = null;
List newEntryIDs = new LinkedList();
while (i.hasNext()) {
insertEntry = (InsertEntryType) i.next();
try {
de = DiscoUtils.getDiscoEntryFactory().createDiscoEntryElement();
} catch (JAXBException je) {
debug.error("DiscoEntryHandlerImplUtils.handleInserts: couldn't " + "create DiscoEntry: ", je);
return insertResults;
}
resOff = insertEntry.getResourceOffering();
String newEntryID = SAMLUtils.generateID();
if (debug.messageEnabled()) {
debug.message("DiscoEntryHandlerImplUtils: newEntryID=" + newEntryID);
}
resOff.setEntryID(newEntryID);
newEntryIDs.add(newEntryID);
de.setResourceOffering(resOff);
List dirs = insertEntry.getAny();
if ((dirs != null) && !dirs.isEmpty()) {
Iterator j = dirs.iterator();
while (j.hasNext()) {
Object dir = j.next();
if (dir instanceof AuthenticateRequesterElement) {
if (!supportedDirectives.contains(DiscoConstants.AUTHN_DIRECTIVE)) {
debug.error("Directive AuthenticateRequester is " + "not supported.");
return insertResults;
}
} else if (dir instanceof AuthorizeRequesterElement) {
if (!supportedDirectives.contains(DiscoConstants.AUTHZ_DIRECTIVE)) {
debug.error("Directive AuthorizeRequester is " + "not supported.");
return insertResults;
}
} else if (dir instanceof AuthenticateSessionContextElement) {
if (!supportedDirectives.contains(DiscoConstants.SESSION_DIRECTIVE)) {
debug.error("Directive AuthenticateSessionContext " + "is not supported.");
return insertResults;
}
} else if (dir instanceof EncryptResourceIDElement) {
if (!supportedDirectives.contains(DiscoConstants.ENCRYPT_DIRECTIVE)) {
debug.error("Directive EncryptResourceID " + "is not supported.");
return insertResults;
}
} else if (dir instanceof GenerateBearerTokenElement) {
if (!supportedDirectives.contains(DiscoConstants.BEARER_DIRECTIVE)) {
debug.error("Directive GenerateBearerToken " + "is not supported.");
return insertResults;
}
} else {
debug.error("Directive " + dir + " is not supported.");
return insertResults;
}
}
de.getAny().addAll(dirs);
}
if (!discoEntries.add(de)) {
debug.error("DiscoEntryHandlerImplUtils.handleInserts: couldn't " + "add DiscoEntry to Set.");
return insertResults;
}
}
insertResults.put(DiscoEntryHandler.STATUS_CODE, DiscoConstants.STATUS_OK);
insertResults.put(DiscoEntryHandler.NEW_ENTRY_IDS, newEntryIDs);
return insertResults;
}
use of com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType in project OpenAM by OpenRock.
the class SMDiscoveryServiceData method setDiscoEntryData.
private static void setDiscoEntryData(DiscoEntryElement entry, SMDiscoEntryData smDisco) {
ResourceOfferingType resOff = entry.getResourceOffering();
ResourceIDType resourceIdType = resOff.getResourceID();
ServiceInstanceType serviceInstance = resOff.getServiceInstance();
String providerID = serviceInstance.getProviderID();
String serviceType = serviceInstance.getServiceType();
smDisco.entryId = resOff.getEntryID();
smDisco.resourceIdAttribute = resourceIdType.getId();
smDisco.resourceIdValue = resourceIdType.getValue();
smDisco.serviceType = serviceType;
smDisco.providerId = providerID;
smDisco.abstractValue = resOff.getAbstract();
OptionsType optType = resOff.getOptions();
if (optType != null) {
smDisco.options = optType.getOption();
smDisco.noOption = false;
} else {
smDisco.noOption = true;
}
List list = serviceInstance.getDescription();
if (list != null && !list.isEmpty()) {
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
SMDescriptionData smDesc = new SMDescriptionData();
DescriptionType desc = (DescriptionType) iter.next();
smDesc.setDescriptionEntry(desc);
smDisco.descData.add(smDesc);
}
} else {
debug.error("SMDiscoveryServiceData.setDiscoEntryData: " + "No description exists in the disco entry");
}
smDisco.directives = getDirectiveEntry(entry);
}
use of com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType 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.jaxb.ResourceOfferingType 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;
}
}
}
Aggregations