在Winchill 8.0 中加入鏈接的用戶驗證

来源:互联网 发布:在淘宝网上买手机可靠吗 编辑:程序博客网 时间:2024/04/26 19:29
问题描述: 在Winchill8.0中加入Struts开发时,需要加入ActionForward鏈接的用戶驗證以提高安全性解决步骤:(1)在%Apache_home%/conf/app-Windchill-Auth.conf文件中加入:綠色:要驗證的鏈接名藍色:跟其它相同的 AuthName "Windchill" AuthType Basic AuthLDAPURL ldap://pdm.company.com/ou=people,cn=Windchill_8.0,cn=Application%20Services,o=company require valid-user(2)寫一個繼承org.apache.struts.action.ActionServlet類,復寫其process方法import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionServlet;import wt.auth.Authentication;import wt.httpgw.WTContextBean;import wt.method.RemoteMethodServer;import wt.util.WTContext;import wt.util.WTProperties;/** * StrutsAcationServlet繼承自Struts提供的ActionServlet * 在調用此Servlet則進行登錄檢查,如果沒有登錄,則彈出Basic的論證窗口,輸入.*/public class StrutsActionServlet extends ActionServlet {private static final String CHAR_SET = "utf-8";private static final long serialVersionUID = 1L;private static String WWW_AUTHENTICATE;protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {String s = request.getRemoteUser();if (s == null || s.length() == 0) {String s1 = request.getHeader("AUTHORIZATION");if (s1 == null || s1.length() == 0) {if (WWW_AUTHENTICATE != null) {response.setHeader("www-authenticate", WWW_AUTHENTICATE);}response.sendError(401, "Request not authenticated");return;}}request.setCharacterEncoding(CHAR_SET);WTContextBean bean = (WTContextBean)request.getAttribute("wtcontext");if(bean == null){bean = new WTContextBean();}bean.setRequest(request);//response.setCharacterEncoding(CHAR_SET);super.process(request, response);}static {WTProperties wtproperties;ThreadGroup threadgroup=null;try {wtproperties = WTProperties.getLocalProperties();WWW_AUTHENTICATE = wtproperties.getProperty("wt.httpgw.wwwAuthenticate");threadgroup = WTContext.getContextGroup();WTContext.setLenientLookup(false);WTContext.setContextGroup(new ThreadGroup("StrutsActionServlet"));WTContext.init((String[]) null, true);RemoteMethodServer.setDefaultPrivateAuthentication(true);RemoteMethodServer.setDefaultPrivateAffinity(true);Authentication.setDefaultAllowUserInteraction(false);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{ WTContext.getContext().destroy(); WTContext.setContextGroup(threadgroup); }}}(3)在web.xml文件中加入:StrutsActionext.company.design.servlet.StrutsActionServletStrutsAction/servlet/ext/struts/*