是否可以Enumeration使用Lambda Expression 进行迭代?以下代码片段的Lambda表示形式是什么:
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
while (nets.hasMoreElements()) {
NetworkInterface networkInterface = nets.nextElement();
}
Run Code Online (Sandbox Code Playgroud)
我没有在其中找到任何流.
我有一个第三方图书馆给了我一个Enumeration<String>.我想懒洋洋地与枚举工作作为Java 8 Stream,呼叫之类的东西filter,map并flatMap在其上.
是否有现有的库?我已经引用了Guava和Apache Commons,所以如果其中任何一个都有理想的解决方案.
或者,是什么把一个最好/最简单的方式Enumeration进入Stream,同时保留所有的懒惰天性?
我知道之前已经问过这个问题,但是我在这里遇到了一个特殊的问题.
我使用spring security 3.1.3.
我的Web应用程序中有3个可能的登录案例:
案例3)的问题是我无法将用户重定向到"产品"页面.无论如何,他们会在成功登录后重定向到主页.
请注意,对于案例2),成功登录后,重定向到受限页面的工作开箱即用.
这是我的security.xml文件的相关部分:
<!-- Authentication policy for the restricted page -->
<http use-expressions="true" auto-config="true" pattern="/restrictedPage/**">
<form-login login-page="/login/restrictedLogin" authentication-failure-handler-ref="authenticationFailureHandler" />
<intercept-url pattern="/**" access="isAuthenticated()" />
</http>
<!-- Authentication policy for every page -->
<http use-expressions="true" auto-config="true">
<form-login login-page="/login" authentication-failure-handler-ref="authenticationFailureHandler" />
<logout logout-url="/logout" logout-success-url="/" />
</http>
Run Code Online (Sandbox Code Playgroud)
我怀疑"每个页面的身份验证策略"都要对此问题负责.但是,如果我将其删除,我将无法再登录... j_spring_security_check发送404错误.
编辑:
感谢拉尔夫,我找到了解决方案.所以这就是事情:我使用了这个属性
<property name="useReferer" value="true"/>
Run Code Online (Sandbox Code Playgroud)
拉尔夫给我看了.之后我遇到了我的案例问题1):当通过登录页面登录时,用户停留在同一页面(并没有重定向到主页,就像以前一样).直到此阶段的代码如下:
<!-- Authentication policy for login page -->
<http use-expressions="true" auto-config="true" pattern="/login/**">
<form-login login-page="/login" authentication-success-handler-ref="authenticationSuccessHandlerWithoutReferer" />
</http>
<!-- Authentication policy for every …Run Code Online (Sandbox Code Playgroud) java ×2
java-8 ×2
enumeration ×1
iteration ×1
java-stream ×1
lambda ×1
login ×1
redirect ×1
spring ×1