1

私は次のコントローラーを持っています:

@Controller
@RequestMapping("/api")
public class APIProvider {
    @Secured(value = {"isAuthenticated()"})
    @RequestMapping(value="/secure/{app}/{query}", method=RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<String> getList(HttpServletRequest request,
        @PathVariable("app") String app,
        @PathVariable("query") String query) {
        //....DO SMTH
    }
}

必要な URL にアクセスしようとすると、「ページが見つかりません」というメッセージが表示されます。

注釈を削除@Securedすると、問題が修正されます。したがって、リクエストのマッピングは正しいです。また、@Secured注釈のために、次の命令を security-config.xml に追加しました。

<security:global-method-security secured-annotations="enabled"/>

@Secured+@RequestMappingを一緒に作るのを手伝ってくれる人はいますか?

4

3 に答える 3

0

security.xml ファイルで、<security:global-method-security secure-annotations="enabled"/>の後に次の行を追加します。

<http use-expressions="true">
    <intercept-url pattern="/api/secure/**" access="isFullyAuthenticated() />
</http>

これにより、ユーザーが完全に認証されている場合、すべての /api/secure リクエストが確実に処理されます。

于 2012-11-01T17:11:52.040 に答える
0

セキュリティ式ハンドラーも含める必要があると思います。

<security:global-method-security pre-post-annotations="enabled" >
    <security:expression-handler ref="expressionHandler"/>
</security:global-method-security>

<beans:bean id="expressionHandler"   class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHa ndler">
    <beans:property name="permissionEvaluator" ref="permissionEvaluator"/>
</beans:bean>
于 2012-11-04T07:27:55.743 に答える
0

代わりにこれを試してください@Secured("IS_AUTHENTICATED_FULLY")

于 2012-10-30T13:14:34.350 に答える