📄 openidpape.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.openid.extensions;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openid4java.message.AuthRequest;
import org.openid4java.message.MessageException;
import org.openid4java.message.MessageExtension;
import org.openid4java.message.pape.PapeMessage;
import org.openid4java.message.pape.PapeRequest;
import org.openid4java.message.pape.PapeResponse;
import org.wso2.solutions.identity.IdentityConstants;
import org.wso2.solutions.identity.IdentityProviderException;
import org.wso2.solutions.identity.openid.OpenIDAuthenticationRequest;
public class OpenIDPape extends OpenIDExtension {
private OpenIDAuthenticationRequest request;
private static Log log = LogFactory.getLog(OpenIDPape.class);
/**
* Constructed during building the response
* @param request An instance of OpenIDAuthenticationRequest
*/
public OpenIDPape(OpenIDAuthenticationRequest request) {
this.request = request;
}
public void addRequiredAttributes(List<String> requiredAttributes)
throws IdentityProviderException {
}
/**
* Creates an instance of MessageExtension for the OpenID authentication
* response
* @param request OpenID authentication request
* @return An instance of MessageExtension
* @throws RelyingPartyException
*/
public MessageExtension getMessageExtension(String userId,
String profileName) throws IdentityProviderException {
MessageExtension message = null;
PapeResponse papeResponse = null;
AuthRequest authRequest = null;
try {
authRequest = request.getAuthRequest();
message = authRequest.getExtension(PapeMessage.OPENID_NS_PAPE);
if (message instanceof PapeRequest) {
papeResponse = PapeResponse.createPapeResponse();
if (request.isPhishingResistanceLogin()) {
papeResponse
.addAuthPolicy(PapeMessage.PAPE_POLICY_PHISHING_RESISTANT);
papeResponse.setNistAuthLevel(1);
}
if (request.isMultifactorLogin()) {
papeResponse
.addAuthPolicy(PapeMessage.PAPE_POLICY_MULTI_FACTOR);
papeResponse.setNistAuthLevel(2);
}
}
} catch (MessageException e) {
throw new IdentityProviderException(
IdentityConstants.ErrorCodes.OPENID_RESP_GENERATION_FAILED,
e);
}
return papeResponse;
}
/**
* @param authRequest
* @return
* @throws IdentityProviderException
*/
public static String[] getAuthenticationPolicies(AuthRequest authRequest)
throws IdentityProviderException {
MessageExtension message = null;
PapeRequest papeRequest = null;
List preferredPolicies = null;
try {
if (authRequest.hasExtension(PapeMessage.OPENID_NS_PAPE)) {
message = authRequest.getExtension(PapeMessage.OPENID_NS_PAPE);
if (message instanceof PapeRequest) {
papeRequest = (PapeRequest) message;
preferredPolicies = papeRequest
.getPreferredAuthPoliciesList();
if (preferredPolicies != null
&& !preferredPolicies.isEmpty())
return (String[]) preferredPolicies
.toArray(new String[preferredPolicies.size()]);
}
}
return null;
} catch (MessageException e) {
throw new IdentityProviderException(
IdentityConstants.ErrorCodes.OPENID_RESP_GENERATION_FAILED,
e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -