You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by dansei007 <ch...@gmail.com> on 2013/03/18 16:27:12 UTC

Apache Shiro Spring - not redirecting to success url

Team,

I have the following issue in which the application does not redirect to the
success url.

I am using the web servlet filter also, I am using thymeleaf template
engine..

Everytime, I  hit the app URL at  "/list". I get the login screen even after
authentication.

I have written a custom salted realm that uses mongodb (it works
standalone); but, I want to get the file 

based working.  

>From my understanding using the FormAuthenticationFilter (authc), as long as
the params are named, username, password, rememberMe, it will invoke the
login 


I also need some logging help.. I don't see rejections in the app log.

I loaded up the shiro spring example app (samples-spring-1.2.1) and I saw
very good logging  via TRACE.




Here are my configs

logi4j.xml snippet
	
	<logger name="org.apache.shiro">
		
		<level value="debug" />
	</logger>

Here is the appContext snippet.
===============================================================
<beans:bean id="iniRealm" class="org.apache.shiro.realm.text.IniRealm">
		<beans:property name="resourcePath" value="classpath:/shiro.ini" />
	</beans:bean>

	<beans:bean id="securityManager"
class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		<beans:property name="realm" ref="iniRealm" />
	</beans:bean>
	
	<beans:bean id="lifecycleBeanPostProcessor"
class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />

	<beans:bean
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor" />
	
	<beans:bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
		<beans:property name="securityManager" ref="securityManager" />
	</beans:bean>
	
	<beans:bean id="shiroFilter"
class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
		<beans:property name="securityManager" ref="securityManager" />
		<beans:property name="loginUrl" value="/login" />
		<beans:property name="successUrl" value="/userlist" />

		<beans:property name="filterChainDefinitions">
			<beans:value>
                /favicon.ico = anon
                /js* = anon
                /img* = anon
                /*.css = anon
                 # everything else requires authentication:
                /list= authc			
			</beans:value>
		</beans:property>
	</beans:bean>

==================== end appContext snippet ======================


==================== shiro.ini snippet  ======================

[main]

# does the user wish to be remembered?; if not present filter assumes
'rememberMe'

authc.rememberMeParam = rememberme


[users]
# user 'root' with password 'secret' and the 'admin' role
root = secret, admin
# user 'guest' with the password 'guest' and the 'guest' role
guest = guest, guest

[roles]
# 'admin' role has all permissions, indicated by the wildcard '*'
admin = *




--
View this message in context: http://shiro-user.582556.n2.nabble.com/Apache-Shiro-Spring-not-redirecting-to-success-url-tp7578427.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Apache Shiro Spring - not redirecting to success url

Posted by dansei007 <ch...@gmail.com>.
TEam,


I have taken a final look and what I have found is that the
AbstractAuthenticator  never is invoked.

the below is an example of a sucessful authentication event.

Perhaps something in my configuration is wrong?

Thanks in advance!


2013-03-19 00:30:44,923 TRACE | http-bio-8080-exec-6 |
org.apache.shiro.authc.AbstractAuthenticator            | Authentication
attempt received for token [org.apache.shiro.authc.UsernamePasswordToken -
root, rememberMe=false] 
2013-03-19 00:30:44,923 DEBUG | http-bio-8080-exec-6 |
org.apache.shiro.realm.AuthenticatingRealm              | Looked up
AuthenticationInfo [root] from doGetAuthenticationInfo 
2013-03-19 00:30:44,923 DEBUG | http-bio-8080-exec-6 |
org.apache.shiro.realm.AuthenticatingRealm              | AuthenticationInfo
caching is disabled for info [root].  Submitted token:
[org.apache.shiro.authc.UsernamePasswordToken - root, rememberMe=false]. 
2013-03-19 00:30:44,924 DEBUG | http-bio-8080-exec-6 |
o.a.shiro.authc.credential.SimpleCredentialsMatcher     | Performing
credentials equality check for tokenCredentials of type [[C and
accountCredentials of type [java.lang.String] 
2013-03-19 00:30:44,924 DEBUG | http-bio-8080-exec-6 |
o.a.shiro.authc.credential.SimpleCredentialsMatcher     | Both credentials
arguments can be easily converted to byte arrays.  Performing array equals
comparison 
2013-03-19 00:30:44,925 DEBUG | http-bio-8080-exec-6 |
org.apache.shiro.authc.AbstractAuthenticator            | Authentication
successful for token [org.apache.shiro.authc.UsernamePasswordToken - root,
rememberMe=false].  Returned account [root] 




--
View this message in context: http://shiro-user.582556.n2.nabble.com/Apache-Shiro-Spring-not-redirecting-to-success-url-tp7578427p7578439.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Apache Shiro Spring - not redirecting to success url

Posted by dansei007 <ch...@gmail.com>.
Team,

it seems that within the SecurityManager, the SubjectContext is not
resolving the principals.

I will have to programmatically look at the shiro api and see what is
required within the subjectcontext.

Any ideas?

Thanks in advance

 protected SubjectContext resolvePrincipals(SubjectContext context) {
    
            PrincipalCollection principals = context.resolvePrincipals();
    
            if (CollectionUtils.isEmpty(principals)) {
                log.trace("No identity (PrincipalCollection) found in the
context.  Looking for a remembered identity.");
    
                principals = getRememberedIdentity(context);
    
                if (!CollectionUtils.isEmpty(principals)) {
                    log.debug("Found remembered PrincipalCollection.  Adding
to the context to be used " +
                            "for subject construction by the
SubjectFactory.");
    
                    context.setPrincipals(principals);
                    bindPrincipalsToSession(principals, context);
                } else {
                    log.trace("No remembered identity found.  Returning
original context.");
                }
            }
    
            return context;
        }



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Apache-Shiro-Spring-not-redirecting-to-success-url-tp7578427p7578436.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Apache Shiro Spring - not redirecting to success url

Posted by dansei007 <ch...@gmail.com>.
Team,

I updated the logging, and I receive the following each time after
authenticating but I keep getting

redirected back to the login page for protected urls.

It seems like the SecurityManager is not detecting a subject.

any ideas?

TRACE: org.apache.shiro.mgt.DefaultSecurityManager - Context already
contains a SecurityManager instance.  Returning.
TRACE: org.apache.shiro.mgt.DefaultSecurityManager - No identity
(PrincipalCollection) found in the context.  Looking for a remembered
identity.
TRACE: org.apache.shiro.web.servlet.SimpleCookie - No 'rememberMe' cookie
value
TRACE: org.apache.shiro.mgt.DefaultSecurityManager - No remembered identity
found.  Returning original context.
TRACE: org.apache.shiro.subject.support.DelegatingSubject - attempting to
get session; create = false; session is null = false; session has id = true
TRACE: org.apache.shiro.subject.support.DelegatingSubject - attempting to
get session; create = false; session is null = false; session has id = true
TRACE: org.apache.shiro.subject.support.DelegatingSubject - attempting to
get session; create = false; session is null = false; session has id = true
TRACE: org.apache.shiro.subject.support.DelegatingSubject - attempting to
get session; create = false; session is null = false; session has id = true
TRACE: org.apache.shiro.util.ThreadContext - Bound value of type
[org.apache.shiro.web.subject.support.WebDelegatingSubject] for key
[org.apache.shiro.util.ThreadContext_SUBJECT_KEY] to thread
[http-bio-8080-exec-8]
TRACE: org.apache.shiro.util.ThreadContext - Bound value of type
[org.apache.shiro.web.mgt.DefaultWebSecurityManager] for key
[org.apache.shiro.util.ThreadContext_SECURITY_MANAGER_KEY] to thread
[http-bio-8080-exec-8]
TRACE: org.apache.shiro.web.servlet.AbstractShiroFilter - No FilterChain
configured for the current request.  Using the default.
INFO : org.alexsotob.html5form.UserHandler - Welcome home! from Thymeleaf
TRACE: org.apache.shiro.util.ThreadContext - get() - in thread
[http-bio-8080-exec-8]
TRACE: org.apache.shiro.util.ThreadContext - Retrieved value of type
[org.apache.shiro.web.subject.support.WebDelegatingSubject] for key
[org.apache.shiro.util.ThreadContext_SUBJECT_KEY] bound to thread
[http-bio-8080-exec-8]
TRACE: org.apache.shiro.subject.support.DelegatingSubject - attempting to
get session; create = false; session is null = false; session has id = true



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Apache-Shiro-Spring-not-redirecting-to-success-url-tp7578427p7578435.html
Sent from the Shiro User mailing list archive at Nabble.com.