SASL, JAAS, JSSE & Java GSS-API总结

SASL JAAS JSSE JGSS-API

全称:
SASL(Simple Authentication and Security Layer)
JAAS(JAVA Authentication and Authorization Service)
JSSE(Secure Socket Extension)
Java GSS-API(Java Generic Security Service Application Programming Interface)

定义:
JAAS -- JAAS implements a Java version of the standard Pluggable Authentication Module (PAM) framework.
JAAS Reference:
http://java.sun.com/javase/6/docs/technotes/guides/security/jaas/JAASRefGuide.html#AppendixA

SASL -- SASL is an Internet standard (RFC 2222) that specifies a protocol for authentication and optional establishment of a security layer between client and server applications. It provides pluggable authentication and security layer for network applications.
SASL Guide:
http://java.sun.com/j2se/1.5.0/docs/guide/security/sasl/sasl-refguide.html

JSSE -- JSSE provides a framework and an implementation for a Java language version of the SSL and TLS protocols.
JSSE Reference:
http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html

Java GSS-API -- Java GSS is the Java language bindings for the Generic Security Service Application Programming Interface (GSS-API). The only mechanism currently supported underneath this API on J2SE is Kerberos v5. Java GSS-API is used for securely exchanging messages between communicating applications.


解释:
以前的Java已经具备了codesource-based access controls,也就是根据code来自哪里,来自谁来决定access controls。 但是缺少根据是谁在执行code来决定access code的能力。 JAAS就是为Java提供这个能力的。 JAAS只用来干两件事:Authentication 和 Authorization。 而具体的形式,就是通过LoginModule的login结果,来确定要执行代码的人是谁(Authentication)和有没有全力来做(Authorization)。

AAS,SASL和GSS-API都是pluggable fashion的,和具体的Authentication方式是分离的。因此可以SASL + GSS-API + Kerberos, 也可以JAAS + Kerberos。

JAAS是对Java platform自身功能的加强。而SASL是一个Internet标准协议,Java SASL只是这个协议的一个种Java实现。这点上和JSSE, GSS-API是类似的,JSSE是SSL标准协议的Java实现, Java GSS-API 是对GSS-API的Java实现。
因此,在$JAVA_HOME/lib/security/java.security中有:
security.provider.2=com.sun.net.ssl.internal.ssl.Provider     #SunJSSE Provider
security.provider.5=sun.security.jgss.SunProvider         #SunGSS-API Provider
security.provider.7=com.sun.security.sasl.Provider        #SunSASL provider

使用哪个API,通常是由protocol的定义决定的。比如LDAP(Lightweight Directory Access Protocol)和IMAP(Internet Message Access Protocol)定义了要使用SASL。 而要实现SSL/TLS通信,则需要使用JSSE。当要用到Kerberos的时候,就需要Java GSS-API了。

另外,JSSE和GSS-API都是用来做通信加密的。不过JSSE是socket-based的API,而GSS-API是token-based的。也就是说JSSE只能使用socket,而GSS-API可以使用TCP sockets, UDP datagrams, 或者其他的。
对GSS-API和JSSE的更多比较参看这里:
http://java.sun.com/j2se/1.5.0/docs/guide/security/jgss/tutorials/JGSSvsJSSE.html


这4个通常还混合使用。比如最常见的模式是:SASL在客户端提供authentication, 而SASL的一种authentication mechanism就是GSS-API, 实现authentication最终通常会使用JAAS的LoginModule。 因此就形成了: SASL GSS-API/Kerberos V5 + LDAP的模式。这种模式常用来实现SSO(Single-Sign-On)。

Advanced Security Programming in Java 中列出了好几种组合模式:
http://java.sun.com/javase/6/docs/technotes/guides/security/jgss/lab/index.html#two

Link:
Java 6.0 Security的Document的总连接:
http://java.sun.com/javase/6/docs/technotes/guides/security/

Java Platform Security Architecture:
http://java.sun.com/javase/6/docs/technotes/guides/security/spec/security-spec.doc.html

Java Cryptography Architecture Reference & API:
http://java.sun.com/j2se/1.5.0/docs/guide/security/CryptoSpec.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java代码中配置`sasl.jaas.config`需要使用`java.util.Properties`对象来设置SASL的JAAS配置。下面是一个示例代码: ```java import java.util.Properties; public class KafkaProducerConfig { private final String BOOTSTRAP_SERVERS = "localhost:9092"; private final String CLIENT_ID = "kafka-producer"; private final String KEY_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer"; private final String VALUE_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer"; private final String SASL_JAAS_CONFIG = "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"username\" password=\"password\";"; public Properties getConfig() { Properties props = new Properties(); props.put("bootstrap.servers", BOOTSTRAP_SERVERS); props.put("client.id", CLIENT_ID); props.put("key.serializer", KEY_SERIALIZER); props.put("value.serializer", VALUE_SERIALIZER); props.put("sasl.jaas.config", SASL_JAAS_CONFIG); props.put("security.protocol", "SASL_PLAINTEXT"); props.put("sasl.mechanism", "PLAIN"); return props; } } ``` 在上面的代码中,我们创建了一个`Properties`对象,并设置了`bootstrap.servers`,`client.id`,`key.serializer`和`value.serializer`等Kafka生产者的配置参数。然后,我们设置`sasl.jaas.config`为SASL的JAAS配置,这里使用的是PLAIN文本认证模式,用户名为`username`,密码为`password`。最后,我们还设置了`security.protocol`和`sasl.mechanism`,以指定使用的SASL协议和认证机制。 你可以根据自己的需要修改相应的配置参数和认证方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值