Announcement Announcement Module
Collapse
No announcement yet.
problems with Spring Security Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problems with Spring Security

    Good afternoon!

    Personal I have the following problem:
    I am developing an application using Spring Security and I have the following problem. When I click on the login page even my username and password being right, my file aplicationContext not doing the redirect to the package "comAutenticacao" as it should do, even if the user has the necessary permissions.

    Below is my code the applicatinContext:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xmlns="http://www.springframework.org/schema/security"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans            
    						http://www.springframework.org/schema/beans/spring-beans-3.0.xsd            
    						
    				        http://www.springframework.org/schema/security
               				http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
                                                
                                          
        <http auto-config="true" access-denied-page="/login.xhtml">   
            <form-login login-page="/login.xhtml" authentication-failure-url="/login.xhtml?error=401"  />
            <logout logout-success-url="/login.xhtml" invalidate-session="true"/> 
        
            <intercept-url pattern="/" access="ROLE_DEFAULT" />
            <intercept-url pattern="/login*/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
            <intercept-url pattern="/js/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
            <intercept-url pattern="/css/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
            <intercept-url pattern="/img/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
           
            <intercept-url pattern="./comAutenticacao*/**" access="ROLE_ADMIN" />
        </http>
     
       
        <authentication-manager>
            <authentication-provider user-service-ref="digestUserDetailService">
            </authentication-provider>
        </authentication-manager>
    
    	<!-- UserDetailService para autenticações DIGEST -->
        <beans:bean id="digestUserDetailService" class="com.rfmagni.tcc.springsecurity.seguranca.UserDetailServiceImpl"/>
        
    </beans:beans>
    Below is my class UserDetailServiceImpl:
    Code:
    @Service
    @Transactional
    public class UserDetailServiceImpl implements UserDetailsService {
    
        @Autowired
        private UsuarioDAO userDAO;
        private UsuarioBean user;
    
        public UserDetails loadUserByUsername(String username)
                throws UsernameNotFoundException, DataAccessException {
    
            if (username != null && !username.equals("")) {
    
                user = (UsuarioBean) userDAO.procurarUsuario(username);
    
                if (user == null) {
                    throw new UsernameNotFoundException("Usuário não encontrado: " + username);
                }
    
                List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
                GrantedAuthorityImpl grantedAuthorityImpl = new GrantedAuthorityImpl("ROLE_DEFAULT");
                authorities.add(grantedAuthorityImpl);
    
                if (user.getPermissaoCollection() != null && !user.getPermissaoCollection().isEmpty()) {
                    for (Permissao p : user.getPermissaoCollection()) {
                        GrantedAuthorityImpl grantedAuthorityTmp = new GrantedAuthorityImpl(p.getRoleDefinition());
                        authorities.add(grantedAuthorityTmp);
                    }
                }
    
                UserDetails userDetails = new UserDetails(user.getPassword(), user.getUsername(), authorities);
    
                return userDetails;
            } else {
                throw new UsernameNotFoundException("Usuário não encontrado: " + username);
            }
    
        }
    }
    Would anyone help me?

  • #2
    Originally posted by narutor99 View Post
    When I click on the login page even my username and password being right, my file aplicationContext not doing the redirect to the package "comAutenticacao" as it should do, even if the user has the necessary permissions.
    What happens instead?

    Comment


    • #3
      Continued on the login page, do not leave it, but not the error.
      I do debug and see my class UserDetailServiceImpl seems that the return is correct.
      If anyone can help me?

      Comment

      Working...
      X