Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有Spring角色库安全性的GWT RPC_Java_Spring_Gwt_Spring Security_Gwt Rpc - Fatal编程技术网

Java 具有Spring角色库安全性的GWT RPC

Java 具有Spring角色库安全性的GWT RPC,java,spring,gwt,spring-security,gwt-rpc,Java,Spring,Gwt,Spring Security,Gwt Rpc,我的问题很简单“在使用Spring security和GWT RPC时可能会有任何问题?” 我想在GWT的RPC方法上使用spring的方法级安全性 @PreAuthorize("hasRole('ROLE_ADMIN')") public final String getById(Long id) { ......... } 若取消授权角色访问用户尝试访问处理此rpc方法的页面,则会引发异常,并且不会重定向到“我的访问被拒绝”页面。我不知道为什么不去我的拒绝访问页面?我在控制台上遇到

我的问题很简单“在使用Spring security和GWT RPC时可能会有任何问题?

我想在GWT的RPC方法上使用spring的方法级安全性

@PreAuthorize("hasRole('ROLE_ADMIN')")
public final String getById(Long id) {
    .........
}
若取消授权角色访问用户尝试访问处理此rpc方法的页面,则会引发异常,并且不会重定向到“我的访问被拒绝”页面。我不知道为什么不去我的拒绝访问页面?我在控制台上遇到了一个例外

引发意外异常:org.springframework.security.access.AccessDeniedException:访问被拒绝

我准确地配置为answer,但仍然出现上述错误。如果我错了,请更正“我认为此问题可能是由于gwt的RPC造成的”,因为非RPC方法很好,并重定向到我的unSecure.html。我花了大约3天的时间来处理这个错误。在我的异步方法的onFailure(Throwable-catch)上显示

500服务器上的调用失败;有关详细信息,请参阅服务器日志

我想显示我的配置


spring security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:sec="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security.xsd">

<sec:global-method-security
    secured-annotations="enabled" pre-post-annotations="enabled" />
<sec:http auto-config="false" entry-point-ref="authenticateFilterEntryPoint">
    <sec:access-denied-handler ref="accessDeniedHandler" />
    <sec:intercept-url pattern="/login.html" />

    <sec:logout logout-url="/logout.html" logout-success-url="/login.html"
        invalidate-session="true" />
    <sec:form-login login-page="/login.html"
        login-processing-url="/login_check" authentication-failure-url="/login.html?error=1" />

    <sec:session-management invalid-session-url="/login.html">
        <sec:concurrency-control max-sessions="50"
            error-if-maximum-exceeded="true" />
    </sec:session-management>
    <sec:remember-me key="mykey"
        token-validity-seconds="604800" />
</sec:http>

<beans:bean id="authenticateFilterEntryPoint"
    class="mypackage.common.security.SessionTimeoutEntryPoint">
    <beans:property name="loginFormUrl" value="/login.html" />
</beans:bean>

<beans:bean id="accessDeniedHandler"
    class="mypackage.common.security.AccessDeniedEntryPoint">
    <beans:property name="errorPage" value="/unSecure.html" />
</beans:bean>

<beans:bean
    class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    <beans:property name="defaultErrorView" value="uncaughtException" />
    <beans:property name="excludedExceptions"
        value="org.springframework.security.access.AccessDeniedException" />

    <beans:property name="exceptionMappings">
        <beans:props>
            <beans:prop key=".DataAccessException">dataAccessFailure</beans:prop>
            <beans:prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</beans:prop>
            <beans:prop key=".TypeMismatchException">resourceNotFound</beans:prop>
            <beans:prop key=".MissingServletRequestParameterException">resourceNotFound</beans:prop>
        </beans:props>
    </beans:property>
</beans:bean>

<beans:bean id="authenticationUserService"
    class="mypackage.common.security.AuthenticationUserService" />

<sec:authentication-manager>
    <sec:authentication-provider
        user-service-ref="authenticationUserService">
        <sec:password-encoder hash="md5" />
    </sec:authentication-provider>
</sec:authentication-manager>

<beans:bean id="authLoggerListener"
    class="org.springframework.security.authentication.event.LoggerListener" />
