- package com.oimacademy.NeedEvaluate;
- import java.util.HashSet;
- import java.util.Set;
- import com.oimacademy.connection.Platform;
- import oracle.iam.identity.exception.AccessDeniedException;
- import oracle.iam.identity.rolemgmt.api.RoleManager;
- import oracle.iam.identity.rolemgmt.api.RoleManagerConstants;
- import oracle.iam.identity.rolemgmt.api.RoleManagerConstants.RoleAttributeName;
- import oracle.iam.identity.rolemgmt.vo.Role;
- import oracle.iam.platform.context.ContextManager;
- public class HasAccessByAdminRole {
- public static void main(String[] args) {
- hasAccessByAdminRole();
- }
- public static void hasAccessByAdminRole() throws AccessDeniedException {
- boolean isAdminRoleGranted = false;
- String loggedinUsrName = (String)ContextManager.getOIMUser();
- String loggedinUsrKey = (String) ContextManager.getUserPreference(ContextManager.USERDETAILS.KEY.getKey());
- try {
- System.out.println(" loggedinUsrKey "+loggedinUsrKey);
- System.out.println(" loggedinUsrName "+loggedinUsrName);
- RoleManager roleManager = Platform.getService(RoleManager.class);
- Set<String> returnAttrs = new HashSet<String>();
- returnAttrs.add(RoleAttributeName.KEY.getId());
- // find the System Admin Role Key
- Role role = roleManager.getDetails(RoleAttributeName.NAME.getId(), RoleManagerConstants.SYS_ADMIN_ROLE_NAME, returnAttrs);
- if(role!=null){
- String roleKey = role.getEntityId();
- System.out.println(" roleKey "+roleKey);
- // check if System Admin role is granted to logged in user in directAndIndirect Roles
- isAdminRoleGranted = roleManager.isRoleGranted(roleKey, loggedinUsrKey, true);
- System.out.println(" isAdminRoleGranted "+isAdminRoleGranted);
- }
- } catch (Exception e) {
- System.out.println("Error while checking user's membership roles");
- }
- //If logged in user is NOT a member of System Administrators group, throw Exception
- if(!isAdminRoleGranted) {
- throw new AccessDeniedException();
- }
- }
- }
Oracle Identity Manager(OIM) is the Provisioning Solution from oracle. This page contains an index with references to all OIM related posts in the oracle identity manager Academy blog. The posts included herein are intended to provide oracle identity management customers and developers with technical information about best practices for implementing OIM based solutions.
OIM API To Check Has Access for Admin Role
Subscribe to:
Post Comments (Atom)
-
Connection Related API's : OIM DB Connection/ Data Source connection OIMClient API / OIMConnection API OIM Platform API to getSer...
-
Error : Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.springframewor...
-
In this post, we set the middle name as “MiddleName” if user does not provide middle name during user create operation. Below are high...
No comments:
Post a Comment