📄 openidauthenticationrequest.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.relyingparty.openid;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.wso2.solutions.identity.relyingparty.RelyingPartyException;
public class OpenIDAuthenticationRequest {
private String returnUrl;
private HttpServletResponse reponse;
private HttpServletRequest request;
private String openIDUrl;
private ArrayList requiredClaims = new ArrayList();
private ArrayList optionalClaims = new ArrayList();
private ArrayList<OpenIDRequestType> requestTypes = new ArrayList<OpenIDRequestType>();
private ArrayList<AuthPolicyType> authTypes = new ArrayList<AuthPolicyType>();
private int maxAuthAge;
public OpenIDAuthenticationRequest(HttpServletRequest request,
HttpServletResponse reponse) {
super();
this.reponse = reponse;
this.request = request;
}
public String getOpenIDUrl() {
return openIDUrl;
}
public void setOpenIDUrl(String openIDUrl) {
this.openIDUrl = openIDUrl;
}
public ArrayList<OpenIDRequestType> getRequestTypes() {
return requestTypes;
}
public HttpServletResponse getReponse() {
return reponse;
}
public void setReponse(HttpServletResponse reponse) {
this.reponse = reponse;
}
public HttpServletRequest getRequest() {
return request;
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}
public String getReturnUrl() {
return returnUrl;
}
public void setReturnUrl(String returnurl) {
this.returnUrl = returnurl;
}
public ArrayList getRequiredClaims() {
return requiredClaims;
}
public int getMaxAuthAge() {
return maxAuthAge;
}
public void setMaxAuthAge(int maxAuthAge) {
this.maxAuthAge = maxAuthAge;
}
public ArrayList<AuthPolicyType> getAuthTypes() {
return authTypes;
}
public ArrayList getOptionalClaims() {
return optionalClaims;
}
/**
* Add requested authentication policies
* @param policyType Requested policy type
*/
public void addAuthPolicy(AuthPolicyType policyType) {
if (!authTypes.contains(policyType)) {
authTypes.add(policyType);
}
}
/**
* Indicate what sort of attributes being requested.
* @param requestType OpenIDRequestType
*/
public void addRequestType(OpenIDRequestType requestType) {
if (!requestTypes.contains(requestType)) {
requestTypes.add(requestType);
}
}
/**
* Add required attributes for Simple Registration. Make sure you have
* already set SIMPLE_REGISTRATION as an RequestType before calling this
* method.
* @param attribute SReg required attribute
* @throws RelyingPartyException
*/
public void addRequiredClaims(String attribute)
throws RelyingPartyException {
addClaims(attribute, requiredClaims);
}
/**
* Add optional attributes for Simple Registration. Make sure you have
* already set SIMPLE_REGISTRATION as an RequestType before calling this
* method.
* @param attribute SReg optional attribute
* @throws RelyingPartyException
*/
public void addOptionalClaims(String attribute)
throws RelyingPartyException {
addClaims(attribute, optionalClaims);
}
/**
* Add required attributes for Attribute Exchange. Make sure you have
* already set ATTRIBUTE_EXCHANGE as an RequestType before calling this
* method.
* @param attribute Name of the attribute
* @param namespace Namespace of the attribute
* @throws RelyingPartyException
*/
public void addRequiredClaims(String attribute, String namespace)
throws RelyingPartyException {
addClaims(attribute, namespace, requiredClaims);
}
/**
* Add optional attributes for Attribute Exchange. Make sure you have
* already set ATTRIBUTE_EXCHANGE as an RequestType before calling this
* method.
* @param attribute Name of the attribute
* @param namespace Namespace of the attribute
* @throws RelyingPartyException
*/
public void addOptionalClaims(String attribute, String namespace)
throws RelyingPartyException {
addClaims(attribute, namespace, optionalClaims);
}
/**
* @param attribute
* @param namespace
* @param claims
* @throws RelyingPartyException
*/
private void addClaims(String attribute, String namespace, ArrayList claims)
throws RelyingPartyException {
OpenIDAxAttribute axAttribute = null;
if (attribute == null || attribute.trim().length() == 0
|| namespace == null || namespace.trim().length() == 0) {
throw new RelyingPartyException("invalidInputParams");
}
axAttribute = new OpenIDAxAttribute(attribute, namespace);
for (Object element : claims) {
if (element instanceof OpenIDAxAttribute) {
OpenIDAxAttribute attr = (OpenIDAxAttribute) element;
if (attr.getAttributeName().equalsIgnoreCase(attribute)
|| attr.getNamespace().equalsIgnoreCase(namespace)) {
throw new RelyingPartyException("duplicatedAttributes");
}
}
}
if (!requestTypes.contains(OpenIDRequestType.ATTRIBUTE_EXCHANGE)) {
requestTypes.add(OpenIDRequestType.ATTRIBUTE_EXCHANGE);
}
claims.add(axAttribute);
}
/**
* @param attribute
* @param claims
* @throws RelyingPartyException
*/
public void addClaims(String attribute, ArrayList claims)
throws RelyingPartyException {
if (attribute == null || attribute.trim().length() == 0) {
throw new RelyingPartyException("invalidInputParams");
}
if (claims.contains(attribute)) {
throw new RelyingPartyException("duplicatedAttributes");
}
if (!requestTypes.contains(OpenIDRequestType.SIMPLE_REGISTRATION)) {
requestTypes.add(OpenIDRequestType.SIMPLE_REGISTRATION);
}
claims.add(attribute);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -