2013-04-06 22 views
12

के लिए लॉगिन करने के लिए रीडायरेक्ट को रोकें मेरे पास स्प्रिंग एमवीसी + स्प्रिंग सिक्योरिटी प्रोजेक्ट है।स्प्रिंग सुरक्षा

<http auto-config="true" access-denied-page="/security/accessDenied" use-expressions="true" disable-url-rewriting="true"> 

... 
<intercept-url pattern="/dashboard/myaccount/**" access="hasAnyRole('ROLE_PERSON', 'ROLE_DEALER')"/> 
... 

<form-login login-page="/security/login" authentication-failure-url="/security/login?error=true" 
       default-target-url="/security/success" username-parameter="email" 
       password-parameter="secret"/> 
<logout invalidate-session="true" logout-success-url="/index" logout-url="/security/logout"/> 

एक उपयोगकर्ता प्रवेश पृष्ठ पर, सफल पुनः निर्देशित किया जाएगा यदि चला जाता है "/ सुरक्षा/सफलता" जहाँ मैं सत्र वस्तु के साथ नियंत्रक में अधिक सामान करना (रिकॉर्ड userID, ... आदि) के लिए

मेरे समस्या (, मुझे 404 फेंक करना चाहते हैं कौन सा मैं नहीं चाहता) एक अतिथि उपयोगकर्ता/डैशबोर्ड/MyAccount (जो प्राधि आवश्यकता होती है), वह पेज लॉगइन करने के लिए पुनः निर्देशित किया जा रहा है जा रहा है जब। उसके बाद वसंत सुरक्षा/सुरक्षा/सफलता पर पुनर्निर्देशित नहीं हो रही है। इसके बजाय/डैशबोर्ड/myaccount पर रीडायरेक्ट किया गया है।

मैं पूरी तरह से अतिथि एक प्राधि पृष्ठ का उपयोग करने की कोशिश कर के मामले में पेज प्रवेश करने और इस पुनर्निर्देशन निष्क्रिय करने के लिए एक रास्ता खोजने के लिए पसंद करेंगे।

ऐसा करने का कोई तरीका है?

Tnx

उत्तर

5

मिले इस: हमेशा उपयोग-default-लक्ष्य = "true"

मैं इस तरह से, मेरे नियंत्रक समारोह हमेशा किसी भी प्रवेश के बाद शुरू हो जाती है। SpringSecurity 4 में

<http auto-config="true" access-denied-page="/security/accessDenied" use-expressions="true" 
     disable-url-rewriting="true" entry-point-ref="authenticationEntryPoint"/> 

<beans:bean id="authenticationEntryPoint" class="a.b.c..AuthenticationEntryPoint"> 
    <beans:constructor-arg name="loginUrl" value="/security/login"/> 
</beans:bean> 

public class AuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {  
    public AuthenticationEntryPoint(String loginUrl) { 
     super(loginUrl); 
    } 

    @Override 
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 
     response.sendError(403, "Forbidden"); 
    } 
} 
11

हम एक नए authenticationEntryPoint जोड़ने

public class SecurityConfig extends WebSecurityConfigurerAdapter { 

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    // .... 
    http.exceptionHandling().authenticationEntryPoint(new AuthenticationEntryPoint() { 

     @Override 
     public void commence(HttpServletRequest request, HttpServletResponse response, 
       AuthenticationException authException) throws IOException, ServletException { 
      if (authException != null) { 
       response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 
       response.getWriter().print("Unauthorizated...."); 
      } 
     } 
    }); 
    // .... 
} 

}

+1

अपनी खुद की AuthenticationEntryPoint, उपयोग बनाने की आवश्यकता: org। springframework.security.web.authentication.Http403ForbiddenEntryPoint – unify

+0

@unify मुझे खुशी है कि मैं अपनी टिप्पणी को देखा इतना क्लीनर – ndrone

+0

क्या आप pl आसानी से मेरे प्रश्न पर एक नज़र डालें https://stackoverflow.com/q/47849246/2556354 – madz

2

एनोटेट विन्यास में आप कर सकते हैं:

+0

मुझे यह सलाह दूसरी स्थिति में मेरी मदद करने में मिली। धन्यवाद – madz

संबंधित मुद्दे