You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Stephanp <st...@googlemail.com> on 2012/01/04 10:38:50 UTC

JackRabbitSession cannot be cast to Session

Hello All,

I am using the below code:

String User = "admin";
String Password = "admin";
String url = "http://localhost:8080/jackrabbit-webapp-2.3.6/rmi";
Repository repository = JcrUtils.getRepository(url);
Session session =  repository.login(new
SimpleCredentials(User,Password.toCharArray()));
JackrabbitSession js = (JackrabbitSession) session;

I encounter ClassCastException when I execute the above code.

java.lang.ClassCastException:
org.apache.jackrabbit.rmi.client.ClientXASession cannot be cast to
org.apache.jackrabbit.jcr2spi.SessionImpl

I am using jackrabbit-standalone-2.3.6.jar file in the build path of my java
code.

Could you please help me?

Thanks!!
Stephan.

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/JackRabbitSession-cannot-be-cast-to-Session-tp4260623p4260623.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Session cannot be cast to JackRabbitSession

Posted by Stephanp <st...@googlemail.com>.
Hello Mark,

I want to have Principal-based ACLs and as per my knowledge the
AccessControlManager provided by jcr 2.0 is used for Resource-based ACLs.

I want to use code similar to the below one. As you can see I need an
instance of JackrabbitSession for that:

JackrabbitSession js = (JackrabbitSession) session;

User user = ((User)
js.getUserManager().getAuthorizable(session.getUserID()));
Principal principal = user.getPrincipal();

JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager)
session.getAccessControlManager();

JackrabbitAccessControlPolicy[] ps = acMgr.getPolicies(principal); // or
getApplicablePolicies()
JackrabbitAccessControlList list = (JackrabbitAccessControlList) ps[0];

// list entries
JackrabbitAccessControlEntry[] entries = (JackrabbitAccessControlEntry[])
list.getAccessControlEntries();
JackrabbitAccessControlEntry entry = entries[0];
....
....


Please correct me if I am wrong. Thanks in Advance.

Cheers!
Stephan

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Session-cannot-be-cast-to-JackRabbitSession-tp4260623p4262434.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: AW: Session cannot be cast to JackRabbitSession

Posted by Stephanp <st...@googlemail.com>.
@Mark thx for the suggestion.

Finally I made it by publishing the JackRabbit Ressource as a JNDI name and
use the connection method I posted earlier. From a .jsp running in the same
JVM as JackRabbit it is now possible to obtain the JackrabbitSession by
casting from a Session. 

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Session-cannot-be-cast-to-JackRabbitSession-tp4260623p4294827.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: AW: Session cannot be cast to JackRabbitSession

Posted by Mark Herman <MH...@NBME.org>.
See models 1 and 2 for the jackrabbit deployment methods [1].  

Personally I use a product based on apache sling. Sling is a web framework
built on top of JR that has a nifty way of resolving resources(jsp)
associated with content.  The JSP that you store in sling by default are
given native access to the JR repo.  It all depends on your project if
that's something you're interested in. I find it very useful to quickly
generate admin scripts and tasks not available through webdav/rmi, so just
wanted to let you know it's out there. You access those scripts all through
standard HTTP post/get requests so you can trigger them in a client app or
use sling to generate the jsp interface you need.


[1] http://jackrabbit.apache.org/deployment-models.html


--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Session-cannot-be-cast-to-JackRabbitSession-tp4260623p4288922.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: AW: Session cannot be cast to JackRabbitSession

Posted by Stephanp <st...@googlemail.com>.
Hi,

how is it from within the same JVM? Does it work in that case?
E.g. if I am creating the session within an .jsp?
Do I need to use same special connection method?
Currently I am using:

for (RepositoryFactory factory :
ServiceLoader.load(RepositoryFactory.class)) {
	repo = factory.getRepository(parameters);
	if (repo != null) {
		// factory accepted parameters
		s1 = repo.login(new SimpleCredentials(user, pw.toCharArray()));
		break;
	}
}


regrads,
stephan

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Session-cannot-be-cast-to-JackRabbitSession-tp4260623p4288801.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

AW: Session cannot be cast to JackRabbitSession

Posted by KÖLL Claus <C....@TIROL.GV.AT>.
Hi,

As Mark Hermann exactly described JCR over RMI is not full compliant with JSR-283 spec.
I have worked on it some time ago and so i have openend a new jira issue JCR-3206 
(as the JCRRMI Project is no more used) for the JSR-283 support over rmi.
I will commit some code soon.

greets
claus


Re: Session cannot be cast to JackRabbitSession

Posted by "saleh.hazrami" <sa...@yahoo.com>.
Hello Mark,

I am facing a similar problem as Stefan. Could you please let us know if you
have any idea of solving the problem?

Cheers!
Saleh


--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Session-cannot-be-cast-to-JackRabbitSession-tp4260623p4288113.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Session cannot be cast to JackRabbitSession

Posted by Mark Herman <MH...@NBME.org>.
Stephanp wrote
> 
> What I am trying is to restrict user actions in jackrabbit with help of
> JackrabbitSession.
> 

I'm not exactly sure what you mean by "restrict user actions", but as far as
I know access control management isn't quite supported yet in JR RMI [0]. 
You will probably have to do it from within the repository instance. 

Either way, why can't you use the JCR2 methods rather than casting to
jackrabbit?


[0] https://issues.apache.org/jira/browse/JCRRMI-27

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Session-cannot-be-cast-to-JackRabbitSession-tp4260623p4261852.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Session cannot be cast to JackRabbitSession

Posted by Stephanp <st...@googlemail.com>.
Thx for the answer.
In my enironment the web application runs on jboss and jackrabbit runs on
tomcat. Therefore the RMI connection is used for communication between
jackrabbit and webapp. Additionally the webapp uses JAAS for authentication
and I also want to use JAAS for jackrabbit. 
What I am trying is to restrict user actions in jackrabbit with help of
JackrabbitSession.




--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Session-cannot-be-cast-to-JackRabbitSession-tp4260623p4261448.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Session cannot be cast to JackRabbitSession

Posted by Mark Herman <MH...@NBME.org>.
Stephanp wrote
> 
> java.lang.ClassCastException:
> org.apache.jackrabbit.rmi.client.ClientXASession cannot be cast to
> org.apache.jackrabbit.jcr2spi.SessionImpl
> 

That's because when connecting via RMI, you are actually using a
ClientXASession instead of a native session.  What are you trying to
accomplish?  You may be looking for ClientSession, but it is not recommended
to cast to JR specific objects unless necessary.

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Session-cannot-be-cast-to-JackRabbitSession-tp4260623p4261169.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.