针对JAX-WS,GenericFault的OWSM自定义安全策略

时间:2010-03-17 06:36:33

标签: oracle web-services security

我尝试创建自定义安全性和策略,如下所示: http://download.oracle.com/docs/cd/E15523_01/relnotes.1111/e10132/owsm.htm#CIADFGGC

当我运行服务客户端时,执行自定义断言,成功返回。

   public IResult execute(IContext context) throws WSMException { 
        try { 
            System.out.println("public execute");
            IAssertionBindings bindings = 
                ((SimpleAssertion)(this.assertion)).getBindings(); 
            IConfig config = bindings.getConfigs().get(0); 
            IPropertySet propertyset = config.getPropertySets().get(0); 
            String valid_ips = 
                propertyset.getPropertyByName("valid_ips").getValue(); 
            String ipAddr = ((IMessageContext)context).getRemoteAddr(); 
            IResult result = new Result();
            System.out.println("valid_ips  "+valid_ips);
            if (valid_ips != null && valid_ips.trim().length() > 0) { 
                String[] valid_ips_array = valid_ips.split(","); 
                boolean isPresent = false; 
                for (String valid_ip : valid_ips_array) { 
                    if (ipAddr.equals(valid_ip.trim())) { 
                        isPresent = true; 
                    } 
                } 
                System.out.println("isPresent  "+isPresent);
                if (isPresent) { 
                    result.setStatus(IResult.SUCCEEDED); 
                } else { 
                  result.setStatus(IResult.FAILED); 
                  result.setFault(new WSMException(WSMException.FAULT_FAILED_CHECK)); 
                } 
            } else { 
                result.setStatus(IResult.SUCCEEDED); 
            } 
            System.out.println("result  "+result);
            System.out.println("public execute complete");
            return result;
        } catch (Exception e) { 
            System.out.println("Exception e");
            e.printStackTrace();

            throw new WSMException(WSMException.FAULT_FAILED_CHECK, e); 
        } 
    } 

控制台输出为:

  

public execute valid_ips   127.0.0.1,192.168.1.1 isPresent true result成功执行公共执行   完整

但是,webservice会抛出GenericFault。

参数:[void] 错误:GenericFault:一般错误

我不知道可能有什么不对,有什么想法吗?

这里是完整的堆栈跟踪:

  

线程“main”中的异常   javax.xml.ws.soap.SOAPFaultException:   GenericFault:通用错误   com.sun.xml.internal.ws.fault.SOAP12Fault.getProtocolException(SOAP12Fault.java:210)   在   com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:119)   在   com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)   在   com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)   在   com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)   在$ Proxy30.sayHello(未知来源)   在   creditproxy.CreditRatingSoap12HttpPortClient.main(CreditRatingSoap12HttpPortClient.java:21)   引起:   javax.xml.ws.soap.SOAPFaultException:   GenericFault:通用错误   weblogic.wsee.jaxws.framework.jaxrpc.TubeFactory $ JAXRPCTube.processRequest(TubeFactory.java:203)   在   weblogic.wsee.jaxws.tubeline.FlowControlTube.processRequest(FlowControlTube.java:99)   在   com.sun.xml.ws.api.pipe.Fiber .__ doRun(Fiber.java:604)   在   com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:563)   在   com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:548)   在   com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:445)   在   com.sun.xml.ws.server.WSEndpointImpl $ 2.process(WSEndpointImpl.java:275)   在   com.sun.xml.ws.transport.http.HttpAdapter $ HttpToolkit.handle(HttpAdapter.java:454)   在   com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:250)   在   com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:140)   在   weblogic.wsee.jaxws.HttpServletAdapter $ AuthorizedInvoke.run(HttpServletAdapter.java:319)   在   weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:232)   在   weblogic.wsee.jaxws.JAXWSServlet.doPost(JAXWSServlet.java:310)   在   javax.servlet.http.HttpServlet.service(HttpServlet.java:727)   在   weblogic.wsee.jaxws.JAXWSServlet.service(JAXWSServlet.java:87)   在   javax.servlet.http.HttpServlet.service(HttpServlet.java:820)   在   weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:227)   在   weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)   在   weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)   在   weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)   在   weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)   在   oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:326)   在   weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)   在   weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.run(WebAppServletContext.java:3592)   在   weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)   在   weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)   在   weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)   在   weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)   在   weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)   在   weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)   在   weblogic.work.ExecuteThread.run(ExecuteThread.java:173)   进程退出,退出代码为1。

3 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,但他们在Metalink上有一个解决方案(如果你还没有看到它)。这将解决问题:

  public IResult execute(IContext context) throws WSMException {      
     IResult result = new Result();        
     try {         
       oracle.wsm.common.sdk.IMessageContext.STAGE stage =   ((oracle.wsm.common.sdk.IMessageContext)context).getStage();            
       if (stage  == IMessageContext.STAGE.request)  {    

          javax.security.auth.Subject subject = oracle.security.jps.util.SubjectUtil.getAnonymousSubject();                
          context.setProperty(oracle.wsm.common.sdk.IMessageContext.SECURITY_SUBJECT, subject);                       
          IAssertionBindings bindings = ((SimpleAssertion)(this.assertion)).getBindings();               
          IConfig config = bindings.getConfigs().get(0);               
          IPropertySet propertyset = config.getPropertySets().get(0);                  
          String valid_ips = propertyset.getPropertyByName("valid_ips").getValue();               
          String ipAddr = ((IMessageContext)context).getRemoteAddr();

          if (valid_ips != null && valid_ips.trim().length() > 0) {                  
             String[] valid_ips_array = valid_ips.split(",");
             boolean isPresent = false;                    
             for (String valid_ip : valid_ips_array) {                      
               if (ipAddr.equals(valid_ip.trim())) { 
                     isPresent = true;                      
               }                    
             }                   
             if (isPresent) {                       
                result.setStatus(IResult.SUCCEEDED);                    
             } else {                          
                result.setStatus(IResult.FAILED);                      
                result.setFault(new WSMException(WSMException.FAULT_FAILED_CHECK));                    
             }               
          } else {                
              result.setStatus(IResult.SUCCEEDED);               
          }               
          return result;          
       }        
     } catch (Exception e) {            
       throw new WSMException(WSMException.FAULT_FAILED_CHECK, e);        
     }      
     return result;    
}

答案 1 :(得分:0)

        result.setFault(null);

您将状态设置为成功。无论状态如何设置,它都会使用故障值。

答案 2 :(得分:0)

我遇到了同样的问题。深入研究wls类,我发现WSMMessageContext在Subject中不包含正确的主体。并且实际上抛出了IllegalArgumentExeception,不幸的是,这个真正的异常被包裹并包裹了很多次,我们可能会看到" GenericFault:泛型错误"这是在控制台中执行输出的WSMAgentHook类中的最后一个包装。不幸的是我无法前进,似乎没有人使用自定义安全断言。所以没有人可以帮助我们