protected boolean configureFilters(Node xmlDom) throws Exception { XPath xpath = XPathFactory.newInstance().newXPath(); NodeList filtersNodes = (NodeList) xpath.evaluate("/web-app/filter", xmlDom, XPathConstants.NODESET); // Check if josso is already installed XPathExpression jossoFilterClassExp = xpath.compile( "/web-app/filter[filter-class='org.josso.liferay5.agent.LiferaySSOAgentFilter']"); Node jossoFilterNode = (Node) jossoFilterClassExp.evaluate(xmlDom, XPathConstants.NODE); // Append josso filter after auto-login filter in web.xml if (jossoFilterNode != null) { getPrinter() .printActionWarnStatus( "Configure", "JOSSO SSO Filter", "Already configured : " + (jossoFilterNode != null ? jossoFilterNode.getNodeValue() : "<unknown>")); return false; } // Find auto-filter node in web.xml // Append josso filter after auto-login filter in web.xml if (filtersNodes != null && filtersNodes.getLength() > 0) { String xupdJossoFilter = "\n\t<xupdate:insert-after select=\"/web-app/filter[filter-class='com.liferay.portal.servlet.filters.autologin.AutoLoginFilter']\" >\n" + "\t\t<xupdate:element name=\"filter\"> \n" + "\t\t\t<xupdate:element name=\"filter-name\">SSO Josso Filter</xupdate:element>\n" + "\t\t\t<xupdate:element name=\"filter-class\">org.josso.liferay5.agent.LiferaySSOAgentFilter</xupdate:element>\n" + "\t\t</xupdate:element>\n" + "\t</xupdate:insert-after>\n\n" + "\t<xupdate:insert-before select=\"/web-app/filter-mapping[1]\" >\n" + "\t\t<xupdate:element name=\"filter-mapping\">\n" + "\t\t\t<filter-name>SSO Josso Filter</filter-name>\n" + "\t\t\t<url-pattern>/*</url-pattern>\n" + "\t\t</xupdate:element>\n" + "\t</xupdate:insert-before>"; String qry = XUpdateUtil.XUPDATE_START + xupdJossoFilter + XUpdateUtil.XUPDATE_END; log.debug("XUPDATE QUERY: \n" + qry); XUpdateQuery xq = new XUpdateQueryImpl(); xq.setQString(qry); xq.execute(xmlDom); getPrinter() .printActionOkStatus( "Added josso filter into web.xml", "JOSSO Liferay 5 Agent ", "WEB-INF/web.xml"); return true; } return false; }
protected boolean configureJaasModule() { String tcInstallDir = getProperty("tomcatInstallDir"); String jbInstallDir = getProperty("jbossInstallDir"); final String JOSSO_TOMCAT_MODULE_DEFINITION = "\n\njosso {\n" + "org.josso.liferay5.agent.jaas.SSOGatewayLoginModule required debug=true;\n" + "};"; if (tcInstallDir != null) { log.debug("[configureJaasModule]: Tomcat install dir: " + tcInstallDir); try { FileObject tomcatInstallDir = getFileSystemManager().resolveFile(tcInstallDir); FileObject jaasConfigFile = tomcatInstallDir.resolveFile("conf/jaas.config"); if (jaasConfigFile != null) { BufferedWriter writerJaas = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(jaasConfigFile.getURL().getFile(), true))); writerJaas.write(JOSSO_TOMCAT_MODULE_DEFINITION); writerJaas.flush(); writerJaas.close(); return true; } else { getPrinter() .printActionErrStatus( "Configure", "JOSSO SSO Filter", "jaas.conf doesn't exist on given path"); return false; } } catch (FileSystemException e) { getPrinter() .printActionErrStatus( "Configure", "JOSSO SSO Filter", "Tomcat install directory is wrong."); } catch (IOException e) { getPrinter() .printActionErrStatus("Configure", "JOSSO SSO Filter", "Can not write to jaas.conf."); } } if (jbInstallDir != null) { log.debug("[configureJaasModule]: JBoss install dir: " + jbInstallDir); FileObject jbossInstallDir = null; try { jbossInstallDir = getFileSystemManager().resolveFile(jbInstallDir); FileObject loginConfig = jbossInstallDir.resolveFile("server/default/conf/login-config.xml"); Node xDom = readContentAsDom(loginConfig); if (xDom == null) { log.debug( "[configureJaasModule]: XML is not loaded. " + loginConfig.getName().getFriendlyURI()); return false; } String xupdJossoModule = "\n\t<xupdate:append select=\"/policy\" >\n" + "\t\t<xupdate:element name=\"application-policy\">\n" + "\t\t\t<xupdate:attribute name=\"name\">josso</xupdate:attribute>\n" + "\t\t\t<authentication>\n" + "\t\t\t\t<login-module code=\"org.josso.liferay5.agent.jaas.SSOGatewayLoginModule\" flag=\"required\">\n" + "\t\t\t\t\t<module-option name=\"debug\">true</module-option>\n" + "\t\t\t\t</login-module>\n" + "\t\t\t</authentication>\n" + "\t\t</xupdate:element>\n" + "\t</xupdate:append>"; String qry = XUpdateUtil.XUPDATE_START + xupdJossoModule + XUpdateUtil.XUPDATE_END; log.debug("XUPDATE QUERY: \n" + qry); XUpdateQuery xq = new XUpdateQueryImpl(); xq.setQString(qry); xq.execute(xDom); writeContentFromDom(xDom, loginConfig); getPrinter() .printActionOkStatus( "Changed login-config.xml", "JOSSO Liferay 5 Agent ", "server/default/conf/login-config.xml"); return true; } catch (FileSystemException e) { getPrinter() .printActionErrStatus( "Configure", "JOSSO SSO Filter", "JBoss install directory is wrong."); } catch (Exception e) { e.printStackTrace(); } } return false; }
@Override public boolean updateAgentConfiguration(String idpHostName, String idpPort, String idpType) { boolean updated; updated = super.updateAgentConfiguration( idpHostName, idpPort, idpType); // To change body of overridden methods use File | Settings | File Templates. try { log.debug("targetJOSSOConfDir = " + targetJOSSOConfDir); FileObject agentConfigFile = targetJOSSOConfDir.resolveFile("josso-agent-config.xml"); if (agentConfigFile.exists()) { // Get a DOM document of the josso-agent-config.xml Node configXmlDom = readContentAsDom(agentConfigFile); String updateSchemaLocations = "<xupdate:update select=\"//@xsi:schemaLocation\">" + "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd " + " urn:org:josso:agent:liferay5 jar:" + targetLibDir + "/josso-liferay5-agent-" + getProperty("version") + ".jar!/josso-liferay5-agent.xsd" + " urn:org:josso:protocol:client jar:" + targetLibDir + "/josso-agents-bin-" + getProperty("version") + ".jar!/josso-protocol-client.xsd " + " urn:org:josso:agent:core jar:" + targetLibDir + "/josso-agents-bin-" + getProperty("version") + ".jar!/josso-agent.xsd" + "" + "</xupdate:update>"; String updateSchemaLocationQryStr = XUpdateUtil.XUPDATE_START + updateSchemaLocations + XUpdateUtil.XUPDATE_END; log.debug("XUPDATE QUERY: \n" + updateSchemaLocationQryStr); XUpdateQuery updateSchemaLocationQry = new XUpdateQueryImpl(); updateSchemaLocationQry.setQString(updateSchemaLocationQryStr); updateSchemaLocationQry.execute(configXmlDom); getPrinter().printActionOkStatus("Configure", "Schema Locations", ""); // Write modifications to file writeContentFromDom(configXmlDom, agentConfigFile); getPrinter() .printActionOkStatus( "Save", agentConfigFile.getName().getBaseName(), agentConfigFile.getName().getFriendlyURI()); } } catch (Exception e) { log.error("Error injecting schema locations to agent configuration", e); getPrinter().printErrStatus("UpdateAgentConfiguration", e.getMessage()); updated = false; } return updated; }
protected boolean configureValve(Node serverXmlDom) throws Exception { XPath xpath = XPathFactory.newInstance().newXPath(); // Check if josso agent valve is already present String valveClass = "org.josso." + (getPlatformId().equals("tc80") ? "tc70" : getPlatformId()) + ".agent.SSOAgentValve"; // TODO : Be carefull with platform ID, this could not match // the agent pacakge XPathExpression findAgentValve = xpath.compile("/Server/Service/Engine/Host/Valve[@className=\"" + valveClass + "\"]"); NodeList agentValves = (NodeList) findAgentValve.evaluate(serverXmlDom, XPathConstants.NODESET); // If we already have a JOSSO Valve, do nothing! if (agentValves != null && agentValves.getLength() > 0) { for (int i = 0; i < agentValves.getLength(); i++) { Node valve = agentValves.item(i); Node valveClassNode = valve.getAttributes().getNamedItem("className"); getPrinter() .printActionWarnStatus( "Configure", "JOSSO Agent Valve", "Already configured : " + (valveClassNode != null ? valveClassNode.getNodeValue() : "<unknown>")); } return false; } String appendJossoValveQryMod = "\n\t<xupdate:append select=\"//Server/Service/Engine/Host\" >" + "\n\t<xupdate:comment>" + " ================================================== " + "</xupdate:comment>" + "\n\t<xupdate:comment>" + " JOSSO Agent Valve, configuration automatially generated by JOSSO Installer " + "</xupdate:comment>" + "\n\t<xupdate:element name=\"Valve\">" + "<xupdate:attribute name=\"appName\">josso</xupdate:attribute>" + "<xupdate:attribute name=\"debug\">1</xupdate:attribute>" + "\n\t\t<xupdate:attribute name=\"className\">" + valveClass + "</xupdate:attribute>" + "</xupdate:element>" + "\n\t<xupdate:comment>" + " ================================================== " + "</xupdate:comment>\n\t" + "</xupdate:append>"; String appendJossoValveQryStr = XUpdateUtil.XUPDATE_START + appendJossoValveQryMod + XUpdateUtil.XUPDATE_END; log.debug("XUPDATE QUERY: \n" + appendJossoValveQryStr); XUpdateQuery appendJossoValveQry = new XUpdateQueryImpl(); appendJossoValveQry.setQString(appendJossoValveQryStr); appendJossoValveQry.execute(serverXmlDom); getPrinter().printActionOkStatus("Configured", "JOSSO Agent Valve ", valveClass); return true; }
protected boolean configureRealm(Node serverXmlDom) throws Exception { XPath xpath = XPathFactory.newInstance().newXPath(); // Because we removed all realms, we always add JOSSO realm String usersClassNames = "org.josso.gateway.identity.service.BaseUserImpl"; String roleClassNames = "org.josso.gateway.identity.service.BaseRoleImpl"; // For TC80 we're still using tc7 classes String realmClass = "org.josso." + (getPlatformId().equals("tc80") ? "tc70" : getPlatformId()) + ".agent.jaas.CatalinaJAASRealm"; // TODO : Be carefull with platform ID, this could // not match the agent pacakge // Check if josso agent valve is already present XPathExpression findAgentRealm = xpath.compile("/Server/Service/Engine/Realm[@className=\"" + realmClass + "\"]"); NodeList agentRealms = (NodeList) findAgentRealm.evaluate(serverXmlDom, XPathConstants.NODESET); // If we already have a JOSSO Valve, do nothing! if (agentRealms != null && agentRealms.getLength() > 0) { for (int i = 0; i < agentRealms.getLength(); i++) { Node valve = agentRealms.item(i); Node valveClassNode = valve.getAttributes().getNamedItem("className"); getPrinter() .printActionWarnStatus( "Configure", "JOSSO JASS Realm", "Already configured : " + (valveClassNode != null ? valveClassNode.getNodeValue() : "<unknown>")); } return false; } XPathExpression findRealmsExpr = xpath.compile("/Server/Service/Engine/Realm"); NodeList realms = (NodeList) findRealmsExpr.evaluate(serverXmlDom, XPathConstants.NODESET); if (realms != null && realms.getLength() > 0) { String qryModifications = "\n\t<xupdate:remove select=\"/Server/Service/Engine/Realm\"/>"; String qry = XUpdateUtil.XUPDATE_START + qryModifications + XUpdateUtil.XUPDATE_END; log.debug("XUPDATE QUERY: \n" + qry); XUpdateQuery xq = new XUpdateQueryImpl(); xq.setQString(qry); xq.execute(serverXmlDom); for (int i = 0; i < realms.getLength(); i++) { Node realmDom = realms.item(i); Node className = realmDom.getAttributes().getNamedItem("className"); getPrinter() .printActionOkStatus( "Removed", "Tomcat default Realm ", (className != null ? className.getNodeValue() : "<unknown>")); } } String appendJossoRealmQryMod = "\n\t<xupdate:insert-before select=\"//Server/Service/Engine/Host[1]\" >" + "\n\t<xupdate:comment>" + " ================================================== " + "</xupdate:comment>" + "\n\t<xupdate:comment>" + " JOSSO JAAS Realm, configuration automatially generated by JOSSO Installer " + "</xupdate:comment>" + "\n\t<xupdate:element name=\"Realm\">" + "<xupdate:attribute name=\"appName\">josso</xupdate:attribute>" + "<xupdate:attribute name=\"debug\">1</xupdate:attribute>" + "\n\t<xupdate:attribute name=\"className\">" + realmClass + "</xupdate:attribute>" + "\n\t<xupdate:attribute name=\"userClassNames\">" + usersClassNames + "</xupdate:attribute>" + "\n\t<xupdate:attribute name=\"roleClassNames\">" + roleClassNames + "</xupdate:attribute>" + "</xupdate:element>" + "\n\t<xupdate:comment>" + " ================================================== " + "</xupdate:comment>\n\t" + "</xupdate:insert-before>"; String appendJossoRealmQryStr = XUpdateUtil.XUPDATE_START + appendJossoRealmQryMod + XUpdateUtil.XUPDATE_END; log.debug("XUPDATE QUERY: \n" + appendJossoRealmQryStr); XUpdateQuery appendJossoRealmQry = new XUpdateQueryImpl(); appendJossoRealmQry.setQString(appendJossoRealmQryStr); appendJossoRealmQry.execute(serverXmlDom); getPrinter().printActionOkStatus("Configured", "JOSSO JAAS Realm ", realmClass); return true; }