我是Spring和Spring安全的新手,我们有一个扩展的Java应用程序(不是Web应用程序),并尝试使用spring作为框架.我已经阅读了一些关于jaas的内容,并为我的应用程序创建了一个简单的jaas安全框架(不是完美的).
现在,因为我们想要合并到Spring框架,我有一些问题:
"Spring Security"是基于"jaas"还是可以使用jaas作为可选提供者,可以用完全不同的东西替换?
"Spring Security"能否在单个应用程序中管理多个并行用户?(特别是授权)
我发现你应该有很多工作要将基本的jaas api转换为有用的api(使用DB,用户/组管理类......),那么"Spring Security"呢?(似乎在jaas-Provider中我们有很多有用的实现)
你知道使用"Spring Security"的摇摆应用程序的示例代码吗?
非常感谢你的时间
我正在使用从原始Java运行时上运行的独立EJB客户端到JavaEE服务器的自定义Principal测试JAAS Subject的传播.我的目标是JBoss和WebSphere实现.
根据这个论坛帖子,我预计它可以轻松地与JBoss一起使用.
这是我的EJB客户端代码代码段:
Subject subject = new Subject();
Principal myPrincipal = new MyPrincipal("me I myself");
subject.getPrincipals().add(myPrincipal);
PrivilegedExceptionAction<String> action = new PrivilegedExceptionAction<String>() {
public String run() throws Exception {
String result;
System.out.println("Current Subject: " + Subject.getSubject(AccessController.getContext()));
InitialContext ic = new InitialContext();
Business1 b = (Business1) ic.lookup("StatelessBusiness1");
result = b.getNewMessage("Hello World");
return result;
}
};
result = subject.doAs(subject, action);
System.out.println("result "+result);
Run Code Online (Sandbox Code Playgroud)
服务器端代码是:
public String getNewMessage(String msg) {
System.out.println("getNewMessage principal: " + sessionContext.getCallerPrincipal());
System.out.println("Current Subject: " …Run Code Online (Sandbox Code Playgroud) 我正在使用JBoss 7上的安全域进行Annotations的EJB-Security.例如
@RolesAllowed({"User", "Admin"})
Run Code Online (Sandbox Code Playgroud)
目前,我在standalone.xml中声明了安全域.这是小事情的批准,但我想在同一JBoss服务器上使用这个安全孩子与不同的项目.因此,我正在寻找一种在standalone.xml之外声明安全域的方法.我想在war-Deployment中使用Deployment Descriptors.
根据这个文档,这应该是可能的.但这适用于JBoss 5,似乎不适用于JBoss 7.1.1.由于Parser Error,启动JBoss会抛出异常.我也看过这个问题,但我不确定这是否是我需要的东西.我需要在standalone.xml之外的某个地方使用Login Module声明新的安全域.
是否有任何简单的解决方案可以在war-Deployment中存储安全域声明和配置?
谢谢
关于java中安全框架的一个简单问题.
到目前为止,JAAS一直是我的框架.是的人抱怨它很难设置,它需要挂钩你的底层系统,但它确实有它的工作,并有额外的作为规范的奖励.
这就是说我最近一直在研究Java中的其他安全框架,这两个似乎最受网络关注的是:
1 - Spring Security
Spring Security似乎非常受欢迎,但我发现它有点令人费解.
2 - Apache Shiro
Apache Shiro似乎比Spring Security更直接,但似乎缺少一些文档.
所以我的问题是,在上面提到的框架中,人们认为我应该花时间学习Spring Security或Apache Shiro吗?
(或者我应该坚持使用JAAS?)
我需要编写一个java程序来连接到HTTPS服务器(DoD网站).该网站需要CAC(DoD通用访问卡)身份验证.如果您通过浏览器访问此站点,则先插入CAC,然后输入PIN.
我需要在java中以编程方式完成身份验证过程(有点像浏览器).如何从CAC检索信息?我一直在谷歌上搜索Java PKCS#11参考指南.看起来像Sun PKCS#11 Provider可以做到这一点,但您需要本机PKCS#11令牌实现.
我对吗?有没有人这样做过?任何建议或评论将不胜感激.
以下代码用于使用Java + Kerberos对Windows AD服务器进行身份验证,并且它可以正常工作 -
public class KerberosAuthenticator {
public static void main(String[] args) {
String jaasConfigFilePath = "/myDir/jaas.conf";
System.setProperty("java.security.auth.login.config", jaasConfigFilePath);
String krb5ConfigFilePath = "/etc/krb5/krb5.conf";
System.setProperty("java.security.krb5.conf", krb5ConfigFilePath);
boolean success = auth.KerberosAuthenticator.authenticate("testprincipal", "testpass");
System.out.println(success);
}
}
Run Code Online (Sandbox Code Playgroud)
以上只是一个测试程序.实际代码将在tomcat webapp中运行.我面临的问题是,如果krb5.conf文件发生变化,如果使用早期版本的krb5.conf成功进行了一次身份验证,那么tomcat中就不会反映出来.新的更改仅反映了tomcat的重启.
我想知道是否有一种方法可以指定JVM来重新加载krb5.conf,以便在不重新启动JVM的情况下获取最新的更改.
我正在尝试使用GlassFish v3.1.1 Build 12和JSF 2.1设置容器管理的安全性.由于某种原因我一直收到以下异常,我无法登录.
WARNING: WEB9102: Web Login Failed: com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Security Exception
WARNING: Exception
com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Security Exception
at com.sun.enterprise.security.auth.login.LoginContextDriver.doPasswordLogin(LoginContextDriver.java:394)
at com.sun.enterprise.security.auth.login.LoginContextDriver.login(LoginContextDriver.java:240)
at com.sun.enterprise.security.auth.login.LoginContextDriver.login(LoginContextDriver.java:153)
at com.sun.web.security.RealmAdapter.authenticate(RealmAdapter.java:512)
at com.sun.web.security.RealmAdapter.authenticate(RealmAdapter.java:453)
at org.apache.catalina.connector.Request.login(Request.java:1932)
at org.apache.catalina.connector.Request.login(Request.java:1895)
at org.apache.catalina.connector.RequestFacade.login(RequestFacade.java:1146)
at com.perpro.controller.MemberBean.doNavigation(MemberBean.java:354)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at …Run Code Online (Sandbox Code Playgroud) 我实际上正在努力使用 SASL 纯文本设置简单的 Kafka 身份验证并添加 ACL 授权。但当我尝试使用数据时遇到问题。
[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka version : 0.10.0.0
[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka commitId : b8642491e78c5a13
[main] WARN org.apache.kafka.clients.NetworkClient - Error while fetching metadata with correlation id 1 : {test-topic=TOPIC_AUTHORIZATION_FAILED}
[main] WARN org.apache.kafka.clients.NetworkClient - Error while fetching metadata with correlation id 2 : {test-topic=TOPIC_AUTHORIZATION_FAILED}
[main] WARN org.apache.kafka.clients.NetworkClient - Error while fetching metadata with correlation id 3 : {test-topic=TOPIC_AUTHORIZATION_FAILED}
[main] WARN org.apache.kafka.clients.NetworkClient - Error while fetching metadata with correlation id 4 : {test-topic=TOPIC_AUTHORIZATION_FAILED}
[main] …Run Code Online (Sandbox Code Playgroud) 我想创建使用安全协议 SASL_SSL 和 sasl Merchanism PLAIN 的 kafka 消费者。有人可以帮我配置这些详细信息吗?
我已经阅读了许多有关如何配置 SASL 详细信息的文档,但仍然没有清楚地了解如何做到这一点。这里我附上我用来创建kafka消费者的代码
Properties props = new Properties();
props.put("bootstrap.servers", "servers");
String consumeGroup = "consumer_group";
props.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"username\" password=\"password\"");
props.put("group.id", consumeGroup);
props.put("client.id", "client_id");
props.put("security.protocol", "SASL_SSL");
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "101");
props.put("max.partition.fetch.bytes", "135");
// props.put("auto.offset.reset", "earliest");
props.put("heartbeat.interval.ms", "3000");
props.put("session.timeout.ms", "6001");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
return new KafkaConsumer<String, String>(props);
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪
14:56:12.767 [main] DEBUG o.a.k.clients.consumer.KafkaConsumer - Starting the Kafka consumer
14:56:12.776 [main] DEBUG org.apache.kafka.clients.Metadata - Updated cluster metadata version 1 to Cluster(nodes = [Node(-2, kafka-events-nonprod-ds1.i, …Run Code Online (Sandbox Code Playgroud) 在javax.faces.webapp.FacesServlet文档中,提到了,
允许的HTTP方法
JSF规范只需要使用GET和POST http方法.如果您的Web应用程序不需要任何其他http方法,例如PUT和DELETE,请考虑使用
<http-method>和<http-method-omission>元素限制允许的http方法.有关使用这些元素的更多信息,请参阅Java Servlet规范的安全性.
我的应用程序确实不依赖于其他HTTP方法(除了GET和POST).因此,我试图使用<http-method>(或<http-method-omission>)排除除GET和之外的所有方法POST.
在web.xml中,JAAS Servlet安全性约束配置如下.
<security-constraint>
<display-name>AdminConstraint</display-name>
<web-resource-collection>
<web-resource-name>ROLE_ADMIN</web-resource-name>
<description/>
<url-pattern>/admin_side/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>ROLE_ADMIN</role-name>
</auth-constraint>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<display-name>UserConstraint</display-name>
<web-resource-collection>
<web-resource-name>ROLE_USER</web-resource-name>
<description/>
<url-pattern>/user_side/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>ROLE_USER</role-name>
</auth-constraint>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)
使用这些元素,
<http-method>GET</http-method>
<http-method>POST</http-method>
Run Code Online (Sandbox Code Playgroud)
我希望不允许所有其他HTTP方法.
但是,GlassFish Server 4.1在服务器终端上记录以下警告.
警告:JACC:对于URL模式
/user_side/*,除了以下方法之外的所有方法都被发现:POST,GET警告:JACC:对于URL模式
/admin_side/*,除了以下方法之外的所有方法都被发现:POST,GET
这是什么意思?
此外,它不是在所有<security-constraint>元素中执行,而是可以全局配置,以便它可以应用于应用程序中的所有资源, …