parameters,
this.resolver);
doc = org.apache.cocoon.components.source.SourceUtil.toDOM(source);
} catch (SAXException se) {
throw new ProcessingException(se);
} catch (SourceException se) {
throw org.apache.cocoon.components.source.SourceUtil.handle(se);
} catch (IOException e) {
throw new ProcessingException(e);
} finally {
this.resolver.release(source);
}
} catch (ProcessingException local) {
this.getLogger().error("authenticator: " + local.getMessage(), local);
exceptionMsg = local.getMessage();
}
// test if authentication was successful
boolean isValid = false;
UserHandler handler = null;
if (doc != null) {
isValid = this.isValidAuthenticationFragment( doc );
if ( isValid ) {
if (this.getLogger().isInfoEnabled() ) {
this.getLogger().info("Authenticator: User authenticated using handler '" + configuration.getName()+"'");
}
handler = new UserHandler(configuration);
SessionContext context = handler.getContext();
MediaManager mediaManager = null;
String mediaType;
try {
mediaManager = (MediaManager)this.manager.lookup( MediaManager.ROLE );
mediaType = mediaManager.getMediaType();
} catch (ServiceException se) {
throw new ProcessingException("Unable to lookup media manager.", se);
} finally {
this.manager.release( mediaManager );
}
synchronized(context) {
// add special nodes to the authentication block:
// useragent, type and media
Element specialElement;
Text specialValue;
Element authNode;
authNode = (Element)doc.getFirstChild();
specialElement = doc.createElementNS(null, "type");
specialValue = doc.createTextNode("cocoon.authentication");
specialElement.appendChild(specialValue);
authNode.appendChild(specialElement);
specialElement = doc.createElementNS(null, "media");
specialValue = doc.createTextNode(mediaType);
specialElement.appendChild(specialValue);
authNode.appendChild(specialElement);
// store the authentication data in the context
context.setNode("/" + configuration.getName(), doc);
// And now load applications
boolean loaded = true;
Iterator applications = configuration.getApplications().values().iterator();
while ( applications.hasNext() ) {
ApplicationConfiguration appHandler = (ApplicationConfiguration)applications.next();
if ( !appHandler.getLoadOnDemand() ) {
handler.getContext().loadApplicationXML( appHandler, this.resolver );
} else {
loaded = false;
}
}
} // end sync
}
}
if ( !isValid ) {
if (this.getLogger().isInfoEnabled() ) {
this.getLogger().info("Authenticator: Failed authentication using handler '" + configuration.getName()+"'");
}
// get the /authentication/data Node if available
Node data = null;
if (doc != null) {
data = DOMUtil.getFirstNodeFromPath(doc, 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
DocumentFragment 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));
}
// now set this information in the temporary context
SessionManager sessionManager = null;
try {
sessionManager = (SessionManager) this.manager.lookup( SessionManager.ROLE );
SessionContext temp = sessionManager.getContext( SessionConstants.TEMPORARY_CONTEXT );
temp.appendXML("/", authenticationFragment);
} catch ( ServiceException se ) {
throw new ProcessingException("Unable to lookup session manager.", se);
} finally {
this.manager.release( sessionManager );
}
}