Hi Hemika,

If you are concerned if the logged in user is authorized to perform some
specific action, you can use following without going for role comparison.

String loggedInUser =
CarbonContext.getThreadLocalCarbonContext().getUsername();

UserRealm realm = (UserRealm)
CarbonContext.getThreadLocalCarbonContext().getUserRealm();

if (realm.getAuthorizationManager().isUserAuthorized(loggedInUser,
*permissionResourcePath*,* UserMgtConstants.EXECUTE_ACTION*)) {

          // action
}

You need to specify the permissionResourcePath and the action (bold above)
accordingly.

Regards,
TharinduE

On Mon, Jan 26, 2015 at 10:04 AM, Hemika Kodikara <[email protected]> wrote:

> Hi Tharindu,
>
> Thanks for the code snippet,
>
> I'll check that out.
>
> Thanks,
> Hemika
>
> Hemika Kodikara
> Software Engineer
> WSO2 Inc.
> lean . enterprise . middleware
> http://wso2.com
>
> Mobile : +94777688882
>
> On Sun, Jan 25, 2015 at 11:23 PM, Tharindu Edirisinghe <[email protected]
> > wrote:
>
>> Hi Hemika,
>>
>> org.wso2.carbon.user.core.util.UserCoreUtil class has following method
>> for checking if the user is primary admin user.
>>
>> public static boolean isPrimaryAdminUser(String userName,
>> RealmConfiguration realmConfig)
>>
>> Regards,
>> TharinduE
>>
>> On Sun, Jan 25, 2015 at 11:02 PM, Hemika Kodikara <[email protected]>
>> wrote:
>>
>>> Hi All,
>>>
>>> Is there an existing method in carbon to find whether a user is an admin
>>> or not provided their username ?
>>>
>>> Regards,
>>> Hemika
>>>
>>> Hemika Kodikara
>>> Software Engineer
>>> WSO2 Inc.
>>> lean . enterprise . middleware
>>> http://wso2.com
>>>
>>> Mobile : +94777688882
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>>
>> Tharindu Edirisinghe
>> Software Engineer | WSO2 Inc
>> Identity Server Team
>> mobile : +94 775 181586
>>
>
>


-- 

Tharindu Edirisinghe
Software Engineer | WSO2 Inc
Identity Server Team
mobile : +94 775 181586
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to