init.jspf revision 4fe4e4f798a84a46e567f64ceadd3648eb0582d4
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster The contents of this file are subject to the terms
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster of the Common Development and Distribution License
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster (the License). You may not use this file except in
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster compliance with the License.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster You can obtain a copy of the License at
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster https://opensso.dev.java.net/public/CDDLv1.0.html or
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster See the License for the specific language governing
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster permission and limitations under the License.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster When distributing Covered Code, include this CDDL
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Header Notice in each file and include the License file
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster If applicable, add the following below the CDDL Header,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster with the fields enclosed by brackets [] replaced by
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster your own identifying information:
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "Portions Copyrighted [year] [name of copyright owner]"
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster $Id: init.jspf,v 1.5 2009/08/01 00:21:52 sean_brydon Exp $
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%-- imports --%>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.sun.identity.common.SystemConfigurationUtil" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.sun.identity.saml2.common.AccountUtils" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.sun.identity.saml2.common.SAML2Constants" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.sun.identity.saml2.common.SAML2Utils" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.sun.identity.saml2.meta.SAML2MetaManager" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.sun.identity.saml2.jaxb.metadata.SPSSODescriptorElement" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.sun.identity.saml2.jaxb.metadata.AssertionConsumerServiceElement" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.sun.identity.saml2.jaxb.metadata.SingleLogoutServiceElement" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="java.util.*, java.net.URLEncoder" %>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page import="com.iplanet.sso.SSOTokenManager,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%-- functions --%>
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster private static final String UNIVERSAL_IDENTIFIER =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String deployuri = SystemConfigurationUtil.getProperty(
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "com.iplanet.am.services.deploymentDescriptor");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if ((deployuri == null) || (deployuri.length() == 0)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster deployuri = "../../..";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String SAMPLES_DIR = "samples/saml2/useCaseDemo";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // Change the value if you want to show a different title in your install
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // Change the value if you want to show a different title in your install
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String thisUrl = request.getRequestURL().toString();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String appBase = thisUrl.substring(0, thisUrl.lastIndexOf("/samples") + 1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String samplesBase = appBase + SAMPLES_DIR + "/";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String reserveFlightUrl = samplesBase + "reserveFlight.jsp";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String reserveCarUrl = samplesBase + "reserveCar.jsp";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster //To determine if user is logged in thru SAML or Local login
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SAML2MetaManager mm = SAML2Utils.getSAML2MetaManager();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List idpMetaAliases = mm.getAllHostedIdentityProviderMetaAliases(REALM);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List spMetaAliases = mm.getAllHostedServiceProviderMetaAliases(REALM);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List idpEntities = mm.getAllRemoteIdentityProviderEntities(REALM);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List spEntities = mm.getAllRemoteServiceProviderEntities(REALM);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster iAmIdp = true;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster myTitle = idpTitle;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster partnerTitle = spTitle;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster myEntityID = mm.getEntityByMetaAlias(myMetaAlias);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster iAmSp = true;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster myTitle = spTitle;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster partnerTitle = idpTitle;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster myEntityID = mm.getEntityByMetaAlias(myMetaAlias);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "No SAML2 Service Hosted Here, "
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster + " Verify SAML2 Metadata Configuration");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "This is an IDP, "
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster + "No SAML2 Trusted Partner SP Service Registered Here,"
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster + " Verify SAML2 Metadata Configuration");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster idpTitle = idpTitle + "(IDP: " + myEntityID + ")";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster myTitle = idpTitle;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster spTitle = spTitle + "(SP: " + partnerEntityID + ")";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster partnerTitle = spTitle;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "This is an SP, "
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster + "No SAML2 Trusted IDP Service Registered Here, "
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster + " Verify SAML2 Metadata Configuration");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster spTitle = spTitle + "(SP: " + myEntityID + ")";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster myTitle = spTitle;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster idpTitle = idpTitle + "(IDP: " + partnerEntityID + ")";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster partnerTitle = idpTitle;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster = mm.getSPSSODescriptor(REALM, partnerEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if ((partnerSlosList == null) || partnerSlosList.isEmpty()) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "Could not determine partner samples base");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster = (SingleLogoutServiceElement)partnerSlosList.get(0);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster reserveCarWithPartnerUrl = partnerSampleHomeUrl.substring(0,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster } else if (iAmSp && (partnerEntityID != null)) { //i am sp
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster = mm.getIDPSSODescriptor(REALM, partnerEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if ((partnerSlosList == null) || partnerSlosList.isEmpty()) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "Could not determine partner samples base");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster = (SingleLogoutServiceElement)partnerSlosList.get(0);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if ((partnerEntityID != null) && (partnerSampleHomeUrl != null)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SSOTokenManager tokenManager = SSOTokenManager.getInstance();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster ssoToken = tokenManager.createSSOToken(request);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if ((ssoToken != null) && tokenManager.isValidToken(ssoToken)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster userLoggedIn = true;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String spMetaAlias = ssoToken.getProperty(SAML2Constants.SP_METAALIAS);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (spMetaAlias==null || spMetaAlias.trim().length() == 0){
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster //if detect presence of SP MetaAlias property then
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster //it means login was thru SAML, else if not then local
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster isLocalLogin = true;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster //login was thru SAML since SP_METAALIAS was set
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster isLocalLogin = false;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster userName = ssoToken.getProperty(UNIVERSAL_IDENTIFIER);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster userLabel = userName;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster userLabel = userName.substring(j+1,k).trim();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster userLabel = userLabel.substring(0,1).toUpperCase()
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster } catch (SSOException e) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster //response.sendError(response.SC_INTERNAL_SERVER_ERROR);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (userLoggedIn) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster federatedWithPartner = (AccountUtils.getAccountFederation(
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster userName, myEntityID, partnerEntityID) == null) ? false : true;