--
LuisRodriguez - 19-Jan-2012
Source code of hello.jsp for sample application
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="ch.cern.sso.weblogic.principals.CernWlsPrincipal"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.net.URLEncoder" %>
<%@page import="java.security.Principal"%>
<%@page import="weblogic.security.Security"%>
<%@page import="javax.security.auth.Subject"%>
<%@page import="java.net.URLEncoder" %>
<html>
<head>
<title>Sample Application JSP Page</title>
</head>
<body bgcolor=white>
<table border="0">
<tr>
<td align=center>
<img src="images/tomcat.gif">
</td>
<td>
<h1>Sample Application JSP Page</h1>
This is the output of a JSP page that is part of the Hello, World
application.
</td>
</tr>
</table>
<p>
<h2>User info through request.getRemoteUser()</h2>
<%= new String("Hello! ") %> <%= request.getRemoteUser()%>
</p>
<p>
<h2>User info through CernWlsPrincipal</h2>
<%
Subject subject = Security.getCurrentSubject();
Set<Principal> principals = subject.getPrincipals();
CernWlsPrincipal cernWlsPrincipal = null;
for (Iterator<Principal> iterator = principals.iterator(); iterator.hasNext();) {
Principal principal = iterator.next();
if (principal instanceof CernWlsPrincipal) {
cernWlsPrincipal = (CernWlsPrincipal)principal;
}
}
if(cernWlsPrincipal!=null){
out.println(
"<strong>UserName:</strong> " + cernWlsPrincipal.getName() + "<br/>" +
"<strong>Upn:</strong> " + cernWlsPrincipal.getUpn() + "<br/>" +
"<strong>EmailAddress:</strong> " + cernWlsPrincipal.getEmailAddress() + "<br/>" +
"<strong>CommonName:</strong> " + cernWlsPrincipal.getCommonName() + "<br/>" +
"<strong>Role:</strong> " + cernWlsPrincipal.getRole() + "<br/>" +
"<strong>DisplayName:</strong> " + cernWlsPrincipal.getDisplayName() + "<br/>" +
"<strong>PhoneNumber:</strong> " + cernWlsPrincipal.getPhoneNumber() + "<br/>" +
"<strong>Building:</strong> " + cernWlsPrincipal.getBuilding() + "<br/>" +
"<strong>FirstName:</strong> " + cernWlsPrincipal.getFirstName() + "<br/>" +
"<strong>LastName:</strong> " + cernWlsPrincipal.getLastName() + "<br/>" +
"<strong>Department:</strong> " + cernWlsPrincipal.getDepartment() + "<br/>" +
"<strong>HomeInstitute:</strong> " + cernWlsPrincipal.getHomeInstitute() + "<br/>" +
"<strong>PersonID:</strong> " + cernWlsPrincipal.getPersonID() + "<br/>" +
"<strong>UidNumber:</strong> " + cernWlsPrincipal.getUidNumber() + "<br/>" +
"<strong>GidNumber:</strong> " + cernWlsPrincipal.getGidNumber() + "<br/>" +
"<strong>Groups:</strong> " + cernWlsPrincipal.getGroups());
}
%>
</p>
<h2>Logout</h2>
<a href="http://ssowlssp.cern.ch:7003/saml2slo/sp?userName=<%= URLEncoder.encode(request.getRemoteUser(), "ISO-8859-1") %>">Logout</a>
</body>
</html>