Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

SQL query to get all Confluence spaces with anonymous enabled

Topicus December 29, 2015

Hi,

I want to get all anonymous spaces in my Confluence instance through a SQL query, however I couldn't find a decent query. I have this which returns the permissions on (all) spaces, but not the anonymous ones:

SELECT sp.permid, sp.permtype, s.spacekey, s.spacename, sp.permgroupname, um.lower_username
FROM SPACEPERMISSIONS sp
JOIN SPACES s ON sp.spaceid = s.spaceid
LEFT JOIN user_mapping um ON sp.permusername = um.user_key

i have tried with where sp.permgroupname IS NULL, but that doesn't work.

Any help or pointers in the right direction?

Marc

3 answers

1 accepted

2 votes
Answer accepted
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2015

This might work:

SELECT *
  FROM spacepermissions
  WHERE COALESCE(permgroupname, '') = '' 
  and COALESCE(permusername, '') = '';

I got the information from this page: http://stackoverflow.com/questions/14172978/postgresql-select-empty-fields

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2015

note: anonymous permissions are those in which both group name and user name fields are blank :)

Topicus December 29, 2015

That did the trick, thank you good sir!

1 vote
Rodrigo Girardi Adami
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 29, 2015

Hi Marc,

If I understood you correctly, you would like to retrieve spaces which anonymous users can access correct?

This query should return all spaces which anonymous can see and access:

select distinct s.spacename
from spaces s
join spacepermissions sp on s.spaceid = sp.spaceid
where sp.permtype = 'VIEWSPACE' or 'EDITSPACE'
and permgroupname is null
and permusername is null;

The anonymous permissions are stored with the permgroupname and permusername as null.

I hope this helps!

Cheers,

Rodrigo

Chander Inguva
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2015

Hey Rodrigo, a small correction... where sp.permtype = 'VIEWSPACE' or sp.permtype ='EDITSPACE'

Topicus December 29, 2015

That also does the trick, thanks :)

James Thomas April 20, 2016

What about the pages which are having anonymous permission??

0 votes
Hans-Hermann Hunfeld January 23, 2017

Just as a hint for Oracle users, here you can use following

select distinct s.spacename
from spaces s
join spacepermissions sp on s.spaceid = sp.spaceid
where sp.permtype in ('VIEWSPACE','EDITSPACE')
and permgroupname is null
and permusername is null;
sanan sanan February 11, 2019

Hi Hans,

we are using oracle db. 

we want to remove all the anonymous access from our Confluence spaces. 

your sql query will give us the list of such spaces. But can you suggest a command by which we can remove the anonymous access from the listed spaces?

 

Regards

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events