मैं निम्नलिखित कोड (प्रोग्राम के में एक उपयोगकर्ता लॉग ऑन करने का प्रयास कर रहा है): जब मैं उस चलाने का प्रयासवसंत Authentication.setAuthenticated (बुलियन) java.lang.IllegalArgumentException: करने के लिए इस टोकन सेट नहीं कर सकता पर भरोसा
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
...
User tempUser = new User(correctUsername,
correctPassword,
true, true, true, true, // logging them in...
authorities // type is List<GrantedAuthority>
);
...
Authentication authentication
= new UsernamePasswordAuthenticationToken(tempUser, authorities);
// I'm using authorities again (List<GrantedAuthority>)
// is this the right spot for it?
...
// this is the line causing the error
authentication.setAuthenticated(true);
java.lang.IllegalArgumentException: Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead
ध्यान दें कि मैं दोनों User
और Authentication
वस्तुओं में GrantedAuthority
के authorities
सूची का उपयोग कर रहा: मैं निम्नलिखित मिलता है। मुझे यकीन नहीं है कि मुझे उन लोगों का उपयोग क्यों करना चाहिए। मैं another SO question के उत्तर को दोहराने की कोशिश कर रहा हूं लेकिन ऊपर पोस्ट अपवाद में भाग रहा हूं। अन्य इसी तरह के सवाल है कि काफी मेरे सवाल का जवाब नहीं दिया:
- How to programmatically log user in with Spring Security 3.1
- Programmatically login in a user using spring security
कुछ होने के बाद सबसे करीब मैं the forum at springsource.org पर था एक जवाब के लिए मिल गया है उसकी खोज करने वाले और उस व्यक्ति के एक का उपयोग कर deprecated method, लेकिन यह एक समान दृष्टिकोण है। मैं प्रोग्राम में प्रोग्राम को कैसे लॉग कर सकता हूं?
कौन सी लाइन समस्या पैदा कर रही है? –
अंतिम एक; इसके ऊपर की टिप्पणी के साथ यह कहता है 'यह लाइन है जो त्रुटि उत्पन्न करती है ('प्रमाणीकरण.सेट प्रमाणीकृत (सत्य);') – Josh