2017-09-04 20 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);