`

phpCAS: Uncaught exception 'CAS_AuthenticationException'故障排除

 
阅读更多
采用phpCAS和J2EE的cas开源框架对接wordpress,构建自己的门户网站。
刚开始用windows部署,很顺利,但配置太麻烦,而且windows总感觉不甚方便,考虑到最新的docker技术,apache+php+mysql+tomcat都可以在linux和docker上部署,于是开始迁移,于是,填坑工作开始。

考虑到Docker成熟度,还是使用内核为3.10以上的CentOS7默认的docker1.12安装,然后部署apache+php、tomcat以及mysql的docker,再讲应用部署到各个docker上,一切都很顺利,不过半小时而已,然后就是噩梦开始。

1、wordpress报数据库连接出错,发现
PHP Warning:  mysqli_real_connect(): (HY000/2003): Can't connect to MySQL server on 'xx.xx.xx.xx' (113) in /var/www/html/wp/wp-includes/wp-db.php on line 1489


mysql服务器上执行perror 113,返回“OS error code 113:  No route to host”,是防火墙问题,执行:
宿主机防火墙上加上端口的允许
iptables -I INPUT -s 0/0 -p tcp --dport 3306 -j ACCEPT


ok, mysql可以了

2、然后就是CAS认证通过后白屏,后台cas.log提示validate failed,提示:
[Fri Feb 17 00:51:59.740721 2017] [:error] [pid 17] [client] PHP Fatal error:  Uncaught exception 'CAS_AuthenticationException' in /var/www/html/phpCAS/CAS/CAS/Client.php:3265\nStack trace:\n#0 /var/www/html/phpCAS/CAS/CAS/Client.php(1450): CAS_Client->validateCAS20('http://168.X.XX...', '\\r\\n\\r\\n\\r\\n<cas:serv...', Object(DOMElement), false)\n#1 /var/www/html/phpCAS/CAS/CAS/Client.php(1351): CAS_Client->isAuthenticated()\n#2 /var/www/html/phpCAS/CAS/CAS.php(1060): CAS_Client->checkAuthentication()\n#3 /var/www/html/wp/wp-content/plugins/wpcas/wpcas.php(88): phpCAS::checkAuthentication()\n#4 /var/www/html/wp/wp-settings.php(255): include_once('/var/www/html/w...')\n#5 /var/www/html/wp/wp-config.php(99): require_once('/var/www/html/w...')\n#6 /var/www/html/wp/wp-load.php(43): require_once('/var/www/html/w...')\n#7 /var/www/html/wp/wp-login.php(12): require('/var/www/html/w...')\n#8 {main}\n  thrown in /var/www/html/phpCAS/CAS/CAS/Client.php on line 3265, referer: http://168.X.XX.XXX:8080/wp/


看phpCAS的Client.php源码,认证应该通过了,但就是抛错,对J2EE的cas应用的配置修改

WEB-INF\spring-configuration目录下的ticketExpirationPolicies.xml,把c:timeToKill="${st.timeToKillInSeconds:10}"改为c:timeToKill="${st.timeToKillInSeconds:100}",ok,认证通过

3、问题继续,发现wordpress访问奇慢无比,查看

mysql> show variables like "%skip%";
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| skip_external_locking  | ON    |
| skip_name_resolve      | OFF   |
| skip_networking        | OFF   |
| skip_show_database     | OFF   |
| slave_skip_errors      | OFF   |
| sql_slave_skip_counter | 0     |
+------------------------+-------+
6 rows in set (0.00 sec)

应该是skip_name_resolve的问题,加上就可以了,速度快很多了

4、考虑到可用性,将docker镜像导出到另外一台服务器,结果其他都没问题,CAS又开始报错:
[Fri Feb 24 16:27:09.933558 2017] [:error] [pid 20] [client] PHP Fatal error:  Uncaught exception 'CAS_AuthenticationException' in /var/www/html/phpCAS/CAS/CAS/Client.php:3183\nStack trace:\n#0 /var/www/html/phpCAS/CAS/CAS/Client.php(1449): CAS_Client->validateCAS20('http://168.X.XX...', '', NULL, false)\n#1 /var/www/html/phpCAS/CAS/CAS/Client.php(1350): CAS_Client->isAuthenticated()\n#2 /var/www/html/phpCAS/CAS/CAS.php(1060): CAS_Client->checkAuthentication()\n#3 /var/www/html/wp/wp-content/plugins/wpcas/wpcas.php(88): phpCAS::checkAuthentication()\n#4 /var/www/html/wp/wp-settings.php(255): include_once('/var/www/html/w...')\n#5 /var/www/html/wp/wp-config.php(100): require_once('/var/www/html/w...')\n#6 /var/www/html/wp/wp-load.php(43): require_once('/var/www/html/w...')\n#7 /var/www/html/wp/wp-login.php(12): require('/var/www/html/w...')\n#8 {main}\n  thrown in /var/www/html/phpCAS/CAS/CAS/Client.php on line 3183, referer: http://168.X.XX.XX:8080/wp/


查了无数帮助,包括stackoverflow都没有解决办法,只能祭出大招,把phpCAS的log打开,在wordpress的/wp-content/plugins/wpcas/wpcas.php中将cas的log打开
// Enable debugging
phpCAS::setDebug("/var/www/html/phpCAS.log");
// Enable verbose error messages. Disable in production!
phpCAS::setVerbose(true);


可以看到
D989 .|    |    |    |    could not open URL 'http://168.X.XX.XX/cas/serviceValidate?service=http%3A%2F%2F168.X.XX.XX%3A8080%2Fwp%2Fwp-login.php&ticket=ST-8-6v6FgAqONLAxDGovQ1I9-cas01.example.org' to validate (CURL error #7: Failed to connect to 168.X.XX.XX port 80: No route to host) [Client.php:3182]
D989 .|    |    |    |    => CAS_AuthenticationException::__construct(CAS_Client, 'Ticket not validated', 'http://168.X.XX.XX/cas/serviceValidate?service=http%3A%2F%2F168.5.15.19%3A8883%2Fwp%2Fwp-login.php&ticket=ST-8-6v6FgAqONLAxDGovQ1I9-cas01.example.org', true) [Client.php:3186]
D989 .|    |    |    |    |    => CAS_Client::getURL() [AuthenticationException.php:76]
D989 .|    |    |    |    |    <= 'http://168.X.XX.XX:8080/wp/wp-login.php'
D989 .|    |    |    |    |    CAS URL: http://168.X.XX.XX/cas/serviceValidate?service=http%3A%2F%2F168.5.15.19%3A8883%2Fwp%2Fwp-login.php&ticket=ST-8-6v6FgAqONLAxDGovQ1I9-cas01.example.org [AuthenticationException.php:79]


的错误,是防火墙问题,即selinux开了

原来新服务器的selinux忘了关闭了

vi /etc/sysconfig/selinux

把里边的一行改为
SELINUX=disabled

改了之后保存,然后重启。

重启后别忘了iptables增加端口权限

宿主机防火墙上加上端口的允许
iptables -I INPUT -s 0/0 -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -s 0/0 -p tcp --dport 8080 -j ACCEPT
iptables-save | cat >/etc/sysconfig/iptables


OK,一切问题都解决呢,考虑到提高速度,可以加上WP-ROCKET插件提高速度
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics