IdentityServicesHandler.java revision 2cdbc4fc62ed8b9c2c8ef660adc4fe0188b65407
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: IdentityServicesHandler.java,v 1.7 2008/12/15 19:50:21 arviranga Exp $
*
*/
/*
* Portions Copyrighted 2011-2014 ForgeRock AS.
* Portions Copyrighted 2012 Open Source Solution Technology Corporation
*/
/**
* Provides a marshall/unmarshall layer to the Security interface.
*/
public class IdentityServicesHandler extends HttpServlet {
private static final long serialVersionUID = 2774677132209419157L;
// =======================================================================
// Constants
// =======================================================================
// =======================================================================
// Fields
// =======================================================================
private IdentityServicesFactory factory;
private String lbCookieName;
private String lbCookieValue;
// =======================================================================
// =======================================================================
/**
* Loads the init parameters for use in the HTTP methods.
*
* @see javax.servlet.GenericServlet#init()
*/
public void init() throws ServletException {
super.init();
// determine if the provider is correct..
try {
// get the security provider from the params.
} catch (Exception e) {
// wrap in a servlet exception as to not scare the natives..
throw new ServletException(e);
}
}
// =======================================================================
// HTTP Methods
// =======================================================================
/**
* Determines unmarshalls the request and executes the proper method based
* on the request parameters.
*
* @see javax.servlet.http.HttpServlet#service(HttpServletRequest request,
* HttpServletResponse response)
*/
}
//set headers before executing the method, so they are set even if exception is being thrown
}
// =======================================================================
// Helper Methods
// =======================================================================
/**
* Get a consistent behaviour between application servers..
*/
}
return ret;
}
{
}
private void initLbCookieSettings() {
}
return;
}
return;
}
}
}
try {
// unable to set lb cookie
}
}
/**
* Enum to get the request parameters and test w/ the SecurityMethods.
*/
public static class SecurityParameter {
public static final SecurityParameter URI =
new SecurityParameter("URI");
public static final SecurityParameter ACTION =
new SecurityParameter("ACTION");
public static final SecurityParameter USERNAME =
new SecurityParameter("USERNAME");
public static final SecurityParameter PASSWORD =
new SecurityParameter("PASSWORD");
public static final SecurityParameter CLIENT =
new SecurityParameter("CLIENT");
public static final SecurityParameter TOKENID =
public static final SecurityParameter SUBJECTID =
public static final SecurityParameter IDENTITY =
public static final SecurityParameter ATTRIBUTENAMES =
new SecurityParameter("ATTRIBUTENAMES",
public static final SecurityParameter LOGNAME =
new SecurityParameter("LOGNAME");
public static final SecurityParameter MESSAGE =
new SecurityParameter("MESSAGE");
public static final SecurityParameter MESSAGECODE =
new SecurityParameter("MESSAGECODE");
public static final SecurityParameter APPID =
public static final SecurityParameter ADMIN =
public static final SecurityParameter NAME =
new SecurityParameter("NAME");
public static final SecurityParameter FILTER =
new SecurityParameter("FILTER");
public static final SecurityParameter ATTRIBUTES =
public static final SecurityParameter REFRESH =
// ===================================================================
// Fields
// ===================================================================
}
}
return name;
}
} else if (this.type == IdentityDetails.class) {
} else {
}
return ret;
}
}
}
return ret;
}
try {
// Check the cookie value "iPlanetDirectoryPro"
}
} catch (SSOException ex) {
// Ignore the exception, and no valid token
}
}
}
return ret;
}
}
}
}
return ret;
}
{
}
return ret;
}
{
break;
}
String attrValues[] =
}
}
if (attributeList == null) {
attributeList = new ArrayList();
}
} else {
// Add empyt attribute
if (attributeList == null) {
attributeList = new ArrayList();
}
}
}
}
}
return ret;
}
{
if (!isBlank(identityName)) {
rv = new IdentityDetails();
}
}
}
}
}
}
}
}
}
}
}
break;
}
String attrValues[] =
if (attrValues != null) {
}
}
} else {
}
}
}
}
}
return rv;
}
}
/**
* Defined by the interface 'com.sun.identity.idsvcs.Security'.
*/
public static class SecurityMethod {
// ===================================================================
// Constructors
// ===================================================================
SecurityParameter[] params) {
final Method[] SECURITY_METHODS =
IdentityServicesImpl.class.getMethods();
// find the method
Method m = SECURITY_METHODS[i];
// found the method by name..
// lets check based on parameters..
imethod = m;
break;
}
}
// need to throw if we can't find it..
throw new IllegalArgumentException();
}
// set the internal fields
this.parameters = params;
}
}
}
}
// ===================================================================
// Fields
// ===================================================================
final SecurityParameter[] parameters;
throws ServletException, IOException {
// find the security method from the path..
// Set the respone content type
} else {
}
}
try {
// Throw Unsupported Operation Exception
return;
}
// Respect Zero-Page Login Settings
throw new UnsupportedOperationException("Zero-page login is not allowed");
}
// execute the method w/ the parameters..
// marshall the response..
} else {
}
}
} catch (ObjectNotFound ex) {
// write out the proper ObjectNotFound exception.
// set the response error code
try {
} catch (Exception e) {
// something really went wrong so just give up..
throw new ServletException(e);
}
} catch (GeneralFailure ex) {
// write out the proper security based exception..
try {
} catch (Exception e) {
// something really went wrong so just give up..
throw new ServletException(e);
}
} catch (Throwable e) {
try {
// something really went wrong so just give up..
if (e instanceof UnsupportedOperationException) {
} else if (e instanceof OrgInactive || e instanceof UserLocked
|| e instanceof UserInactive || e instanceof AccountExpired
|| e instanceof MaximumSessionReached){
} else if (e instanceof InvocationTargetException) {
} else {
}
throw new ServletException(ex);
}
} finally {
}
}
}
private static boolean isZeroPageLoginAllowed(HttpServletRequest request) throws AuthException, SMSException,
}
/**
* Gets the realm being used for this request by parsing the query parameters on the URI parameter (if present).
* This matches the logic used in opensso/IdentityServicesImpl. Defaults to "/".
*/
break;
}
}
}
return realm;
}
/**
* If both exist on the path then return JSON, XML, and then Properites
* in that order.
*/
// default is properties format
}
throws Throwable
{
// find the value for each parameter..
if (parameters != null) {
}
}
try {
// Special case for authentication.
// If parameters are null and if already authenitcated
// i.e., iPlanetDirectoryPro cookie is present, send the
// SSOToken
// username & password is null for the authenticate method
// Check for iPlanetDirectoryPro cookie
try {
// Contruct Token object
ret = t;
}
} catch (SSOException ssoe) {
// SSOToken not present, ignore the exception
}
} else {
// invoke the actual security param..
}
} catch (IllegalArgumentException e) {
throw new GeneralFailure(e.getMessage());
} catch (IllegalAccessException e) {
throw new GeneralFailure(e.getMessage());
} catch (InvocationTargetException e) {
if (debug.warningEnabled()) {
}
throw (e.getTargetException());
}
return ret;
}
}
}