Results 1 to 5 of 5

Thread: Good example how to use database for user loging / roles

Threaded View

  1. #1
    Join Date
    Sep 2011
    Posts
    1

    Default Problem: Any example how to use database for user loging / roles

    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:
    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 bean that is hardcoded, just to try...

    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;
    	}
    }
    and this is more/less all that I found for use of database...

    but for some reason I got error:

    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
    Is there anything else I need to setup?

    In same project I used:

    Code:
        <authentication-provider>
            <password-encoder hash="md5"/>
            <user-service>
                <user name="admin" password="a564de63c2d0da68cf47586ee05984d7" authorities="ROLE_ADMIN" />
    	    </user-service>
    	</authentication-provider>
    and it worked fine...

    Thanks for answer or some good link!

    Vedran
    Last edited by tkojemile; Sep 25th, 2011 at 10:16 PM. Reason: Confusing subject

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •