String password = new string ((char[)) token.getcredentials ());
Above: This can pass the test normally.
String password = token.getcredentials (). toString ();
Error:
Org.apache.shiro.authc.IncorrectCredentialsException at Com.accord.shiro01.MyRealm1.getAuthenticationInfo ( MYREALM1.JAVA:32) at Org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication ( modularrealmauthenticator.java:180) at Org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate ( modularrealmauthenticator.java:267) at Org.apache.shiro.authc.AbstractAuthenticator.authenticate ( abstractauthenticator.java:198) at Org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate ( authenticatingsecuritymanager.java:106) at Org.apache.shiro.mgt.DefaultSecurityManager.login ( defaultsecuritymanager.java:270) at Org.apache.shiro.subject.support.DelegatingSubject.login ( delegatingsubject.java:256) at Com.accord.shiro01.LoginLogoutTest.testCustomRealm (loginlogouttest.java:57) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native method) at Sun.reflect.NativeMethodAccessorImpl.invoke ( nativemethodaccessorimpl.java:57) at Sun.reflect.DelegatingMethodAccessorImPl.invoke (delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (method.java:601) at Org.junit.runners.model.frameworkmethod$1.runreflectivecall (frameworkmethod.java:44) at Org.junit.internal.runners.model.ReflectiveCallable.run (reflectivecallable.java:15) at Org.junit.runners.model.FrameworkMethod.invokeExplosively (frameworkmethod.java:41) at Org.junit.internal.runners.statements.InvokeMethod.evaluate (INVOKEMETHOD.JAVA:20) at Org.junit.runners.ParentRunner.runLeaf (parentrunner.java:263) at Org.junit.runners.BlockJUnit4ClassRunner.runChild (blockjunit4classrunner.java:69) at Org.junit.runners.BlockJUnit4ClassRunner.runChild (blockjunit4classrunner.java:48) at Org.junit.runners.parentrunner$3.run (parentrunner.java:231) at Org.junit.runners.parentrunner$1.schedule ( PARENTRUNNER.JAVA:60) at Org.junit.runners.ParentRunner.runChildren (parentrunner.java:229) at org.junit.runners.parentrunner.access$000 (parentrunner.java:50) at Org.junit.runners.parentrunner$2.evalUate (parentrunner.java:222) at Org.junit.runners.ParentRunner.run (parentrunner.java:292) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (JUNIT4TESTREFERENCE.JAVA:50) at Org.eclipse.jdt.internal.junit.runner.TestExecution.run (testexecution.java:38) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:459) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:675) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (remotetestrunner.java:382) at
Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (remotetestrunner.java:192)
Test code:
Public AuthenticationInfo Getauthenticationinfo (Authenticationtoken token)
throws Authenticationexception {
String username = Token.getprincipal (). toString ();
String password = new string ((char[)) token.getcredentials ());
System.out.println (Token.getcredentials ());
System.out.println ((char[]) token.getcredentials ());
SYSTEM.OUT.PRINTLN (password);
System.out.println ("----------------");
String password2 = Token.getcredentials (). toString ();
System.out.println (Token.getcredentials ());
System.out.println (PASSWORD2);
if (! () Zhangsan ". Equals (username))) {
throw new unknownaccountexception ();
}
if (! () 123 ". Equals (password))) {
throw new incorrectcredentialsexception ();
}
return new Simpleauthenticationinfo (username, password, getName ());
}
Results:
[c@7aa91b
123
123
----------------
[c@7aa91b
[c@7aa91b
Note: string password = new string ((char[)) token.getcredentials ());