Hi,
I have a problem that can't solve googling...
I try to use database for defining user roles.
On this article:
http://www.mularien.com/blog/2008/07...ring-security/
there is good explanation hoe to use this, but I have few questions because I got stupid error.
This is my code/config:
and bean that is hardcoded, just to try...Code:<security:authentication-provider> <security:jdbc-user-service data-source-ref="dataSource"/> </security:authentication-provider> <bean id="dataSource" class="com.mypack.springsecurity.auth.AuthorizationService"> </bean>
and this is more/less all that I found for use of database...Code:public class AuthorizationService implements UserDetailsService { private static Logger log = Logger.getLogger(AuthorizationService.class.getName()); public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { log.info("LOGIN-AUTH: " + username); String userPwd = "21232f297a57a5a743894a0e4a801fc3"; // get pwd of username int userId = 1; // get id of username try { log.info("LOGIN-CHECK-PASSWORD: " + username); return new User(String.valueOf(userId), userPwd, true, true, true, true, getGrantedAuthorities(userId)); } catch(Exception e) { log.info("Failed to login user {" + e.getMessage() + "}"); return null; } } private List<GrantedAuthority> getGrantedAuthorities(int userId) { List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(); GrantedAuthority authority = new GrantedAuthorityImpl("SUPER_ADMIN"); authList.add(authority); return authList; } }
but for some reason I got error:
Is there anything else I need to setup?Code:Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.mypack.springsecurity.auth.AuthorizationService' to required type 'javax.sql.DataSource' for property 'dataSource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.mypack.springsecurity.auth.AuthorizationService] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:462) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:499) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:493) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ... 62 more
In same project I used:
and it worked fine...Code:<authentication-provider> <password-encoder hash="md5"/> <user-service> <user name="admin" password="a564de63c2d0da68cf47586ee05984d7" authorities="ROLE_ADMIN" /> </user-service> </authentication-provider>
Thanks for answer or some good link!
Vedran


Reply With Quote