use of com.sun.identity.liberty.ws.interaction.jaxb.UserInteractionElement in project OpenAM by OpenRock.
the class InteractionManager method getUserInteractionElement.
static UserInteractionElement getUserInteractionElement(Message message) {
UserInteractionElement ue = null;
List list = message.getOtherSOAPHeaders();
try {
list = Utils.convertElementToJAXB(list);
} catch (JAXBException je) {
debug.error("InteractionManager.getUserInteractionElement():" + "not able to get userInteractionElement:" + "can not convert Element to JAXBObject", je);
return null;
}
Iterator iter = list.iterator();
while (iter.hasNext()) {
Object obj = (Object) iter.next();
if (obj instanceof UserInteractionElement) {
ue = (UserInteractionElement) obj;
break;
}
}
return ue;
}
use of com.sun.identity.liberty.ws.interaction.jaxb.UserInteractionElement in project OpenAM by OpenRock.
the class InteractionManager method handleInteraction.
/**
* Handles resource owner interactions on behalf of <code>WSP</code>.
* This is invoked at <code>WSP</code> side.
*
* @param requestMessage SOAP request that requires resource
* owner interactions
* @param inquiryElement query that <code>WSP</code> wants to pose to
* resource owner
* @param language language in which the query page needs to be rendered
* @return SOAP message that contains <code>InteractionResponse</code>,
* gathered by <code>InteractionManager</code>
*
* @throws InteractionException for generic interaction error
* @throws InteractionSOAPFaultException if a SOAP fault
* has to be returned to <code>WSC</code>
* @throws SOAPFaultException if the response message has SOAP fault
*
* @supported.api
*/
public Message handleInteraction(Message requestMessage, InquiryElement inquiryElement, String language) throws InteractionException, InteractionSOAPFaultException, SOAPFaultException {
if (debug.messageEnabled()) {
debug.message("InteractionManager.handleInteraction():entering");
}
//Check redirect is enabled for WSP
if (!interactionConfig.wspSupportsRedirect()) {
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + " WSP requests for interaction:wspWillRedirect=" + interactionConfig.wspSupportsRedirect());
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionException");
}
throw new InteractionException(INTERACTION_RB_NAME, "wsp_does_not_support_interaction", null);
}
//Check wsc provided UserInteraction header
UserInteractionElement ue = getUserInteractionElement(requestMessage);
if (ue == null) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_REQUIRED);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + " WSP requests for interaction - WSC did not " + " provide UserInteractionHeader");
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
//Check WSC is willing to redirect
if (ue.isRedirect() == false) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_REQUIRED);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + "WSP rquests for interaction - WSC " + " says redirect=false");
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
//Check WSC allowed interaction
if (ue.getInteract().equals(QNAME_DO_NOT_INTERACT)) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_REQUIRED);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + "WSP rquests for interaction - WSC " + " UserInteractionHeader says doNotInteract");
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
//Check WSC allowed interaction for data
if (interactionConfig.wspRedirectsForData() && ue.getInteract().equals(QNAME_DO_NOT_INTERACT_FOR_DATA)) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_REQUIRED_FOR_DATA);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + "WSP rquests interaction for data - WSC " + " UserInteractionHeader says doNotInteractForData");
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
//Check WSP will not exceed maxInteractionTime specified by WSC
BigInteger uemi = ue.getMaxInteractTime();
if ((uemi != null) && (interactionConfig.getWSPRedirectTime() > uemi.intValue())) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_TIME_NOT_SUFFICEINT);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + "WSP inteaction time =" + interactionConfig.getWSPRedirectTime() + " exceeds WSC maxInteractTime= " + ue.getMaxInteractTime());
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
String requestMessageID = requestMessage.getCorrelationHeader().getMessageID();
SOAPFaultException sfe = newRedirectFault(requestMessageID);
String redirectResponseID = getResponseID(sfe);
String requestIP = requestMessage.getIPAddress();
String requestHost = null;
if (interactionConfig.wspEnforcesReturnToHostEqualsRequestHost()) {
try {
InetAddress inetAddress = InetAddress.getByName(requestIP);
//requestHost = inetAddress.getCanonicalHostName();
requestHost = inetAddress.getHostName();
if (debug.messageEnabled()) {
debug.message("InteractionManager.handleInteraction():" + " caching requestHost=" + requestHost + ", for redirectResponseID= " + redirectResponseID);
}
setRequestHost(redirectResponseID, requestHost);
} catch (UnknownHostException uhe) {
debug.error("InteractionManager.handleInteraction():" + " can not resolve host name", uhe);
debug.error("InteractionManager.handleInteraction():" + " throwing InteractionSOAPFaultException", sfe);
SOAPFaultException sfe1 = newRedirectFaultError(QNAME_INTERACTION_CAN_NOT_DETERMINE_REQUEST_HOST);
throw new InteractionSOAPFaultException(sfe1);
}
}
setInquiryElement(redirectResponseID, inquiryElement);
setRequestMessageID(redirectResponseID, requestMessageID);
setLanguage(redirectResponseID, language);
if (debug.messageEnabled()) {
debug.message("InteractionManager.handleInteraction():" + " throwing InteractionSOAPFaultException " + " to redirect user agent=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
//return responseMessage;
}
use of com.sun.identity.liberty.ws.interaction.jaxb.UserInteractionElement in project OpenAM by OpenRock.
the class InteractionUtils method getInteractionLangauge.
/**
* Returns languages listed for the language attribute of the
* <code>UserInteraction</code> header in the message. Returns empty list
* if <code>UserInteraction</code> header is not included in the message
*
* @param message SOAP message from which to find out
* interaction languages
*
* @return languages listed for the language attribute of the
* <code>UserInteraction</code> header in the message.
* Returns empty list
* if <code>UserInteraction</code> header is not included
* in the message
*/
public static List getInteractionLangauge(Message message) {
List languages = null;
UserInteractionElement ue = InteractionManager.getUserInteractionElement(message);
if (ue != null) {
languages = ue.getLanguage();
}
if (languages == null) {
languages = Collections.EMPTY_LIST;
}
return languages;
}
use of com.sun.identity.liberty.ws.interaction.jaxb.UserInteractionElement in project OpenAM by OpenRock.
the class InteractionManager method createUserInteractionElement.
private UserInteractionElement createUserInteractionElement(List acceptLanguages) {
UserInteractionElement ue = null;
try {
ue = objectFactory.createUserInteractionElement();
ue.setInteract(interactionConfig.getWSCSpecifiedInteractionChoice());
ue.setRedirect(interactionConfig.wscSupportsRedirect());
ue.setMaxInteractTime(java.math.BigInteger.valueOf(interactionConfig.getWSCSpecifiedMaxInteractionTime()));
ue.getLanguage().addAll(acceptLanguages);
} catch (JAXBException je) {
debug.error("InteractionManager.createUserInteractionElement():" + " can not create UserInteractionElement", je);
}
return ue;
}
use of com.sun.identity.liberty.ws.interaction.jaxb.UserInteractionElement in project OpenAM by OpenRock.
the class InteractionManager method sendRequest.
/**
* Sends SOAP request to <code>WSP</code>.
* This would be invoked at <code>WSC</code> side.
*
* @param requestMessage request message.
* @param connectTo SOAP URL to which to send the SOAP request
* @param certAlias SOAP Client Certificate Alias
* @param soapAction SOAP Action Attribute
* @param returnToURL URL to which to redirect user agent after
* <code>WSP</code> - resource owner interactions
* @param httpRequest HTTP request object of current user agent request
* @param httpResponse HTTP response object of current user agent request
* @return response SOAP response message sent by <code>WSP</code>.
*
* @throws InteractionException for generic interaction error
* @throws InteractionRedirectException if user agent is redirected to
* <code>WSP</code> for resource owner interactions
* @throws SOAPBindingException for generic SOAP binding errors
* @throws SOAPFaultException if the response message has SOAP fault
*
* @supported.api
*/
public Message sendRequest(Message requestMessage, String connectTo, String certAlias, String soapAction, String returnToURL, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws InteractionException, InteractionRedirectException, SOAPBindingException, SOAPFaultException {
if (debug.messageEnabled()) {
debug.message("InteractionManager.sendRequest():" + " entering with messageID=" + requestMessage.getCorrelationHeader().getMessageID() + ":refToMessageID=" + requestMessage.getCorrelationHeader().getRefToMessageID() + ":requestMessage=" + requestMessage);
}
// construct and set UserInteraction element in requestMessage
if (interactionConfig.wscIncludesUserInteractionHeader()) {
Enumeration locales = httpRequest.getLocales();
List acceptLanguages = new ArrayList();
while (locales.hasMoreElements()) {
acceptLanguages.add(locales.nextElement().toString());
}
if (debug.messageEnabled()) {
debug.message("InteractionManager.sendRequest():" + "Accept-Language specified by httpRequest=" + acceptLanguages);
}
UserInteractionElement ue = createUserInteractionElement(acceptLanguages);
String id = SAMLUtils.generateID();
ue.setId(id);
if (ue != null) {
try {
Element element = Utils.convertJAXBToElement(ue);
requestMessage.setOtherSOAPHeader(element, id);
} catch (JAXBException je) {
debug.error("InteractionManager.sendRequest():" + "not setting userInteractionHeader:" + "can not convert JAXBObject to Element", je);
}
}
}
Message responseMessage = null;
try {
if (debug.messageEnabled()) {
debug.message("InteractionManager.sendRequest():" + "invoking soap Client.sendRequest():" + ":requestMessage=" + requestMessage + ":connecTo=" + connectTo);
}
if (LogUtil.isLogEnabled()) {
String[] objs = new String[1];
objs[0] = requestMessage.getCorrelationHeader().getMessageID();
LogUtil.access(Level.INFO, LogUtil.IS_SENDING_MESSAGE, objs);
}
responseMessage = Client.sendRequest(requestMessage, connectTo, certAlias, soapAction);
} catch (SOAPFaultException sfe) {
if (debug.messageEnabled()) {
debug.message("InteractionManager.sendRequest():" + " catching SOAPFaultException=" + sfe);
}
String redirectURL = getRedirectURL(sfe);
if (redirectURL == null) {
throw sfe;
}
String responseID = getResponseID(sfe);
responseMessage = handleRedirectRequest(requestMessage, redirectURL, responseID, connectTo, certAlias, soapAction, returnToURL, httpRequest, httpResponse);
}
if (debug.messageEnabled()) {
debug.message("InteractionManager.sendRequest():" + " returning response message=" + responseMessage);
}
if (LogUtil.isLogEnabled()) {
String[] objs = new String[2];
objs[0] = responseMessage.getCorrelationHeader().getMessageID();
objs[1] = requestMessage.getCorrelationHeader().getMessageID();
LogUtil.access(Level.INFO, LogUtil.IS_RETURNING_RESPONSE_MESSAGE, objs);
}
return responseMessage;
}
Aggregations