<beans:bean id="eventLoggerListener"
    class="org.springframework.security.access.event.LoggerListener" />
SessionTimeoutEntryPoint.java

public class AccessDeniedEntryPoint extends org.springframework.security.web.access.AccessDeniedHandlerImpl {
private static final Logger logger = LoggerFactory.getLogger(AccessDeniedEntryPoint.class);

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    super.handle(request, response, accessDeniedException);

}
}
public class SessionTimeoutEntryPoint extends LoginUrlAuthenticationEntryPoint {

@Override
public final void commence(final HttpServletRequest request, final HttpServletResponse response,
        final AuthenticationException authException) throws IOException, ServletException {
    super.commence(request, response, authException);
}
}

因此,当取消授权角色用户访问此方法时,我希望获得unSecure.html。我非常感谢你的任何建议。对不起,我的问题太长了。我不想再撞我的头了!谢谢。

就像我上次的回答一样,我很久以前就用过这个。在我的例子中,我不总是处理URL,而是将其委托给处理程序

我的意思是,如果您想将GWT-RPC与Spring安全性集成,我做的第一件事就是从我的GWT应用程序尝试登录Spring

因此,您需要做的第一件事是创建一个登录名

我发现注释
@RemoteServiceRelativePath(“examplelogin.rpc”)
很有用,因此如果使用它,您可以利用路径,然后在
spring security.xml
中,您可以根据这些路径过滤请求(参见下面更新的示例)

不确定为什么要将GWT-RPC与Spring安全性集成,然后指定/login.html(应该是一个RPC调用,而不是之前描述的html?但可能您正在将自己的MVP用于GWT,所以我并不是说这是错误的,只是让我感到惊讶:)

阅读您的代码时,我没有发现任何错误,但就我而言,我有一些不同之处:

....
<http use-expressions="true" entry-point-ref="http401UnauthorizedEntryPoint">

    <intercept-url pattern="/yourProject/public.rpc" access="permitAll" />
    <intercept-url pattern="/yourProject/examplelogin.rpc" access="hasRole('ROLE_ADMIN')" />

    <form-login authentication-success-handler-ref="authenticationSuccessHandler"
        authentication-failure-handler-ref="authenticationFailureHandler"/>


    ..... //logout, session-management, custom-filters....

    <beans:bean id="http401UnauthorizedEntryPoint" 
                class="your.project.Http401UnauthorizedEntryPoint" />
    <beans:bean id="authenticationSuccessHandler" 
                class="your.project.GWTAuthenticationSuccessHandler"/>
    <beans:bean id="authenticationFailureHandler" 
                class="your.project.GWTAuthenticationFailureHandler"/>
</http>
....
。。。。
..... //注销、会话管理、自定义筛选器。。。。
....
您特别询问了将
Spring Security
GWT-RPC
一起使用的可能性(这是因为在
标记中我将
.RPC
URL放在那里)

请注意

答案是肯定的,我已经做到了(三年前,但我做到了:)

我认为解决问题的关键在于:

  • 指定RPC调用或/login.html的侦听器url

  • 像我一样委托处理者(小心,也许你做得很好 错误在另一部分,但至少我喜欢这个例子 工作)

很抱歉没有直接向您显示错误,我希望这些答案会有所帮助


谢谢。

如我所述,我还使用了Spring security的登录安全性,效果很好。但对于方法级安全性,我错了什么?这不会重定向到我的unSecure.html页面,除非以
AccessDenied
身份登录控制台。谢谢兄弟!谢谢你之前对我问题的回答:-)。现在,如何为RPC调用指定拦截器?因为我使用方法级安全性作为
@PreAuthorize(“hasRole('ROLE\u ADMIN')”)
。您将表单登录错误委托为
。如果是这样的话,我该如何处理我的AccessDenied处理程序?您是否同意我认为这个问题可能是由于gwt的RPC造成的?哦!对不起,可能我没有直接回答,因为我在Hibernate上仍然“迷路”。我认为最好的选择是你创建一个尽可能简单的项目(一步一步地描述你的场景和需求),然后给我(你可以在我的个人资料中查看我的电子邮件)一个链接到你的github,然后我在我的机器上测试。如果可以的话,我很乐意帮忙:)