com.mycomm.itool.AuthAPI.core.MyAuthNContext Maven / Gradle / Ivy
/*
* Copyright 2018 jw362j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mycomm.itool.AuthAPI.core;
import com.mycomm.itool.AuthAPI.API.AuthNContext;
import com.mycomm.itool.AuthAPI.base.BaseAuthNContext;
import com.mycomm.itool.AuthAPI.bean.TokenStatus;
import com.mycomm.itool.AuthAPI.bean.UsrInforBean;
import com.mycomm.itool.AuthAPI.bean.UsrInforError;
import com.mycomm.itool.AuthAPI.util.HttpProviders;
import com.mycomm.itool.AuthAPI.util.TokenValidationListener;
import com.mycomm.itool.AuthAPI.util.UsrInforListener;
/**
*
* @author jw362j
*/
public class MyAuthNContext extends BaseAuthNContext {
private TokenStatus usrTokenValidationResult;
private UsrInforBean inforBean;
private MyAuthNContext(String requestUrl) {
if (requestUrl.endsWith("/")) {
this.mRequestUrl = requestUrl;
} else {
this.mRequestUrl = requestUrl + "/";
}
}
public static AuthNContext getAuthNContext(String requestUrl) {
if ("".equals(requestUrl) || requestUrl == null) {
throw new IllegalArgumentException("requestUrl is null!");
}
return new MyAuthNContext(requestUrl);
}
public void usrLogout(String usrToken) {
HttpProviders.usrLogout(this.mRequestUrl + "usrLogout.xhtml", usrToken);
}
public TokenStatus usrTokenValidation(String usrToken) {
TokenStatus result = TokenStatus.TokenStatus_FAILED;
HttpProviders.usrTokenValidation(this.mRequestUrl + "usrTokenValidation.xhtml", usrToken, new TokenValidationListener() {
public void onResponse(TokenStatus tokenStatus) {
usrTokenValidationResult = tokenStatus;
}
});
return usrTokenValidationResult;
}
public UsrInforBean loadUsrInfor(String usrToken) {
HttpProviders.loadUsrInfor(this.mRequestUrl + "loadUsrInfor.xhtml", usrToken, new UsrInforListener() {
public void onSuccess(UsrInforBean usrInforBean) {
inforBean = usrInforBean;
}
public void onFailed(UsrInforError usrInforError) {
}
});
return inforBean;
}
}