Hey guys,
I'm really confused. I allready had a question with a simular question (https://answers.atlassian.com/questions/18810508).
I want to restrict a page to some specific users with my plugin - which is no problem now, but I get nullpointers if I want to remove all restrictions to restrict the page to other users or open in to all which has the space permission.
If you know how to remove this please help me!
the code:
public void removePageRestriciton(Page page) { try { List<ContentPermission> toDeleteEdit = new ArrayList<ContentPermission>(); List<ContentPermission> toDeleteView = new ArrayList<ContentPermission>(); if (conPerMan.getContentPermissionSets(page, ContentPermission.EDIT_PERMISSION) != null) { for (ContentPermission cp : page .getContentPermissionSet(ContentPermission.EDIT_PERMISSION)) { toDeleteEdit.add(cp); } for (ContentPermission cp : toDeleteEdit) { conPerMan.removeContentPermission(cp); } } if (conPerMan.getContentPermissionSets(page, ContentPermission.VIEW_PERMISSION) != null) { for (ContentPermission cp : page .getContentPermissionSet(ContentPermission.VIEW_PERMISSION)) { toDeleteView.add(cp); } for (ContentPermission cp : toDeleteView) { conPerMan.removeContentPermission(cp); } } System.out.println("RESTRICTION REMOVED: " + page.getId()); } catch (Exception e) { System.out.println("CATCH REMOVE RESTRICTION"); e.printStackTrace(); } }
the error:
[com.atlassian.hibernate.HibernateObjectDao] remove remove error! org.springframework.orm.hibernate.HibernateSystemException: not-null property references a null or transient value: com.atlassian.confluence.security.ContentPermission.owningSet; nested exception is net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: com.atlassian.confluence.security.ContentPermission.owningSet
It would be great if u would or could help me!
Best regards from Germany!
Community moderators have prevented the ability to post new answers.
Maybe try not to access ContentPermisionSets directly from page. Use contentPermissionManager instead.
Try this and see if it works
List<ContentPermissionSet> permSetList = contentPermissionManager.getContentPermissionSets(page, ContentPermission.VIEW_PERMISSION); for (ContentPermissionSet permSet : permSetList) { List<ContentPermission> toRemove = new ArrayList<ContentPermission>(); for (ContentPermission perm : permSet) toRemove.add(perm); for (ContentPermission perm : toRemove) contentPermissionManager.removeContentPermission(perm); }
I was facing the same issue earlier today when trying to reset all view permissions on a page, and setting the permissions based on a dialog I injected on the editor save button. I tried different approaches which led me to either the not-null-property exception thrown by Hibernate, or a java.util.ConcurrentModificationException when removing a permission via ContentPermissionManagers removePermission() method while iterating through a ContentPermissionSet.
I finally ended up managing to reset the permissions on a two-step approach:
List<ContentPermissionSet> setList = contentPermissionManager.getContentPermissionSets(pageToUpdate, ContentPermission.VIEW_PERMISSION); List<ContentPermission> toDelete = new LinkedList<ContentPermission>(); log.debug("total sets: " + setList.size()); for( ContentPermissionSet set: setList ){ log.debug("in set: " + set + ": " + set.size()); for( ContentPermission perm: set ){ log.debug("perm: " + perm); toDelete.add(perm); } } log.debug("removing permissions..."); for(ContentPermission perm: toDelete ){ log.debug("trying to remove: " + perm); contentPermissionManager.removeContentPermission(perm); log.debug("removed."); } //checking to see if all permissions have been removed properly setList = contentPermissionManager.getContentPermissionSets(pageToUpdate, ContentPermission.VIEW_PERMISSION); log.debug("total sets: " + setList.size());
Note that
I haven't encountered an exception so far, so this seems to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Its still the code above - but i also get a not-null-property exception if it code this:
public void removePageRestriciton(Page page) { try { ContentPermissionSet viewPerms = page .getContentPermissionSet(ContentPermission.VIEW_PERMISSION); ContentPermissionSet editPerms = page .getContentPermissionSet(ContentPermission.EDIT_PERMISSION); page.removeContentPermissionSet(viewPerms); page.removeContentPermissionSet(editPerms); } catch (Exception e) { System.out.println("CATCH REMOVE RESTRICTION"); log.error(e.getMessage(), e); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pauls Žunda, thank you - it seems like I am to stupid to implement sth like that...
Still got some errors...:
org.springframework.orm.hibernate.HibernateSystemException: could not insert: [com.atlassian.confluence.security.ContentPermission#8224769]; nested exception is net.sf.hibernate.HibernateException: could not insert: [com.atlassian.confluence.security.ContentPermission#8224769] at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:597) caused by: net.sf.hibernate.HibernateException: could not insert: [com.atlassian.confluence.security.ContentPermission#8224769] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:475) caused by: net.sf.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:62)
and also:
java.lang.RuntimeException: Failed to add entry to queue
... thanks for your help..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, weird, this works for me on 5.7.4 version. Maybe it's some kind of version bug? Also it is weird that it is saying that it "could not insert ContentPermission" since you are trying to remove it. Maybe you are executing along with a code that throws this exception? Like trying to add ContentPermission for user which already has this permission?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks yap thats a problem - its caused by the not-null problem - i cant remove the restrictions... still my problem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's hard to tell what is wrong. maybe you can paste your code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
cc @Edith Tom
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.