我想在 Java EE 服务器后端对连接到他的 iOS 应用程序的用户进行身份验证。在这里,您可以找到我的 spring 安全配置后端:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/home.mediator" access="permitAll" />
<intercept-url pattern="/loginInvalid.security" access="permitAll" />
<intercept-url pattern="/logout*" access="permitAll" />
<intercept-url pattern="/user**" access="hasRole('ROLE_USER')"/>
<intercept-url pattern="/admin**" access="hasRole('ROLE_ADMIN')"/>
<intercept-url pattern="/*" access="isAuthenticated()" />
<form-login login-page="/home.mediator"
default-target-url="/loginValid.security"
authentication-failure-url="/loginInvalid.security" />
<logout invalidate-session="true"
logout-success-url="/logoutSuccess.security"
logout-url="/logout.do"/>
</http>
<authentication-manager>
<authentication-provider user-service-ref="customUserDetailsService">
</authentication-provider>
</authentication-manager>
</beans:beans>
这可以在后台 Web 应用程序的浏览器上完美运行。但问题是当我使用我的 iOS 目标 C 客户端访问我的后端 Java EE 服务器以进行如下身份验证过程时:
NSString *login = self.loginTextField.text;
NSString *password = self.passwordTextField.text;
NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/myJeeServer/j_spring_security_check"]];
[request setHTTPMethod:@"POST"];
NSString *post =[[NSString alloc] initWithFormat:@"j_username=%@&j_password=%@",login,password];
[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];
NSHTTPURLResponse *urlResponse = nil;
NSError *err;
[NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&err];
NSLog(@"Request : %@",request);
NSLog(@"Response : %d",urlResponse.statusCode);
NSLog(@"Error : %d",err.code);
每次 HTTP 响应状态代码为 200 时,我都无法根据 iOS 客户端检查身份验证是成功还是失败。也许这种方式是使用 Spring 安全后端和 Objective-C 客户端前端实现身份验证的错误方式,但我没有在网上找到任何其他方式。有人可以帮我解决这个安全用例吗?使用 Objective-C 和 Spring 安全性对用户进行身份验证的最佳方法是什么?
感谢您的回答。