Authentication Required Dialog popup unexpectedly
I have a Java Web Start program that communicate with server via http invoker. The server is protected by spring security as following:
Code:
<sec:http realm="My App">
<sec:http-basic />
<sec:intercept-url pattern="/remoting/**" access="ROLE_USER" />
</sec:http>
<bean id="myUserDetailsService" class="securityutil.MyUserDetailsService" />
<sec:authentication-manager>
<sec:authentication-provider user-service-ref="myUserDetailsService" />
</sec:authentication-manager>
My RemotingBean.xml is as following:
Code:
<bean id="MyUserBean" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8081/BondWMS4-war/remoting/MyUserBean"/>
<property name="serviceInterface" value="exportBeans.MyUserBean" />
<property name="httpInvokerRequestExecutor" value="org.springframework.security.context.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />
</bean>
My login code is as following:
Code:
public tryLogin(String userName, String password) {
Authentication auth = new UsernamePasswordAuthenticationToken(userName, password);
SecurityContextHolder.getContext().setAuthentication(auth);
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("myappclient/RemotingBean.xml"));
MyUserBean myBean = (MyUserBean) beanFactory.getBean("MyUserBean");
try {
UserInfo userInfo = myBean.getUserInfo(userName, password);
if (userInfo != null) {
JOptionPane.showMessageDialog(this, "Login Successful.");
} else {
JOptionPane.showMessageDialog(this, "Login failed!");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Login failed!");
}
}
If user key in wrong password, a "Authentication Required" dialog by java will popup, and if the user key in correct password this time. My program will show Login failed dialog. This will confuse user.
Please tell me how to suppress "Authentication Required" dialog or get authentication info from "Authentication Required" dialog.
If you have better authentication solution, please tell advice.
Thanks in Advance.