`

Web Service Security --- Application Authentication

阅读更多

Container-Managed Security for Web Service

 

(Tomcat  is the reference implementation, it can not only be used to published Restful web service as servlet, but also can publish SOAP-based web service.)

It provides not only user authentication but also wire-level security. 

 

Securing the @WebService underTomcat

You should ensure that the Tomcat connector for SSL/TLS is enabled. Tomcat connector is an endpoint for client request. You need to update tomcat configuration file config/server.xml

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" redirectPort="8443"

   SSLEnabled="true" maxThreads="150"  scheme="https"

   secure="true"  clientAuth="false"  sslProtocol="TLS"   keystoreFile="/conf/server.keystore" keystorePass="123456" />

 

keystore and truststore, that have same format, client uses truststore to compare the certificate from Tomcat.

Client code to invoke web service.

public class Test {

      public static final String END_POINT = "https://localhost:8443/WebServiceExample/tc?wsdl";

      /**

       * @param args

       */

      public static void main(String[] args) {

            TempConvertImplService port = new TempConvertImplService();

            TempConvert service = port.getTempConvertImplPort();

           

            //

            Map<String, Object> req_ctx = ((BindingProvider)service).getRequestContext();

           

            req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, END_POINT);

           

            //place username and password into header which a non-java client could do as well.

            Map<String, List<String>> hdr = new HashMap<String, List<String>>();

            hdr.put("Username", Collections.singletonList("localhost"));

            hdr.put("Password", Collections.singletonList("123456tt"));

            req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, hdr);

           

            System.out.println(service.c2F(12.f));

            System.out.println(service.f2C(-40.1f));

      }

 

}

SEI中添加authenticated()进行Authentication

@WebService(endpointInterface="com.csc.ws.temp.TempConvert")

public class TempConvertImpl implements TempConvert {

      @Resource

      WebServiceContext ws_ctx;

     

      @Override

      public float c2f(float c) {

            if (authenticated()) {

                  return 32.0f + (c * 9.0f/5.0f);

            } else {

                  System.err.println("Authentication failure with exception ");

                  throw new HTTPException(401);

            }

           

           

      }

 

      @Override

      public float f2c(float c) {

            if (authenticated()) {

                  return (5.0f/9.0f)*(c-32.0f);

            } else {

                  System.err.println("Authentication failure with exception ");

                  throw new HTTPException(401);

            }

           

      }

     

      private boolean authenticated(){

            MessageContext mctx = ws_ctx.getMessageContext();

            Map http_headers = (Map) mctx.get(MessageContext.HTTP_REQUEST_HEADERS);

           

            List uList = (List) http_headers.get("Username");

            List plist = (List) http_headers.get("Password");

           

            if (uList.contains("localhost") && plist.contains("123456")) return true;

            else return false;

      }

 

}

分享到:
评论

相关推荐

    jboss安全性 jboss设置安全性

    这里的`&lt;security-domain&gt;`标签指定了一个JAAS(Java Authentication and Authorization Service)安全域,它关联了一个特定的登录模块,用于验证用户身份。 ##### 2. 配置 `web.xml` 文件 接下来,还需要配置同...

    WebSphere Application Server security

    3. 认证与访问控制:Java Authentication and Authorization Service (JAAS) 提供了一种框架,用于集成各种身份验证和授权服务。政策实施和语法定义了权限分配的规则。 4. 安全通信:Java Secure Socket Extension ...

    Spring Security简易配置指南

    这通常通过`&lt;authentication-manager&gt;`和`&lt;user-service&gt;`元素完成,或者通过连接到数据库的自定义提供者。 ```xml &lt;authentication-manager&gt; &lt;authentication-provider&gt; &lt;user-service&gt; &lt;/user-service&gt; &lt;/...

    JavaEE application to teach application security

    13. **安全的编程实践**:遵循OWASP(Open Web Application Security Project)的指南,如避免硬编码密码和密钥,以及限制代码的权限。 14. **安全的第三方服务集成**:当与外部服务(如支付网关或社交媒体API)...

    security+jcaptcha(验证码)框架搭建

    &lt;security:authentication-provider user-service-ref="myUserDetailsService"&gt; &lt;security:password-encoder ref="passwordEncoder"/&gt; &lt;/security:authentication-provider&gt; &lt;/security:authentication-manager&gt;...

    demo-spring-security-form:백기선스프링시큐리티

    2. **src/main/java**:包含项目的主要源代码,可能有自定义的Controller、Service、DAO类,以及Spring Security的配置类。 3. **src/main/resources**:存储配置文件,如application.properties或yaml文件,可能...

    Jboss学习手册

    为了增强安全性,JBOSS提供了JAAS(Java Authentication and Authorization Service)框架来控制web-console和jmx-console的访问权限。具体实现方式是在应用WAR包内的`WEB-INF/web.xml`和`jboss-web.xml`中取消特定...

    spring-security 案例

    在案例中,你可能会发现配置文件(如`application.yml`或`application.properties`)、安全配置类(如`SecurityConfig.java`)、以及可能的Controller和Service类,它们共同协作实现权限管理和登录功能。通过分析...

    http-basic-security eureka-server .rar

    而安全是任何系统不可忽视的重要环节,HTTP Basic Security是实现Web服务认证的一种常见方式,本文将围绕"HTTP Basic Security与Eureka Server的整合"这一主题,深入探讨如何在SpringCloud环境中确保服务的安全性。...

    Improve Web Services Security

    Authentication, authorization, and communication design for your services Solution patterns for common distributed application scenarios using WCF Principles, patterns, and practices for improving key...

    WebSphere Application Server v6.1 安全篇(Security)

    - **Java Authentication and Authorization Service (JAAS)**:集成认证和授权框架,支持多种认证模块。 5. **审计与日志** - **安全事件记录**:记录登录、授权和认证事件,便于安全分析和故障排查。 - **定制...

    spring boot整合CAS Client实现单点登陆验证的示例

    此外,我们还可以配置其他的认证参数,例如 cas.authentication-url-patterns、cas.validation-url-patterns、cas.request-wrapper-url-patterns 等。 在手动配置 CAS Client 时,我们需要在 web.xml 文件中添加...

    security-service

    其次,Java中提供了标准的安全API,如Java Cryptography Extension (JCE) 和 Java Authentication and Authorization Service (JAAS)。JCE用于加密和解密数据,支持各种加密算法,如AES、RSA等,以确保数据的安全...

    apache security 安全

    Web Application Security Resources Chapter 11. Web Security Assessment Section 11.1. Black-Box Testing Section 11.2. White-Box Testing Section 11.3. Gray-Box Testing Chapter 12. Web ...

    Windows7下如何安装IIS

    - Application Development Features - ASP.NET - ISAPI Extensions - ISAPI Filters - Common HTTP Features - Static Content - Default Document - Directory Browsing - Security - Authentication -...

    GOweb应用编程(go-building-web-applications)

    Module 2, Go Programming Blueprints, has a project-based approach where you will be building chat application, adding authentication, and adding your own profile pictures in different ways....

    Node.js Web Development

    Node.js Web Development: Build secure and high performance web applications with Node.js 10 Node.js is a server-side JavaScript platform using an event-driven, non-blocking I/O model allowing users to...

Global site tag (gtag.js) - Google Analytics