cancel
Showing results for 
Search instead for 
Did you mean: 

Create authority as admin

mdergalev
Champ in-the-making
Champ in-the-making
Hi.
I need to create authority using AuthorityService.
String authority = authorityService.createAuthority(AuthorityType.GROUP, siteRoleGroup)

If I signed as admin then works fine, and if as common user with no roles then AccessDeniedException appears.
Is there any way to run this code under admin session?
2 REPLIES 2

kaynezhang
World-Class Innovator
World-Class Innovator
run your code  as a admin user.

                return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>()
                {
                    public String doWork() throws Exception
                    {
         String authority = authorityService.createAuthority(AuthorityType.GROUP, siteRoleGroup);
         return authority ;
                    }
                }, AuthenticationUtil.getSystemUserName());

mdergalev
Champ in-the-making
Champ in-the-making
Thanks a lot. Works fine!