📄 openidsubmitaction.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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.StrutsStatics;
import org.wso2.solutions.identity.IdentityConstants;
import org.wso2.solutions.identity.relyingparty.RelyingPartyException;
import org.wso2.solutions.identity.relyingparty.openid.OpenIDAuthenticationRequest;
import org.wso2.solutions.identity.relyingparty.openid.OpenIDConsumer;
import org.wso2.solutions.identity.relyingparty.openid.OpenIDRequestType;
import org.wso2.utils.ServerConfiguration;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
public class OpenIDSubmitAction extends ActionSupport {
private static final long serialVersionUID = 152947298858636931L;
private String openIdUrl;
/**
* This will get executed once the OpenID user name/password submitted
*/
public String execute() throws Exception {
ActionContext context = null;
OpenIDConsumer consumer = null;
HttpServletResponse response = null;
HttpServletRequest request = null;
OpenIDAuthenticationRequest openIDAuthRequest = null;
try {
context = ActionContext.getContext();
response = (HttpServletResponse) context
.get(StrutsStatics.HTTP_RESPONSE);
request = (HttpServletRequest) context
.get(StrutsStatics.HTTP_REQUEST);
openIDAuthRequest = new OpenIDAuthenticationRequest(request,
response);
openIDAuthRequest.setOpenIDUrl(getOpenIdUrl());
openIDAuthRequest
.addRequestType(OpenIDRequestType.SIMPLE_REGISTRATION);
// Set the required claims - I need these claims from the OpenID
// Provider.
openIDAuthRequest
.addRequiredClaims(IdentityConstants.OpenId.SimpleRegAttributes.NICK_NAME);
openIDAuthRequest
.addRequiredClaims(IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME);
openIDAuthRequest
.addRequiredClaims(IdentityConstants.OpenId.SimpleRegAttributes.EMAIL);
openIDAuthRequest
.addRequiredClaims(IdentityConstants.OpenId.SimpleRegAttributes.DOB);
openIDAuthRequest
.addRequiredClaims(IdentityConstants.OpenId.SimpleRegAttributes.GENDER);
openIDAuthRequest
.addRequiredClaims(IdentityConstants.OpenId.SimpleRegAttributes.POSTAL_CODE);
openIDAuthRequest
.addRequiredClaims(IdentityConstants.OpenId.SimpleRegAttributes.COUNTRY);
openIDAuthRequest
.addRequiredClaims(IdentityConstants.OpenId.SimpleRegAttributes.LANGUAGE);
openIDAuthRequest
.addRequiredClaims(IdentityConstants.OpenId.SimpleRegAttributes.TIMEZONE);
ServerConfiguration serverConfig = null;
String host = null;
String httpsPort = null;
serverConfig = ServerConfiguration.getInstance();
host = serverConfig.getFirstProperty("HostName");
httpsPort = serverConfig.getFirstProperty("Ports.HTTPS");
openIDAuthRequest.setReturnUrl("https://" + host + ":" + httpsPort
+ "/" + "OpenIDCallback.action");
consumer = OpenIDConsumer.getInstance();
consumer.doOpenIDAuthentication(openIDAuthRequest);
} catch (RelyingPartyException e) {
return ERROR;
}
return SUCCESS;
}
@RequiredStringValidator(message = "", key = "openIdUrl")
public String getOpenIdUrl() {
return openIdUrl;
}
public void setOpenIdUrl(String openIdUrl) {
this.openIdUrl = openIdUrl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -