📄 openiduserapprovalaction.java
字号:
/*
* Copyright 2005-2008 WSO2, Inc. (http://wso2.com)
*
* 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 org.wso2.solutions.identity.user.ui.action;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.StrutsStatics;
import org.openid4java.message.ParameterList;
import org.wso2.solutions.identity.IdentityConstants;
import org.wso2.solutions.identity.admin.RelyingPartyAdmin;
import org.wso2.solutions.identity.admin.ReportAdmin;
import org.wso2.solutions.identity.persistence.IPPersistenceManager;
import org.wso2.solutions.identity.persistence.dataobject.ActionDO;
import org.wso2.solutions.identity.persistence.dataobject.OpenIDUserRPDO;
import org.wso2.solutions.identity.user.ui.util.UserUtil;
import com.opensymphony.xwork2.ActionContext;
public class OpenIDUserApprovalAction extends ManagedAction {
/**
*
*/
private static final long serialVersionUID = 2836760032315263963L;
private String profileName;
/**
* This will get executed during user approval
*/
public String execute() throws Exception {
ActionContext context = null;
HttpServletRequest request = null;
String authenticatedAndApproved = null;
String action = null;
String submitAction = null;
try {
context = ActionContext.getContext();
request = (HttpServletRequest) context
.get(StrutsStatics.HTTP_REQUEST);
ParameterList requestp = (ParameterList) request.getSession()
.getAttribute(IdentityConstants.OpenId.PARAM_LIST);
submitAction = ((String[]) request.getParameterMap()
.get("approval"))[0];
if (submitAction.equals("Only Once")) {
action = IdentityConstants.OpenId.COMPLETE;
authenticatedAndApproved = "once";
} else if (submitAction.equals("Always")) {
action = IdentityConstants.OpenId.COMPLETE;
authenticatedAndApproved = "always";
} else if (submitAction.equals("Denyy")) {
action = IdentityConstants.OpenId.CANCEL;
authenticatedAndApproved = "false";
}
String rpUrl = requestp
.getParameterValue(IdentityConstants.OpenId.ATTR_RETURN_TO);
String openididentity = requestp
.getParameterValue(IdentityConstants.OpenId.ATTR_IDENTITY);
rpUrl = UserUtil.getRelyingPartyUrl(rpUrl);
if (openididentity == null || rpUrl == null) {
addErrorMessage(getText("openid_required"));
return ERROR;
}
String userName = UserUtil.getUserName(openididentity);
OpenIDUserRPDO rpdo = null;
rpdo = new OpenIDUserRPDO();
String message = null;
if (action.equalsIgnoreCase(IdentityConstants.OpenId.COMPLETE)) {
Date date = new Date();
if (authenticatedAndApproved.equalsIgnoreCase("once")) {
rpdo.setIsTrustedAlways(false);
message = getText("successful_for",
new String[] { userName });
ReportAdmin.record(userName,
ActionDO.ACTION_USER_APPROVED_OPENID_RP_ONCE,
message);
} else if (authenticatedAndApproved.equalsIgnoreCase("always")) {
message = getText("successful_for",
new String[] { userName });
ReportAdmin.record(userName,
ActionDO.ACTION_USER_APPROVED_OPENID_RP_ALWAYS,
message);
rpdo.setIsTrustedAlways(true);
}
rpdo.setLastVisit(date);
rpdo.setUserName(userName);
rpdo.setRpUrl(rpUrl);
rpdo.setDefaultProfileName(profileName);
} else {
message = getText("successful_for", new String[] { userName });
ReportAdmin
.record(userName,
ActionDO.ACTION_USER_APPROVED_OPENID_RP_DENIED,
message);
return ERROR;
}
IPPersistenceManager db = IPPersistenceManager
.getPersistanceManager();
RelyingPartyAdmin admin = new RelyingPartyAdmin();
OpenIDUserRPDO[] rpdos = null;
rpdos = db.getOpenIDUserRP(userName, rpUrl);
if (rpdos != null && rpdos.length > 0) {
OpenIDUserRPDO existingDO = null;
existingDO = rpdos[0];
rpdo.setVisitCount(existingDO.getVisitCount() + 1);
rpdo.setId(existingDO.getId());
admin.update(rpdo);
} else {
rpdo.setVisitCount(1);
admin.create(rpdo);
}
} catch (Exception e) {
return ERROR;
}
return SUCCESS;
}
public void setProfileName(String profileName) {
this.profileName = profileName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -