LDN - CodeStorm 2009

Protected Content JSP Page - Only viewable when autenthicated

Problem: Create a page with content only viewable when logged in.
Version of Luminis: 3.3.3

By looking at a number of JSP pages I came up with the following code, which I placed in $CP_ROOT/webapps/luminis/ipx/misc/somefile.jsp

I placed a link to the jsp page in a targeted content channel and open it in a new window, but you could probably put it on a tab as well.

If you access the file outside of the portal (when you are not yet authenticated) it will display a link to the login page. If you arrived to the page after you have been authenticated it display some content (for simplicity I removed all the content).

It might be a good start for creating some custom pages, only viewable when logged in.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hey Great idea

Hey this is a great idea. I'm trying to get it to work, but all I get is the link to the login page. I took your file, example.jsp, and used it as is with only chaning the portal address to my portal. Any Ideas? I'm using a targeted content channel.

p.s. As another thought, what about restricting by role?

--Scott Hayes

Oh nifty! AJAX channels here

Oh nifty! AJAX channels here I come!

And yes you can probably look up the users roles this way.


Person_3 cpPerson = (Person_3)oPerson.getAttribute("com.pipeline.bom.Person_3");
String sUID = cpPerson.getUserId();
Iterator oGroups = cpPerson.getAccessGroups();

while(oGroups.hasNext()) {
AccessGroup_4 oGroup = (AccessGroup_4)oGroups.next();
vRoles.add(oGroup.getId().toLowerCase());
}

location of file

Did you place it in the directory I mentioned? I believe the location of the file is somewhat important. You can digg through one of the other posts in how to setup your own app directory to deploy JSP pages, but I just use the misc folder.

Also, if you didn't turn off jsp caching on your development box whenever you make changes you have to restart the webserver:
as root use $CP_ROOT/products/ws/https-cp/restart

p.s. I didn't really care who sees the content, as long as they are authenticated. But I placed it in a targetted content channel to deliver the link to specific roles...

OT - jsp caching

Aha! Turning off jsp caching would help occasionally. How does one turn off jsp caching, please?

-s

turn off jsp caching

We are still new to the Luminis environment, only started this March and we are facing so many delays in our development of JSP files which are hosted on the Luminis server because we need to restart the webserver each time we made a small change to a JSP file, I read here that you can trun off jsp caching .. can you please let me know how to do this knowing that we are running Luminis 3.3.3

thank you

Thanks I got it working, but...

Hey I got it working, the link needed to be from /cp/ipx/misc

I'm having problems with the roles now.

I think I need the page import for the following snippet:

Person_3 cpPerson = (Person_3)oPerson.getAttribute("com.pipeline.bom.Person_3");
String sUID = cpPerson.getUserId();
Iterator oGroups = cpPerson.getAccessGroups();

while(oGroups.hasNext()) {
AccessGroup_4 oGroup = (AccessGroup_4)oGroups.next();
vRoles.add(oGroup.getId().toLowerCase());
}

page import

Yeah you should add something like:

<%@ page import="com.pipeline.bom.AccessGroup_4" %>

This should be simple

This should be simple but ....

Internal error: servlet service function had thrown ServletException (uri=/cp/ipx/misc/example.jsp): o
rg.apache.jasper.JasperException: Unable to compile class for JSP../ClassCache/https-cp/cp/_jsps/_ipx/_misc/_example_jsp.java:103: Undefined variable or class name: oPerson

It's having a problem with
Person_3 cpPerson = (Person_3) oPerson.getAttribute("com.pipeline.bom.Person_3");

I've been digging on the internet trying to find any information on these classes and can't. Am I missing something?

--Scott

just re-use the existing person object

Hey Scott,

Why don't you just re-use the existing person object instead of trying to create a new one:

Iterator oGroups = currentUser.getAccessGroups();

while(oGroups.hasNext()) {
AccessGroup_4 oGroup = (AccessGroup_4)oGroups.next();
vRoles.add(oGroup.getId().toLowerCase());
}

Don't have time to test it...

An easier way

No imports required. Try this instead:

<%
if (session.getAttribute("org.jasig.portal.security.IPerson") != null) {
out.println("Authenticated");
} else {
out.println("Please login");
}
%>

Not working for me

All I can get to display is the "please login"... both scripts... Even when I am logged in.

I am on Version III.3.1... but I cannot see how that makes a difference.

redirect user through login page

Hello

Not sure if this is obvious/implicit in the above but I also found out you can redirect an unauthenticated user back through the portal and then to the page you are protecting.

so if you make the 'login to portal' link to be

http://portal.school.edu/cp/home/displaylogin?service=/cp/ipx/misc/example.jsp

then they get there quicker.