2012-02-23 5 views
20

मैं जेएसपी में उपयोगकर्ता भूमिका मुद्रित करना चाहता हूं? मुझे पता है कि वसंत-सुरक्षा टैग है जिसे <sec:authentication property="principal.username"/> कहा जाता है इस टैग का उपयोग करके मैं उपयोगकर्ता नाम तक पहुंच सकता हूं .. लेकिन कैसे jsp में वर्तमान भूमिका को एक्सेस और प्रिंट करना है?वसंत सुरक्षा का उपयोग कर जेएसपी में भूमिका कैसे प्राप्त करें?

उत्तर

21

principalUserDetails ऑब्जेक्ट को संदर्भित करता है, यदि आप उस ऑब्जेक्ट का निरीक्षण करते हैं तो भूमिका public Collection<GrantedAuthority> getAuthorities() { .. } के अंतर्गत संग्रहीत की जाती है।

जिसके अनुसार, अगर आप केवल स्क्रीन पर भूमिकाओं प्रिंट करना चाहते हैं, ऐसा करते हैं: -

<sec:authentication property="principal.authorities"/> 
18

getAuthorities का उपयोग करें या उपयोगकर्ता के विवरण का अपना कार्यान्वयन लिखें और एक सुविधा विधि बनाएं।

या:

<sec:authorize access="hasRole('supervisor')"> 
This content will only be visible to users who have 
the "supervisor" authority in their list of <tt>GrantedAuthority</tt>s. 
</sec:authorize> 

here से।

+0

कैसे jsp से getAuthorities उपयोग करने के लिए? – Rajesh

+0

बस क्रोम बीन सम्मेलन का उपयोग करें: NimChimpsky

+0

यूआरएल अब काम नहीं करता है। –

3
<sec:authentication property="principal.authorities" var="authorities" /> 
<c:forEach items="${authorities}" var="authority" varStatus="vs"> 
<p>${authority.authority}</p> 
</c:forEach> 
+0

थोड़ा सा विवरण एक लंबा रास्ता तय करता है ... –

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