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;
}
}
分享到:
相关推荐
这里的`<security-domain>`标签指定了一个JAAS(Java Authentication and Authorization Service)安全域,它关联了一个特定的登录模块,用于验证用户身份。 ##### 2. 配置 `web.xml` 文件 接下来,还需要配置同...
3. 认证与访问控制:Java Authentication and Authorization Service (JAAS) 提供了一种框架,用于集成各种身份验证和授权服务。政策实施和语法定义了权限分配的规则。 4. 安全通信:Java Secure Socket Extension ...
这通常通过`<authentication-manager>`和`<user-service>`元素完成,或者通过连接到数据库的自定义提供者。 ```xml <authentication-manager> <authentication-provider> <user-service> </user-service> </...
13. **安全的编程实践**:遵循OWASP(Open Web Application Security Project)的指南,如避免硬编码密码和密钥,以及限制代码的权限。 14. **安全的第三方服务集成**:当与外部服务(如支付网关或社交媒体API)...
<security:authentication-provider user-service-ref="myUserDetailsService"> <security:password-encoder ref="passwordEncoder"/> </security:authentication-provider> </security:authentication-manager>...
2. **src/main/java**:包含项目的主要源代码,可能有自定义的Controller、Service、DAO类,以及Spring Security的配置类。 3. **src/main/resources**:存储配置文件,如application.properties或yaml文件,可能...
为了增强安全性,JBOSS提供了JAAS(Java Authentication and Authorization Service)框架来控制web-console和jmx-console的访问权限。具体实现方式是在应用WAR包内的`WEB-INF/web.xml`和`jboss-web.xml`中取消特定...
在案例中,你可能会发现配置文件(如`application.yml`或`application.properties`)、安全配置类(如`SecurityConfig.java`)、以及可能的Controller和Service类,它们共同协作实现权限管理和登录功能。通过分析...
而安全是任何系统不可忽视的重要环节,HTTP Basic Security是实现Web服务认证的一种常见方式,本文将围绕"HTTP Basic Security与Eureka Server的整合"这一主题,深入探讨如何在SpringCloud环境中确保服务的安全性。...
Authentication, authorization, and communication design for your services Solution patterns for common distributed application scenarios using WCF Principles, patterns, and practices for improving key...
- **Java Authentication and Authorization Service (JAAS)**:集成认证和授权框架,支持多种认证模块。 5. **审计与日志** - **安全事件记录**:记录登录、授权和认证事件,便于安全分析和故障排查。 - **定制...
此外,我们还可以配置其他的认证参数,例如 cas.authentication-url-patterns、cas.validation-url-patterns、cas.request-wrapper-url-patterns 等。 在手动配置 CAS Client 时,我们需要在 web.xml 文件中添加...
其次,Java中提供了标准的安全API,如Java Cryptography Extension (JCE) 和 Java Authentication and Authorization Service (JAAS)。JCE用于加密和解密数据,支持各种加密算法,如AES、RSA等,以确保数据的安全...
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 ...
- Application Development Features - ASP.NET - ISAPI Extensions - ISAPI Filters - Common HTTP Features - Static Content - Default Document - Directory Browsing - Security - Authentication -...
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: 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...