我們的WAS在dev和我們的本地之間不同beanWrapperImpl問題只與websphere
我們的應用程序使用Spring-3.1.0版本的Spring-Security。
它開始在JSP文件中,我們試圖以顯示連接的用戶名:
論DEV WAS,我們有一個NotReadablePropertyException: 「Bean屬性‘委託人’是無法讀取或有一個無效的getter方法:getter的返回類型是否與setter的參數類型相匹配?「
這是因爲AuthenticationTag使用BeanWrapper接口(BeanWrapperImpl中已經)
在文件的行729(春季3.1.0-RELEASE)BeanWrapperImpl中已經錯誤是扔,
727:PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
728:if (pd == null || pd.getReadMethod() == null) {
729: throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName);
730:}
所以PD爲空或者pd.getReadMethod()爲空。 在正常情況下getReadMethod返回此: 對象方法[公共java.lang.Object中org.springframework.security.authentication.UsernamePasswordAuthenticationToken.getPrincipal()]
更新 調試之後和在類加入一些日誌,看來,「PD」爲空
我用純Java寫了這個代碼來識別錯誤我們
logger.info(session.getAttribute("SPRING_SECURITY_CONTEXT").getClass().toString());
final SecurityContextImpl sci = ((SecurityContextImpl) session.getAttribute("SPRING_SECURITY_CONTEXT"));
logger.info(sci.getAuthentication().getClass().toString());
final Authentication auth = sci.getAuthentication();
logger.info(auth.getPrincipal().getClass().toString());
final User u = (User) auth.getPrincipal();
logger.info(u.getUsername());
logger.info(SecurityContextHolder.getContext().getAuthentication().getName());
logger.info("use beanWrapper :");
final BeanWrapperImpl wrapper = new BeanWrapperImpl(auth);
String property = "principal";
Object result = wrapper.getPropertyValue(property);
logger.info("property : " + property + " value :[" + result.toString() + "]");
property = "principal.username";
result = wrapper.getPropertyValue(property);
logger.info("property : " + property + " value :[" + result.toString() + "]");
日誌在開發:
[2012-01-12 12:23:19,843] INFO [WebContainer : 8] [c.b.e.e.w.c.IndexController] class org.springframework.security.core.context.SecurityContextImpl
[2012-01-12 12:23:19,843] INFO [WebContainer : 8] [c.b.e.e.w.c.IndexController] class org.springframework.security.authentication.UsernamePasswordAuthenticationToken
[2012-01-12 12:23:19,843] INFO [WebContainer : 8] [c.b.e.e.w.c.IndexController] class org.springframework.security.core.userdetails.User
[2012-01-12 12:23:19,843] INFO [WebContainer : 8] [c.b.e.e.w.c.IndexController] superadmin
[2012-01-12 12:23:19,843] INFO [WebContainer : 8] [c.b.e.e.w.c.IndexController] superadmin
[2012-01-12 12:23:19,843] INFO [WebContainer : 8] [c.b.e.e.w.c.IndexController] use beanWrapper :
< 500錯誤>
日誌上我們當地是:
[2012-01-13 08:51:10,062] INFO [WebContainer : 4] [c.b.e.e.w.c.IndexController] class org.springframework.security.core.context.SecurityContextImpl
[2012-01-13 08:51:10,062] INFO [WebContainer : 4] [c.b.e.e.w.c.IndexController] class org.springframework.security.authentication.UsernamePasswordAuthenticationToken
[2012-01-13 08:51:10,062] INFO [WebContainer : 4] [c.b.e.e.w.c.IndexController] class org.springframework.security.core.userdetails.User
[2012-01-13 08:51:10,062] INFO [WebContainer : 4] [c.b.e.e.w.c.IndexController] superadmin
[2012-01-13 08:51:10,073] INFO [WebContainer : 4] [c.b.e.e.w.c.IndexController] superadmin
[2012-01-13 08:51:10,073] INFO [WebContainer : 4] [c.b.e.e.w.c.IndexController] use beanWrapper :
[2012-01-13 08:51:10,095] INFO [WebContainer : 4] [c.b.e.e.w.c.IndexController] property : principal value :[[email protected]: Username: superadmin; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: SuperAdmin]
[2012-01-13 08:51:10,095] INFO [WebContainer : 4] [c.b.e.e.w.c.IndexController] property : principal.username value :[superadmin]
我們在開發WAS是一個完整的版本,
我們當地的WAS是一盞燈,免費developper版
UPDATE
編碼一種變通方法來獲取用戶名的問題與BeenWrapperImpl進一步發生在路上,還是後
org.springframework.beans.NotReadablePropertyException: Invalid property 'codeAndName' of bean class [com.data.model.Country]: Bean property 'codeAndName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:729)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:721)
at org.springframework.web.servlet.tags.form.OptionWriter.doRenderFromCollection(OptionWriter.java:216)
at org.springframework.web.servlet.tags.form.OptionWriter.renderFromCollection(OptionWriter.java:186)
at org.springframework.web.servlet.tags.form.OptionWriter.writeOptions(OptionWriter.java:139)
at org.springframework.web.servlet.tags.form.OptionsTag.writeTagContent(OptionsTag.java:169)
更新 2:
問題更加孤立: 沒有任何depenency春天安全,只有springmvc,
當beanWrapper中沒有setter對應於getter時,它只會在dev中引發一個NotReadablePropertyException異常。
當有一個setter,那麼沒有問題。 假定類UsernamePasswordAuthenticationToken是來自spring安全性的類。類。發現
這是一種解決方法,而不是一個真正的解決方案,所以我會建議把這個問題留給未解決的,如果你仍然希望其他人來:這是失敗的
我BeanWrapper接口代碼與想法。 – 2012-01-20 08:08:21