当前位置: 编程技术>综合
本页文章导读:
▪Project.net Config CAS SSO 一、环境
Tomcat6.0
Project.net9.2
CAS3.5
二、配置CAS
参考我的另一篇文章:配置CAS
三、Configuring CAS SSO for Project.net
1、打开文件\webapps\pnet\WEB-INF\web.xml,增加
<!-- CAS -->
<filter>
<filt.........
▪sitemesh 入门demo
看了n天项目了,没啥收获,
项目组里面用到了sitemesh,以前也没接触过,就无聊看了一下。
在此总结一下,给需要的人。
需要有配置3个地方。
web.xml decorators.xml sitemes.........
▪为线程执行设置timeout package com.test.threads;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.co.........
[1]Project.net Config CAS SSO
一、环境
Tomcat6.0
Project.net9.2
CAS3.5
二、配置CAS
参考我的另一篇文章:配置CAS
三、Configuring CAS SSO for Project.net
1、打开文件\webapps\pnet\WEB-INF\web.xml,增加
2、打开文件\webapps\pnet\sso\SSOLogin.jsp,修改文件第46行,如下:
3、打开文件\webapps\pnet\sso\LoggedOut.jsp,在文件头上增加:
4、更新数据库
update pn_propertity set value=1 where propertiy='prm.global.login.sso.allowSSO';
5、从cas项目目录下复制jar文件:\webapps\cas\WEB-INF\lib\cas-client-core-3.2.1.jar到Project.net项目下的lib文件夹中。
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
Tomcat6.0
Project.net9.2
CAS3.5
二、配置CAS
参考我的另一篇文章:配置CAS
三、Configuring CAS SSO for Project.net
1、打开文件\webapps\pnet\WEB-INF\web.xml,增加
<!-- CAS --> <filter> <filter-name>CAS Authentication Filter</filter-name> <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class> <init-param> <param-name>casServerLoginUrl</param-name> <param-value>https://demo.wuyunmin.com:8444/cas/login</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://demo.wuyunmin.com:9090</param-value> </init-param> </filter> <filter> <filter-name>CAS Validation Filter</filter-name> <filter-class>org.jasig.cas.client.validation.Cas10TicketValidationFilter</filter-class> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://demo.wuyunmin.com:8444/cas</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://demo.wuyunmin.com:9090</param-value> </init-param> </filter> <filter> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class> </filter> <filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- /CAS -->
2、打开文件\webapps\pnet\sso\SSOLogin.jsp,修改文件第46行,如下:
boolean ssoEnabled = PropertyProvider.getBoolean("prm.global.login.sso.allowSSO");
if (!ssoEnabled) {
//SSO is disabled
pageContext.forward("/Login.jsp");
return;
}
String remoteUser = request.getRemoteUser();//被修改的行
if ((remoteUser == null)||(remoteUser.equals(""))) {
//no header. this is system error.
pageContext.forward("/sso/NoHeader.jsp");
return;
}
3、打开文件\webapps\pnet\sso\LoggedOut.jsp,在文件头上增加:
<%
response.sendRedirect("https://demo.wuyunmin.com:8444/cas/logout");
%>
4、更新数据库
update pn_propertity set value=1 where propertiy='prm.global.login.sso.allowSSO';
5、从cas项目目录下复制jar文件:\webapps\cas\WEB-INF\lib\cas-client-core-3.2.1.jar到Project.net项目下的lib文件夹中。
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
- —软件人才免语言低担保 赴美带薪读研!—
[2]sitemesh 入门demo
看了n天项目了,没啥收获,
项目组里面用到了sitemesh,以前也没接触过,就无聊看了一下。
在此总结一下,给需要的人。
需要有配置3个地方。
web.xml decorators.xml sitemesh.xml
web.xml的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>test_sitemesh</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
decorators.xml路径在web-inf下面,配置如下:
<?xml version="1.0" encoding="utf-8"?>
<decorators defaultdir="/decorators">
<!-- 此处用来定义不需要过滤的页面 -->
<excludes>
</excludes>
<!-- 用来定义装饰器要过滤的页面 ,style.jsp为装饰页面,/*表示装饰所有页面-->
<decorator name="main" page="style.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
sitemesh.xml的路径也在web-inf下面,配置如下:
<sitemesh>
<property name="decorators-file" value="/WEB-INF/decorators.xml"/>
<excludes file="${decorators-file}"/>
<page-parsers>
<parser content-type="text/html" />
</page-parsers>
<decorator-mappers>
<mapper >
<param name="property.1" value="meta.decorator"/>
<param name="property.2" value="decorator"/>
</mapper>
<mapper >
</mapper>
<mapper >
<param name="match.MSIE" value="ie"/>
<param name="match.Mozilla [" value="ns"/>
<param name="match.Opera" value="opera"/>
<param name="match.Lynx" value="lynx"/>
</mapper>
<mapper >
<param name="decorator" value="printable"/>
<param name="parameter.name" value="printable"/>
<param name="parameter.value" value="true"/>
</mapper>
<mapper >
<param name="decorator" value="robot"/>
</mapper>
<mapper >
<param name="decorator.parameter" value="decorator"/>
<param name="parameter.name" value="confirm"/>
<param name="parameter.value" value="true"/>
</mapper>
<mapper >
</mapper>
<mapper >
<param name="config" value="${decorators-file}"/>
</mapper>
</decorator-mappers>
</sitemesh>
配置文件如上,我看在项目中在web.xml里面是写的sitemeshFilter,但是在网上都很多是pagefilter
有点疑惑,准备下周去问问老大。
然后是装饰页面,它是为了装饰其它页面而存在,style.jsp,
它是放在webRoot/decorators目录下,这个路径是在上面decorators.xml里面定义的。
这里只是测试,所以内容很简单,如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><decorator:title />
</title>
<body>
<p>head decorator...</p> <!-- 头部 -->
<decorator:body />
<p>foot decorator...</p><!-- 脚部,可以写一些copyright之类的东西 -->
</body>
</html>
然后就直接运行,只要在webRoot下面有页面,访问即可看到效果。
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
- —软件人才免语言低担保 赴美带薪读研!—
[3]为线程执行设置timeout
package com.test.threads;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* @author Hawkins
*
*
*在指定时间内执行某个task,超时则退出执行。
*/
public class TimedCall {
public static void main(String[] args) throws InterruptedException,
ExecutionException, TimeoutException {
long timeout = 1000;// 任务必须在设定时间内完成,否则任务将被强制关闭
long timeNeed = 2000;// 任务完成需要的时长。
TimeUnit timeUnit = TimeUnit.MILLISECONDS;// 时间单位
ExecutorService executor = Executors.newSingleThreadExecutor();// 高级并发API
Runnable task = new MyThread(timeNeed, timeUnit);
while (!timedCall(executor, task, timeout, timeUnit))
;// 在某些场景下,需要不断尝试执行任务,直到能够在限定时间内执行完毕。
}
private static boolean timedCall(ExecutorService executor, Runnable c,
long timeout, TimeUnit timeUnit) throws InterruptedException,
ExecutionException {
// FutureTask<?> task = new FutureTask<Object>(c, null);
// executor.execute(task);
//
// task.get(timeout, timeUnit);
Future<?> future = executor.submit(c);
try {
future.get(timeout, timeUnit);
return true;
} catch (TimeoutException e) {
future.cancel(true);// 参数设为true,向执行线程发送中断通知。否则,允许已经启动的线程继续执行直到完成任务。
System.err.println("任务执行超时,强制退出");
return false;
}
}
}
class MyThread implements Runnable {
long timeLong = 0;// how long thread running will cost
TimeUnit timeUnit;
public MyThread() {
}
public MyThread(long milli, TimeUnit timeUnit) {
this.timeLong = milli;
this.timeUnit = timeUnit;
}
@Override
public void run() {
System.out.println("---------" + Thread.currentThread().getName()
+ "开始执行,时长[" + timeLong + "]------");
try {
Thread.sleep(timeLong);
} catch (InterruptedException e) {
System.err.println("线程中断,退出");
return;// 必须响应中断,否则无法退出线程。在退出之前你可能还需做一些资源回收等等。
}
System.out.println("---------" + Thread.currentThread().getName()
+ "执行完毕,时长[" + timeLong + "]------");
}
}
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
- —软件人才免语言低担保 赴美带薪读研!—
最新技术文章: