2017-09-04 21 views
0

我在我的应用程序中使用MFP8。我正在使用安全检查框架来验证用户。为了验证用户,我正在使用一些后端图层来验证用户。一旦用户验证我的后端服务将返回巨大的JSON。现在我需要将此响应发送给客户端。安全检查后IBM MFP8 Respnse

PFB我在UserLogin适配器中试过的代码。来自后端层的响应是JSON格式非常巨大的响应(75-80KB)。请帮助如何将这种响应从安检发送到客户端

P.S:

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; 

    } 
} 

回答

2

我建议你重新设计你的认证流程。

SecurityCheck适配器的设计宗旨是完成名称所暗示的安全检查。理想情况下,validateCredentials方法应验证您的凭据(针对后端/ LDAP /服务或其他方式),并且您的安全检查的响应应该是有关您可能需要的身份验证身份和自定义属性的信息。

请注意,安全检查是有状态的并保留其交互状态。在每个授权或内省请求中,安全框架将从外部存储中检索相关安全检查的状态,并在请求处理结束时将安全检查状态存储回外部存储中。采用您所问的方法,响应也会成为国家的一部分,并会因序列化和反序列化而受到性能处罚。这不适用于重负载系统。

请参阅Security-check state management

理想情况下,您应该推迟JSON请求并响应将请求它的资源适配器,然后使用安全检查进行身份验证。

如果你真的想保持你现在的模式,你应该标记您的自定义JSON响应,transient以防止它的序列化(和SecurityCheck状态成为部分)和数据发回自定义地图是您正在使用您的AuthenticatedUser构造的一部分:

AuthenticatedUser(ID字符串,字符串显示名,字符串 securityCheckName,地图属性);

return new AuthenticatedUser(userId, displayName, this.getName(), attributes);