protected UsecaseMessage[] getErrorMessages(Tab tab) {
UsecaseMessage[] messages;
ServiceSelector selector = null;
AccessControllerResolver acResolver = null;
AccessController accessController = null;
UsecaseResolver usecaseResolver = null;
UsecaseAuthorizer authorizer = null;
try {
selector = (ServiceSelector) this.manager.lookup(AccessControllerResolver.ROLE
+ "Selector");
acResolver = (AccessControllerResolver) selector.select(AccessControllerResolver.DEFAULT_RESOLVER);
accessController = acResolver.resolveAccessController(this.webappUrl);
Authorizer[] authorizers = accessController.getAuthorizers();
for (int i = 0; i < authorizers.length; i++) {
if (authorizers[i] instanceof UsecaseAuthorizer) {
authorizer = (UsecaseAuthorizer) authorizers[i];
}
}
usecaseResolver = (UsecaseResolver) this.manager.lookup(UsecaseResolver.ROLE);
// filter item if usecase not allowed
if (tab.getUsecase() != null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Found usecase [" + tab.getUsecase() + "]");
}
DocumentFactory factory;
ContextUtility util = null;
try {
util = (ContextUtility) this.manager.lookup(ContextUtility.ROLE);
Request request = util.getRequest();
factory = DocumentUtil.getDocumentFactory(this.manager, request);
} finally {
if (util != null) {
this.manager.release(util);
}
}
Publication pub = PublicationUtil.getPublicationFromUrl(this.manager,
factory,
this.webappUrl);
if (!authorizer.authorizeUsecase(tab.getUsecase(), this.roles, pub)) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Usecase not authorized");
}
messages = new UsecaseMessage[1];
messages[0] = new UsecaseMessage("Access denied");
}
}
if (usecaseResolver.isRegistered(this.webappUrl, tab.getUsecase())) {
Usecase usecase = null;
try {
usecase = usecaseResolver.resolve(this.webappUrl, tab.getUsecase());
usecase.setSourceURL(this.webappUrl);
usecase.setName(tab.getUsecase());
String[] keys = tab.getParameterNames();
for (int i = 0; i < keys.length; i++) {
usecase.setParameter(keys[i], tab.getParameter(keys[i]));
}
usecase.checkPreconditions();
if (usecase.hasErrors()) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Usecase preconditions not complied");
}
List msgs = usecase.getErrorMessages();
messages = (UsecaseMessage[]) msgs.toArray(new UsecaseMessage[msgs.size()]);
} else {
messages = new UsecaseMessage[0];
}
} finally {
if (usecase != null) {
usecaseResolver.release(usecase);
}
}
} else {
messages = new UsecaseMessage[1];
messages[0] = new UsecaseMessage("Usecase [" + tab.getUsecase()
+ "] is not registered!", null);
}
} catch (final Exception e) {
throw new RuntimeException(e);
} finally {
if (usecaseResolver != null) {
this.manager.release(usecaseResolver);
}
if (selector != null) {
if (acResolver != null) {
if (accessController != null) {
acResolver.release(accessController);
}
selector.release(acResolver);
}
this.manager.release(selector);
}