我在我的应用中使用了MFP8。我正在使用安全检查框架来验证用户。为了验证用户,我使用了一些后端层来验证用户。一旦用户通过身份验证,我的后端服务将返回巨大的JSON。现在,我需要将此响应发送给客户端。
PFB我在UserLogin适配器中尝试过的代码。无论来自我的后端层的响应是JSON格式的非常大的响应(75-80KB)。请帮助如何将此响应从安全检查发送到客户端
附言:
public class UserLoginResource extends UserAuthenticationSecurityCheck {
private String userId, displayName,errorMsg, cdata, hdata, rid, urlParams, serviceName, queryParameters;
private boolean rememberMe = false;
private boolean authFlag=true;
public static JSONObject queryResponse;
private Map<String, Object> attributes = new HashMap<String, Object>();
@Context
AdapterSecurityContext adapterSecurityContext;
@Override
protected AuthenticatedUser createUser() {
System.out.println("User Authenticated Result "+ userId);
return new AuthenticatedUser(userId, displayName, this.getName(), attributes);
}
@Override
protected boolean validateCredentials(Map<String, Object> credentials) {
try{
String username=credentials.get("username").toString();
String password = credentials.get("password").toString(); ;
if (username != null && password != null) {
queryResponse = <my backend layer>(username, password);
if(queryResponse.errorExist){
System.out.println("User Authentication Failed");
errorMsg="User Authentication Failed";
return false;
}
else{
System.out.println("User Authentication Sucessful");
userId=queryResponse.userid;
displayName=queryResponse.fullname;
attributes.put("queryParams", queryResponse.toString());
authFlag=false;
errorMsg = null;
return true;
}
}
}
catch(Exception e){
e.printStackTrace();
authFlag =true;
return false;
}
return false;
}
}发布于 2017-09-06 23:04:03
我建议您重新设计您的身份验证流程。
SecurityCheck适配器的设计就像它的名字所暗示的那样-安全检查。理想情况下,validateCredentials方法应该(针对后端/LDAP/服务或其他方式)验证您的凭据,并且来自安全检查的响应应该是关于您可能需要的身份验证和自定义属性的信息。
请注意,安全检查是有状态的,并保留其交互状态。在每次授权或自省请求时,安全框架从外部存储检索相关安全检查的状态,并在请求处理结束时,将安全检查状态存储回外部存储。使用您所询问的方法,响应也将成为状态的一部分,并因序列化和反序列化而导致性能损失。这不适合负载过重的系统。
请参阅Security-check state management。
理想情况下,您应该延迟JSON请求和对将请求它的资源适配器的响应,使用Security Check进行post身份验证。
如果您真的希望保留现在拥有的模型,则应该将自定义JSON响应标记为transient,以防止其序列化(并成为SecurityCheck状态的一部分),并在自定义映射中发送回数据,该映射是您已经在使用的AuthenticatedUser构造函数的一部分:
AuthenticatedUser(String id,String displayName,String securityCheckName,Map attributes);
return new AuthenticatedUser(userId, displayName, this.getName(), attributes);https://stackoverflow.com/questions/46032205
复制相似问题