cancel
Showing results for 
Search instead for 
Did you mean: 

BO XI 3.1 Java SDk- setrights

Former Member
0 Kudos

hi,

I am developing a custom java application. one of the features is setting the rights for users/usergroups as described in the code example http://devlibrary.businessobjects.com/businessobjectsxir2/en/en/BOE_SDK/boesdk_java_dg_doc/doc/boesd....

But that code breaks in BO XI 3.1 because IObjectPrincipal is not supported. the intended replacements IExplicitPrincipal and IEffectivePrincipal lacks many features of IObjectPrincipal notably setRole() function.

Please provide me a way to proceed with setting user rights, Preferably code samples

Accepted Solutions (1)

Accepted Solutions (1)

aasavaribhave
Advisor
Advisor
0 Kudos

Here is te code sample to set a "Role" for a user\usergroup on a folder\object. THe code queries for a custom role but can easily be changed to use one of the system defined roles e.g.

select * from ci_systemobjects where si_name='full control' and si_kind='customrole'

Here is the code:


<%@ page import="com.crystaldecisions.sdk.framework.*,
				 com.crystaldecisions.sdk.occa.infostore.*,
				 com.crystaldecisions.sdk.exception.SDKException"
				 
%><%
IEnterpriseSession oEnterpriseSession = null;
IInfoStore oInfoStore = null;
IInfoObjects folders, users, customRoles;
IInfoObject folder, user;

String username = "administrator";
String password = "";
String cmsname = "cmsname";
String authType = "secEnterprise";
String folderName = "test";
String testUser = "test user";
String customRoleName = "test custom role";
int customRoleID;
try
{
	oEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
	oInfoStore = (IInfoStore)oEnterpriseSession.getService("","InfoStore");
	// Retrieve Custom Role ID
	String query = "select * from ci_systemobjects where si_name='" + customRoleName + "' and si_kind='customrole'";
	customRoles = oInfoStore.query(query);
	if(customRoles.size() > 0)
	{	
		customRoleID = ((IInfoObject)customRoles.get(0)).getID();
		query = "select * from ci_infoobjects where si_name ='" + folderName + "' and si_kind = 'folder'";
		folders = oInfoStore.query(query);
		if (folders.size() > 0)
		{
			query = "select * from ci_systemobjects where si_name ='" + testUser + "' and si_kind ='user'";
			users = oInfoStore.query(query);
			if (users.size() > 0)
			{
				// set the custom role.
				folder = (IInfoObject) folders.get(0);
				user = (IInfoObject) users.get(0);
				IExplicitPrincipals explicitPrincipals = folder.getSecurityInfo2().newExplicitPrincipals();
				IExplicitPrincipal explicitPrincipal = explicitPrincipals.add(user.getID());
				IExplicitRole explicitRole = explicitPrincipal.getRoles().add(customRoleID);
				oInfoStore.commit(folders);					
				out.println(explicitRole.getTitle() + " custom access right set on folder " + folder.getTitle() + " for user " + user.getTitle());
				
			}
			else
			{
				out.println("<br>user not found!");
			}
		}
		else
		{
			out.println("<br>folder not found!");
		}
	}
	else
	{
		out.println("<br>custom role not found!");
	}

}
	
catch(SDKException e)
{
	out.println(e.toString());
}
finally
{
	oEnterpriseSession.logoff();
}
%>

Answers (1)

Answers (1)

Former Member
0 Kudos

Thanks. And by the way is there any resources (code samples ) specifically for BO XI 3.1 similiar to the sdn sample applications at http://www.sdn.sap.com/irj/boc/index?rid=/webcontent/uuid/b0daacb7-ad82-2b10-b2b6-f3e9fa3e716a [original link is broken] .

Updating the code samples for every version of BO would be awesome as many people (me for instance) use SDK's rarely and mostly require only the functionalities in the samples or very few modifications if any.

aasavaribhave
Advisor
Advisor
0 Kudos

most of the R2 code should work in R3 almost as is. only a few APIs have changed such as some server administration apis or security\rights related apis. We have the newer code available for 3.1 some on SDN samples\blogs and some in SAP knowledge base articles ( kbases)

Former Member
0 Kudos

hi,

Even the viewrights.jsp in the same example is out of date.If there is sample code for the same which would work in R3 it would be very useful instead of building from scratch.

regards

Edited by: nitin.ac on Aug 26, 2011 11:32 AM

former_member582367
Discoverer
0 Kudos

Hi,

I also have a similar problem, but its while viewing Roles of a folder.

boExplicitPrincipals = boSecurityInfo2.getExplicitPrincipals();

IExplicitPrincipal boExplicitPrincipal = boExplicitPrincipals.get(j);

int id = boExplicitPrincipal.getID();

IExplicitRoles Roles = boExplicitPrincipal.getRoles();

The 4th and 5th line gives me an error

"Exception in thread "main" java.lang.NullPointerException"

Is there any different class or method that can help me get the Roles of existing Folders in BO environment

aasavaribhave
Advisor
Advisor
0 Kudos

Can you make sure if boExplicitPrincipal is not null? And I assume you have posted this snippet from a for\while loop in your code, does IExplicitPrincipal boExplicitPrincipal = boExplicitPrincipals.get(j) can actually return a non-null object, considering value of j?

And are there any users\groups that have "exlicitly" defined roles on the folder, this method will not return "effective" roles that users or groups get by inheritance.

former_member582367
Discoverer
0 Kudos

Hi Aasavari,

Thank you so much for your help.

Luckily I was able to figure out the problem.

All the Principals and Roles are not serialized one after the other, they are serialized based on the ID.

For eg.:

If we use boEffectivePrincipals.get(0).getName();

You will always get NullPointerException, as there is nothing in the index 0.

Now if we use boEffectivePrincipals.get(1).getName();

This will give you "Everyone" Principal for a particular object.

If we use boEffectivePrincipals.get(2).getName(); this will give you "Administrators" principal

For Roles the same principal applies.

Thanks again.