use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class XWikiRightServiceImpl method checkAccess.
@Override
public boolean checkAccess(String action, XWikiDocument doc, XWikiContext context) throws XWikiException {
LOGGER.debug("checkAccess for [{}], [{}]", action, doc);
String username = null;
XWikiUser user = null;
boolean needsAuth = false;
String right = getRight(action);
if (right.equals("login")) {
user = context.getWiki().checkAuth(context);
if (user == null) {
username = XWikiRightService.GUEST_USER_FULLNAME;
} else {
username = user.getUser();
}
// Save the user
context.setUser(username);
logAllow(username, doc.getFullName(), action, "login/logout pages");
return true;
}
if (right.equals("delete")) {
user = context.getWiki().checkAuth(context);
String creator = doc.getCreator();
if ((user != null) && (user.getUser() != null) && (creator != null)) {
if (user.getUser().equals(creator)) {
context.setUser(user.getUser());
return true;
}
}
}
// We do not need to authenticate twice
// This seems to cause a problem in virtual wikis
user = context.getXWikiUser();
if (user == null) {
needsAuth = needsAuth(right, context);
try {
if (context.getMode() != XWikiContext.MODE_XMLRPC) {
user = context.getWiki().checkAuth(context);
} else {
user = new XWikiUser(context.getUser());
}
if ((user == null) && (needsAuth)) {
logDeny("unauthentified", doc.getFullName(), action, "Authentication needed");
if (context.getRequest() != null) {
if (!context.getWiki().Param("xwiki.hidelogin", "false").equalsIgnoreCase("true")) {
context.getWiki().getAuthService().showLogin(context);
}
}
return false;
}
} catch (XWikiException e) {
if (needsAuth) {
throw e;
}
}
if (user == null) {
username = XWikiRightService.GUEST_USER_FULLNAME;
} else {
username = user.getUser();
}
// Save the user
context.setUser(username);
} else {
username = user.getUser();
}
// Check Rights
try {
// Verify access rights and return if ok
String docname;
if (context.getWikiId() != null) {
docname = context.getWikiId() + ":" + doc.getFullName();
if (username.indexOf(":") == -1) {
username = context.getWikiId() + ":" + username;
}
} else {
docname = doc.getFullName();
}
if (context.getWiki().getRightService().hasAccessLevel(right, username, docname, context)) {
logAllow(username, docname, action, "access manager granted right");
return true;
}
} catch (Exception e) {
// This should not happen..
logDeny(username, doc.getFullName(), action, "access manager exception " + e.getMessage());
e.printStackTrace();
return false;
}
if (user == null) {
// Denied Guest need to be authenticated
logDeny("unauthentified", doc.getFullName(), action, "Guest has been denied");
if (context.getRequest() != null && !context.getWiki().Param("xwiki.hidelogin", "false").equalsIgnoreCase("true")) {
context.getWiki().getAuthService().showLogin(context);
}
return false;
} else {
logDeny(username, doc.getFullName(), action, "access manager denied right");
return false;
}
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class EditAction method render.
@Override
public String render(XWikiContext context) throws XWikiException {
try {
XWikiDocument editedDocument = prepareEditedDocument(context);
maybeLockDocument(editedDocument, context);
} catch (XWikiException e) {
if (e.getCode() == XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY) {
context.put("exception", e);
return "docalreadyexists";
} else {
throw e;
}
}
// Make sure object property fields are displayed in edit mode.
// See XWikiDocument#display(String, BaseObject, XWikiContext)
// TODO: Revisit the display mode after the inline action is removed. Is the display mode still needed when
// there is only one edit action?
context.put("display", "edit");
return "edit";
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class ExportAction method render.
@Override
public String render(XWikiContext context) throws XWikiException {
String defaultPage;
try {
XWikiRequest request = context.getRequest();
String format = request.get("format");
if ((format == null) || (format.equals("xar"))) {
defaultPage = exportXAR(context);
} else if (format.equals("html")) {
defaultPage = exportHTML(context);
} else {
defaultPage = export(format, context);
}
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_EXPORT, "Exception while exporting", e);
}
return defaultPage;
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class ExportAction method exportXAR.
private String exportXAR(XWikiContext context) throws XWikiException, IOException, FilterException {
XWikiRequest request = context.getRequest();
boolean history = Boolean.valueOf(request.get("history"));
boolean backup = Boolean.valueOf(request.get("backup"));
String author = request.get("author");
String description = request.get("description");
String licence = request.get("licence");
String version = request.get("version");
String name = request.get("name");
String[] pages = request.getParameterValues("pages");
boolean all = ArrayUtils.isEmpty(pages);
if (!context.getWiki().getRightService().hasWikiAdminRights(context)) {
context.put("message", "needadminrights");
return "exception";
}
if (StringUtils.isEmpty(name)) {
if (all) {
name = "backup";
} else {
name = "export";
}
}
if (context.getWiki().ParamAsLong("xwiki.action.export.xar.usefilter", 1) == 1) {
// Create input wiki stream
DocumentInstanceInputProperties inputProperties = new DocumentInstanceInputProperties();
// We don't want to log the details
inputProperties.setVerbose(false);
inputProperties.setWithJRCSRevisions(history);
inputProperties.setWithRevisions(false);
EntityReferenceSet entities = new EntityReferenceSet();
if (all) {
entities.includes(new WikiReference(context.getWikiId()));
} else {
// Find all page references and add them for processing
Collection<DocumentReference> pageList = resolvePagesToExport(pages, context);
for (DocumentReference page : pageList) {
entities.includes(page);
}
}
inputProperties.setEntities(entities);
InputFilterStreamFactory inputFilterStreamFactory = Utils.getComponent(InputFilterStreamFactory.class, FilterStreamType.XWIKI_INSTANCE.serialize());
InputFilterStream inputFilterStream = inputFilterStreamFactory.createInputFilterStream(inputProperties);
// Create output wiki stream
XAROutputProperties xarProperties = new XAROutputProperties();
// We don't want to log the details
xarProperties.setVerbose(false);
XWikiResponse response = context.getResponse();
xarProperties.setTarget(new DefaultOutputStreamOutputTarget(response.getOutputStream()));
xarProperties.setPackageName(name);
if (description != null) {
xarProperties.setPackageDescription(description);
}
if (licence != null) {
xarProperties.setPackageLicense(licence);
}
if (author != null) {
xarProperties.setPackageAuthor(author);
}
if (version != null) {
xarProperties.setPackageVersion(version);
}
xarProperties.setPackageBackupPack(backup);
xarProperties.setPreserveVersion(backup || history);
BeanOutputFilterStreamFactory<XAROutputProperties> xarFilterStreamFactory = Utils.getComponent((Type) OutputFilterStreamFactory.class, FilterStreamType.XWIKI_XAR_CURRENT.serialize());
OutputFilterStream outputFilterStream = xarFilterStreamFactory.createOutputFilterStream(xarProperties);
// Export
response.setContentType("application/zip");
response.addHeader("Content-disposition", "attachment; filename=" + Util.encodeURI(name, context) + ".xar");
inputFilterStream.read(outputFilterStream.getFilter());
inputFilterStream.close();
outputFilterStream.close();
// Flush
response.getOutputStream().flush();
// Indicate that we are done with the response so no need to add anything
context.setFinished(true);
} else {
PackageAPI export = ((PackageAPI) context.getWiki().getPluginApi("package", context));
if (export == null) {
// No Packaging plugin configured
return "exception";
}
export.setWithVersions(history);
if (author != null) {
export.setAuthorName(author);
}
if (description != null) {
export.setDescription(description);
}
if (licence != null) {
export.setLicence(licence);
}
if (version != null) {
export.setVersion(version);
}
export.setBackupPack(backup);
export.setName(name);
if (all) {
export.backupWiki();
} else {
if (pages != null) {
for (String pageName : pages) {
String defaultAction = request.get("action_" + pageName);
int iAction;
try {
iAction = Integer.parseInt(defaultAction);
} catch (Exception e) {
iAction = 0;
}
export.add(pageName, iAction);
}
}
export.export();
}
}
return null;
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class R40000XWIKI6990DataMigration method getLiquibaseChangeLog.
@Override
public String getLiquibaseChangeLog() throws DataMigrationException {
final XWikiHibernateBaseStore store = getStore();
this.configuration = store.getConfiguration();
final StringBuilder sb = new StringBuilder(12000);
final List<PersistentClass> classes = new ArrayList<PersistentClass>();
detectDatabaseProducts(store);
if (this.logger.isDebugEnabled()) {
if (this.isOracle) {
this.logger.debug("Oracle database detected, proceeding to all updates manually with deferred constraints.");
}
if (this.isMySQL && !this.isMySQLMyISAM) {
this.logger.debug("MySQL innoDB database detected, proceeding to simplified updates with cascaded updates.");
}
if (this.isMySQLMyISAM) {
this.logger.debug("MySQL MyISAM database detected, proceeding to all updates manually without constraints.");
}
if (this.isMSSQL) {
this.logger.debug("Microsoft SQL Server database detected, proceeding to simplified updates with cascaded u" + "pdates. During data type changes, Primary Key constraints and indexes are temporarily dropped.");
}
}
// Build the list of classes to check for updates
classes.add(getClassMapping(BaseObject.class.getName()));
for (Class<?> klass : PROPERTY_CLASS) {
classes.add(getClassMapping(klass.getName()));
}
for (Class<?> klass : STATS_CLASSES) {
classes.add(getClassMapping(klass.getName()));
}
// Initialize the counter of Change Logs
this.logCount = 0;
// do not prevent type changes, we skip all this processing for MySQL table stored using the MyISAM engine.
if (!this.isMySQLMyISAM) {
for (PersistentClass klass : classes) {
this.fkTables.addAll(getForeignKeyTables(klass));
}
}
// Drop all FK constraints
for (Table table : this.fkTables) {
appendDropForeignKeyChangeLog(sb, table);
}
// Process internal classes
for (PersistentClass klass : classes) {
// The same table mapped for StringListProperty and LargeStringProperty
if (klass.getMappedClass() != StringListProperty.class) {
// Update key types
appendDataTypeChangeLogs(sb, klass);
}
}
// Process dynamic and custom mapping
final XWikiContext context = getXWikiContext();
try {
processCustomMappings((XWikiHibernateStore) store, new CustomMappingCallback() {
@Override
public void processCustomMapping(XWikiHibernateStore store, String name, String mapping, boolean hasDynamicMapping) throws XWikiException {
if (INTERNAL.equals(mapping) || hasDynamicMapping) {
PersistentClass klass = R40000XWIKI6990DataMigration.this.configuration.getClassMapping(name);
if (!R40000XWIKI6990DataMigration.this.isMySQLMyISAM) {
List<Table> tables = getForeignKeyTables(klass);
for (Table table : tables) {
if (!R40000XWIKI6990DataMigration.this.fkTables.contains(table)) {
// Drop FK constraints for custom mapped class
appendDropForeignKeyChangeLog(sb, table);
R40000XWIKI6990DataMigration.this.fkTables.add(table);
}
}
}
// Update key types for custom mapped class
appendDataTypeChangeLogs(sb, klass);
}
}
}, context);
} catch (XWikiException e) {
throw new DataMigrationException("Unable to process custom mapped classes during schema updated", e);
}
// Add FK constraints back, activating cascaded updates
for (Table table : this.fkTables) {
appendAddForeignKeyChangeLog(sb, table);
}
// Oracle doesn't support cascaded updates, so we still need to manually update each table
if (this.isOracle) {
this.fkTables.clear();
}
logProgress("%d schema updates required.", this.logCount);
if (this.logger.isDebugEnabled()) {
this.logger.debug("About to execute this Liquibase XML: {}", sb.toString());
}
return sb.toString();
}
Aggregations