%@page import="javax.naming.InitialContext"%> <%@page import="java.security.KeyStore"%> <%@page import="java.lang.reflect.Method"%> <%@page import="java.security.cert.Certificate"%> <%@page import="iaik.x509.X509Certificate"%> <%@page import="iaik.asn1.structures.Name"%> <%@page import="iaik.asn1.structures.GeneralNames"%> <%@page import="iaik.asn1.structures.GeneralName"%> <%@page import="iaik.utils.Util" %> <%@page import="iaik.asn1.DerCoder"%> <%@page import="iaik.asn1.ObjectID"%> <%@page import="com.sap.engine.services.configuration.appconfiguration.*"%> <%@page import="java.util.Properties"%> <%@page import="java.util.Enumeration"%> <%@page import="com.sap.tc.logging.Location"%> <%@page import="com.sap.tc.logging.Severity"%> <%@page import="com.sap.security.api.*"%> <%@page import="com.sap.security.api.logon.*"%> <%@page import="com.sap.engine.frame.core.configuration.*"%> <%! static Location LOCATION =Location.getLocation("com.sap.security.core.server.tcsra.genreq"); %> <% LOCATION.debugT("entering genreq.jsp"); String oldservice = request.getParameter("OLDSERVICE"); if (oldservice==null) oldservice="/"; session.setAttribute("OLDSERVICE", oldservice); String signurl = "/enrollapp/signreq.jsp"; String cn = null; String userName = null; String remoteUser= request.getRemoteUser() ; LOCATION.debugT("genreq.jsp called by remoteUser=" + remoteUser); String j_username= request.getParameter("j_username"); String userEmail=null; String enc_email = null; String userAlias=null; //we use UME to get EMail and Alias IUser user = UMFactory.getAuthenticator().getLoggedInUser(); if (user ==null || remoteUser==null ) { // this can happens only if /enrollap/genreq.jsp was called directly // we don't want to support this case LOCATION.debugT("direct access to enrollapp/genreq.jsp not allowed"); response.sendRedirect("/"); return; } userEmail = user.getEmail(); IUserAccount[] accounts = user.getUserAccounts(); if (accounts != null && accounts.length > 0) { String[] aliases = accounts[0].getAttribute(IPrincipal.DEFAULT_NAMESPACE, ILoginConstants.LOGON_ALIAS); if (aliases != null && aliases.length > 0) { userAlias = aliases[0]; } } LOCATION.debugT("user info: " + "alias=" + userAlias+", userEmail=" + userEmail + ", j_username=" +j_username); //TODO: We need AUTHORITY CHECK HERE !!!! if ( userEmail!=null ) { GeneralNames generalNames = new GeneralNames(); generalNames.addName(new GeneralName( GeneralName.rfc822Name , userEmail)); enc_email= new String(Util.Base64Encode(DerCoder.encode ( generalNames.toASN1Object() ))); } String raKeystoreViewName ="DEFAULT"; String raKeystoreViewEntryName ="j2ee-ra"; String raname=null; String errorMessage = null; String errmsg_1 = "Internal error. Please contact your system administrator !" ; boolean useEMAILasSUBJAltName = true; boolean useAliasAsCN = true; // we need RA Name here // we read app property tcs.myRAName first, if it was not changed // we determine the name from RA dist. name without common name part try { InitialContext ctx = new InitialContext(); //get ApplicationConfigHandlerFactory instance from JNDI ApplicationConfigHandlerFactory appCfgHdlFctry = (ApplicationConfigHandlerFactory)ctx.lookup("ApplicationConfiguration"); if (appCfgHdlFctry != null) { Properties props = appCfgHdlFctry.getApplicationProperties(); if ( props !=null ) { raname = props.getProperty ("tcsra.myRAName"); raKeystoreViewName= props.getProperty ("tcsra.RAKeystoreView"); raKeystoreViewEntryName= props.getProperty ("tcsra.RASigningKey"); errmsg_1 = props.getProperty ("tcsra.genreq_errmsg_1"); useEMAILasSUBJAltName = Boolean.valueOf(props.getProperty ("tcsra.useEMAILasSUBJAltName")).booleanValue(); useAliasAsCN = Boolean.valueOf(props.getProperty ("tcsra.useAliasAsCN")).booleanValue(); } } } catch (Exception e) { LOCATION.traceThrowableT(Severity.DEBUG, "Problem with ApplicationConfigHandlerFactory", e); //we continue with default values .. } if (userAlias!= null && useAliasAsCN) cn = userAlias; else cn = remoteUser ; cn = cn.toUpperCase(); LOCATION.debugT("CN set to:" + cn); try { InitialContext ctx = new InitialContext(); final Object kManager = ctx.lookup("keystore"); Class cl = kManager.getClass(); final Method method = cl.getMethod("getKeystore", new Class[] { String.class }); KeyStore rakeystore = (KeyStore)method.invoke( kManager, new Object[] { raKeystoreViewName} ) ; Certificate [] chain = rakeystore.getCertificateChain(raKeystoreViewEntryName); if (chain == null) LOCATION.infoT("no RA certificate found with parameters View : " +raKeystoreViewName +" Entry: " +raKeystoreViewEntryName ); //it will fail with NullpointerException here if no RA Cert found X509Certificate cert0= (X509Certificate) chain[0]; if ( raname == null || "".equals(raname.trim()) || "put_your_RA_name_here".equals(raname)) { Name name =(Name) cert0.getSubjectDN(); name.removeRDN(ObjectID.commonName); raname= name.toString(); } session.setAttribute("rakey",rakeystore.getKey(raKeystoreViewEntryName, null)); session.setAttribute("racert",cert0); } catch (Exception e) { LOCATION.traceThrowableT(Severity.DEBUG, "internal error", e); errorMessage = errmsg_1; } String userdn = "CN="+cn+"," + raname; //we put the userdn to the session for the next step ! session.setAttribute("tcs.j2ee-ra.userdn",userdn); if (userEmail!=null && useEMAILasSUBJAltName) session.setAttribute("tcs.j2ee-ra.userEmail", userEmail); %> <% if (errorMessage!=null) { %>
<% return ;} %> <% if (request.getHeader("User-Agent").indexOf("MSIE")!=-1 ) { %>