【问题标题】:IBM Mobilefirst JAVA adapter giving MFP-Conflict=Concurrency failure while storing user dataIBM Mobilefirst JAVA 适配器在存储用户数据时出现 MFP-Conflict=Concurrency 失败
【发布时间】:2024-01-21 12:15:01
【问题描述】:

我正在构建一个 JAVA HTTP 适配器,我正在使用以下方法在 UserAuthenticationSecurityCheck 类中对用户进行身份验证

 @Override
            protected AuthenticatedUser createUser() {
                return new AuthenticatedUser(userId, logonId, this.getName(), attributes);
            }

 @Override
    protected boolean validateCredentials(Map<String, Object> credentials) {
        return false;
    }

在此控件转到 android 应用程序后,他们调用名为 /updateClientRegistrtion 的 REST API,该 API 将更新 ClientRegistrationData

@GET
public Response updateClientRegistartion(@Context HttpServletRequest request) {
        AuthenticatedUser authUser = securityContext.getAuthenticatedUser();
        Map<String, Object> attributes = authUser.getAttributes();
        ClientData clientData = securityContext.getClientRegistrationData();
        clientData.getProtectedAttributes().put(some parameter);
        if (clientData.getClientId() != null) {
        securityContext.storeClientRegistrationData(clientData);
} 

但是这段代码给了我类似的错误


异常消息: 409; headers=[ MFP-Conflict=并发失败];身体={}


这个问题有什么解决办法吗?有人可以帮我解决这个问题。 教程如下:http://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/user-authentication/security-check/

【问题讨论】:

    标签: java jax-rs ibm-mobilefirst adapter


    【解决方案1】:
    409; headers=[ MFP-Conflict=Concurrency failure]; body={}
    

    当并发请求尝试将属性存储到同一行或该行中的数据在更新之前被另一个请求修改时的结果。

    这可能是由于请求被多次触发(非常接近)。另一种可能性是,当一个请求处理内存中的数据时,另一个请求已经修改和更新了它。

    没有该行代码应该仍然可以工作:

    securityContext.storeClientRegistrationData(clientData);
    

    试试看。

    或者,在周围放置一个 try-catch

    storeClientRegistrationData(clientData)

    然后在 catch 块中重试。

    【讨论】:

    • 嗨,如果我删除 storeClientRegistrationData() 并用 clientData.getProtectedAttributes().put(some parameter) 结束我的方法; ,客户端注册数据会被保存吗?
    最近更新 更多