Thursday 27 September 2012

Creating role,user and grant role to user using OPSS



        JpsContextFactory ctxf = JpsContextFactory.getContextFactory();
        JpsContext ctx = ctxf.getContext();
        IdentityStoreService storeService = ctx.getServiceInstance(IdentityStoreService.class);
        IdentityStore idStore = storeService.getIdmStore();
        RoleManager rm=idStore.getRoleManager();
        rm.createRole("sampleRole");
        UserManager um=idStore.getUserManager();
        // creating user
       um.createUser("username", "password".toCharArray());

       //grant role to user

            if( um.isCreateUserSupported()){
             
            User u=idStore.searchUser(IdentityStore.SEARCH_BY_NAME,"username");
                                   
            Role role =idStore.searchRole(IdentityStore.SEARCH_BY_NAME,"sampleRole");
                 
            idStore.getRoleManager().grantRole(role,u.getPrincipal());
         
           }
       

1 comment:

  1. Dear
    Now i want create a site with customize adf security.
    But i can't search any thing in internet.
    Can you help me?

    Email: cuongnh2@fpt.com.vn
    Skyper: anhcuong.2211

    Thanks and regards

    ReplyDelete