synchronized(context) {
// add special nodes to the authentication block:
// useragent, type and media
Element specialElement;
Text specialValue;
Element authNode;
authNode = (Element)authenticationFragment.getFirstChild();
specialElement = authenticationFragment.getOwnerDocument().createElementNS(null, "useragent");
specialValue = authenticationFragment.getOwnerDocument().createTextNode(request.getHeader("User-Agent"));
specialElement.appendChild(specialValue);
authNode.appendChild(specialElement);
specialElement = authenticationFragment.getOwnerDocument().createElementNS(null, "type");
specialValue = authenticationFragment.getOwnerDocument().createTextNode("cocoon.authentication");
specialElement.appendChild(specialValue);
authNode.appendChild(specialElement);
specialElement = authenticationFragment.getOwnerDocument().createElementNS(null, "media");
specialValue = authenticationFragment.getOwnerDocument().createTextNode(this.mediaType);
specialElement.appendChild(specialValue);
authNode.appendChild(specialElement);
// store the authentication data in the context
context.setXML("/" + myHandler.getName(), authenticationFragment);
// Now create the return value for this method:
// <code>null</code>
authenticationFragment = null;
// And now load applications
boolean loaded = true;
Iterator applications = myHandler.getApplications().values().iterator();
ApplicationHandler appHandler;
while (applications.hasNext() == true) {
appHandler = (ApplicationHandler)applications.next();
if (appHandler.getLoadOnDemand() == false) {
this.loadApplicationXML((SessionContextImpl)this.getSessionManager().getContext(AuthenticationConstants.SESSION_CONTEXT_NAME),
appHandler, "/");
} else {
loaded = appHandler.getIsLoaded();
}
}
myHandler.setApplicationsLoaded(loaded);
} // end sync
}
}
if (isValid == false) {
if (this.getLogger().isInfoEnabled() == true) {
this.getLogger().info("AuthenticationManager: Failed authentication using handler '" + myHandler.getName()+"'");
}
// get the /authentication/data Node if available
Node data = null;
if (authenticationFragment != null) {
data = DOMUtil.getFirstNodeFromPath(authenticationFragment, new String[] {"authentication","data"}, false);
}
// now create the following xml:
// <failed/>
// if data is available data is included, otherwise:
// <data>No information</data>
// If exception message contains info, it is included into failed
Document doc = DOMUtil.createDocument();
authenticationFragment = doc.createDocumentFragment();
Element element = doc.createElementNS(null, "failed");
authenticationFragment.appendChild(element);
if (exceptionMsg != null) {
Text text = doc.createTextNode(exceptionMsg);
element.appendChild(text);
}
if (data == null) {
element = doc.createElementNS(null, "data");
authenticationFragment.appendChild(element);
Text text = doc.createTextNode("No information");
element.appendChild(text);
} else {
authenticationFragment.appendChild(doc.importNode(data, true));
}