java - SimpleGrantedAuthority cannot be cast to GrantedAuthority -


the specific error is:

exception handling request /login: java.lang.classcastexception: org.springframework.security.core.authority.simplegrantedauthority cannot cast org.springframework.security.core.grantedauthority. 

update: complete stacktrace

error [io.undertow.request] (default task-9) ut005023: exception handling request /login: java.lang.classcastexception: org.springframework.security.core.authority.simplegrantedauthority cannot cast org.springframework.security.core.grantedauthority @ org.springframework.security.authentication.abstractauthenticationtoken.<init>(abstractauthenticationtoken.java:62) @ org.springframework.security.authentication.usernamepasswordauthenticationtoken.<init>(usernamepasswordauthenticationtoken.java:73) @ com.actividades.components.customauthenticationprovider.authenticate(customauthenticationprovider.java:38) @ org.springframework.security.authentication.providermanager.authenticate(providermanager.java:174) @ org.springframework.security.authentication.providermanager.authenticate(providermanager.java:199) @ org.springframework.security.web.authentication.usernamepasswordauthenticationfilter.attemptauthentication(usernamepasswordauthenticationfilter.java:94) @ org.springframework.security.web.authentication.abstractauthenticationprocessingfilter.dofilter(abstractauthenticationprocessingfilter.java:218) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:331) @ org.springframework.security.web.authentication.logout.logoutfilter.dofilter(logoutfilter.java:121) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:331) @ org.springframework.security.web.csrf.csrffilter.dofilterinternal(csrffilter.java:124) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:331) @ org.springframework.security.web.header.headerwriterfilter.dofilterinternal(headerwriterfilter.java:66) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:331) @ org.springframework.security.web.context.request.async.webasyncmanagerintegrationfilter.dofilterinternal(webasyncmanagerintegrationfilter.java:56) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:331) @ org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter.java:106) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:331) @ org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:214) @ org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:177) @ org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:346) @ org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:262) @ io.undertow.servlet.core.managedfilter.dofilter(managedfilter.java:60) @ io.undertow.servlet.handlers.filterhandler$filterchainimpl.dofilter(filterhandler.java:131) @ io.undertow.servlet.handlers.filterhandler.handlerequest(filterhandler.java:84) @ io.undertow.servlet.handlers.security.servletsecurityrolehandler.handlerequest(servletsecurityrolehandler.java:62) @ io.undertow.servlet.handlers.servletdispatchinghandler.handlerequest(servletdispatchinghandler.java:36) @ org.wildfly.extension.undertow.security.securitycontextassociationhandler.handlerequest(securitycontextassociationhandler.java:78) @ io.undertow.server.handlers.predicatehandler.handlerequest(predicatehandler.java:43) @ io.undertow.servlet.handlers.security.sslinformationassociationhandler.handlerequest(sslinformationassociationhandler.java:131) @ io.undertow.servlet.handlers.security.servletauthenticationcallhandler.handlerequest(servletauthenticationcallhandler.java:57) @ io.undertow.server.handlers.predicatehandler.handlerequest(predicatehandler.java:43) @ io.undertow.security.handlers.abstractconfidentialityhandler.handlerequest(abstractconfidentialityhandler.java:46) @ io.undertow.servlet.handlers.security.servletconfidentialityconstrainthandler.handlerequest(servletconfidentialityconstrainthandler.java:64) @ io.undertow.security.handlers.authenticationmechanismshandler.handlerequest(authenticationmechanismshandler.java:60) @ io.undertow.servlet.handlers.security.cachedauthenticatedsessionhandler.handlerequest(cachedauthenticatedsessionhandler.java:77) @ io.undertow.security.handlers.notificationreceiverhandler.handlerequest(notificationreceiverhandler.java:50) @ io.undertow.security.handlers.abstractsecuritycontextassociationhandler.handlerequest(abstractsecuritycontextassociationhandler.java:43) @ io.undertow.server.handlers.predicatehandler.handlerequest(predicatehandler.java:43) @ org.wildfly.extension.undertow.security.jacc.jacccontextidhandler.handlerequest(jacccontextidhandler.java:61) @ io.undertow.server.handlers.predicatehandler.handlerequest(predicatehandler.java:43) @ io.undertow.server.handlers.predicatehandler.handlerequest(predicatehandler.java:43) @ io.undertow.servlet.handlers.servletinitialhandler.handlefirstrequest(servletinitialhandler.java:284) @ io.undertow.servlet.handlers.servletinitialhandler.dispatchrequest(servletinitialhandler.java:263) @ io.undertow.servlet.handlers.servletinitialhandler.access$000(servletinitialhandler.java:81) @ io.undertow.servlet.handlers.servletinitialhandler$1.handlerequest(servletinitialhandler.java:174) @ io.undertow.server.connectors.executeroothandler(connectors.java:202) @ io.undertow.server.httpserverexchange$1.run(httpserverexchange.java:793) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745) 

in class, create list of grantedauthority objects , use own role class wrapper implements grantedauthority:

public collection<grantedauthority> getauthorities() {     list<grantedauthority> simplegrantedauthoritylist = new arraylist<>();     for(rol rol : usuario.getroles()){         simplegrantedauthoritylist.add(new simplegrantedauthority(rol.getname()));     }     return simplegrantedauthoritylist; } 

and use authorities create logged user in system:

collection<grantedauthority> authorities = user.getauthorities();      return new usernamepasswordauthenticationtoken(user, password, authorities); 

the 500 error appears when try create new usernamepasswordauthenticationtoken object params.

i use dependencies of spring:

<dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-context</artifactid>             <version>4.2.6.release</version>         </dependency>       <dependency>           <groupid>org.springframework</groupid>           <artifactid>spring-core</artifactid>           <version>4.2.6.release</version>       </dependency>       <dependency>           <groupid>org.springframework.security</groupid>           <artifactid>spring-security-web</artifactid>           <version>4.1.0.release</version>       </dependency>       <dependency>             <groupid>org.springframework.security</groupid>             <artifactid>spring-security-config</artifactid>             <version>4.1.0.release</version>         </dependency>         <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-web</artifactid>             <version>4.2.6.release</version>         </dependency>         <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-webmvc</artifactid>             <version>4.2.6.release</version>         </dependency>         <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-orm</artifactid>             <version>4.2.6.release</version>         </dependency>         <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-beans</artifactid>             <version>4.2.6.release</version>         </dependency>         <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-tx</artifactid>             <version>4.2.6.release</version>         </dependency>         <dependency>             <groupid>org.thymeleaf</groupid>             <artifactid>thymeleaf-spring4</artifactid>             <version>3.0.0.release</version>         </dependency>         <dependency>             <groupid>org.thymeleaf.extras</groupid>             <artifactid>thymeleaf-extras-springsecurity4</artifactid>             <version>3.0.0.release</version>         </dependency>         <dependency>             <groupid>org.thymeleaf.extras</groupid>             <artifactid>thymeleaf-extras-java8time</artifactid>             <version>3.0.0.release</version>         </dependency> 

we deploy project on wildfly 10.0.0 , compile project java 8.

any suggestions? try find 500 error via google , had no luck finding solution.

solved

the classloaders different initial object. have project divided modules , having problem. moved code module have classes , not create problems.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -