001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.security; 029 030import org.opencms.file.CmsObject; 031import org.opencms.main.CmsException; 032 033import java.io.IOException; 034import java.util.Map; 035 036import javax.servlet.http.HttpServletRequest; 037import javax.servlet.http.HttpServletResponse; 038 039/** 040 * Defines general authorization methods.<p> 041 * 042 * One of the application scenarios for this interface is a personalized SSO implementation.<p> 043 * 044 * @since 6.5.4 045 */ 046public interface I_CmsAuthorizationHandler { 047 048 /** 049 * Class providing the privileged login action.<p> 050 */ 051 interface I_PrivilegedLoginAction { 052 053 /** 054 * Used to provide an initial cms object.<p> 055 * 056 * @param cms an initial cms object 057 */ 058 void setCmsObject(CmsObject cms); 059 060 /** 061 * Returns the cms object.<p> 062 * 063 * @return the cms object 064 */ 065 CmsObject getCmsObject(); 066 067 /** 068 * Performs a privileged login action and returns a cms object initialized for the principal.<p> 069 * 070 * @param request the current request 071 * @param principal the principal to login 072 * 073 * @return a cms object initialized for the principal 074 * @throws CmsException if the login action fails 075 */ 076 CmsObject doLogin(HttpServletRequest request, String principal) throws CmsException; 077 } 078 079 /** 080 * Returns the full URL used to call a login form with additional parameters and a callbackURL.<p> 081 * 082 * @param loginFormURL the form URL specified in the cms (either as a property or system-wide) 083 * @param params additional parameters to provide to the login form 084 * @param callbackURL the call-back URL to redirect after a successful login 085 * 086 * @return the full URL used to call a login form 087 */ 088 String getLoginFormURL(String loginFormURL, String params, String callbackURL); 089 090 /** 091 * Creates a new cms object from the given request object.<p> 092 * 093 * This method is called by OpenCms every time a resource is requested 094 * and the session can not automatically be authenticated.<p> 095 * 096 * @param request the HTTP request to authenticate 097 * 098 * @return the cms context object associated to the current session 099 */ 100 CmsObject initCmsObject(HttpServletRequest request); 101 102 /** 103 * Creates a new cms object from the given request object.<p> 104 * 105 * This method is called by OpenCms every time a resource is requested 106 * and the session can not automatically be authenticated.<p> 107 * 108 * @param request the HTTP request to authenticate 109 * @param loginAction the privileged login action 110 * 111 * @return the cms context object associated to the current session 112 */ 113 CmsObject initCmsObject(HttpServletRequest request, I_PrivilegedLoginAction loginAction); 114 115 /** 116 * Authenticates the current request with additional user information.<p> 117 * 118 * You have to call this method by your own.<p> 119 * 120 * @param request the HTTP request to authenticate 121 * @param userName the user name to authenticate 122 * @param pwd the user password to authenticate with 123 * 124 * @return the cms context object associated to the given user 125 * 126 * @throws CmsException if something goes wrong 127 */ 128 CmsObject initCmsObject(HttpServletRequest request, String userName, String pwd) throws CmsException; 129 130 /** 131 * This method sends a request to the client to display a login form, 132 * it is needed for HTTP-Authentication.<p> 133 * 134 * @param req the client request 135 * @param res the response 136 * @param loginFormURL the full URL used for form based authentication 137 * 138 * @throws IOException if something goes wrong 139 */ 140 void requestAuthorization(HttpServletRequest req, HttpServletResponse res, String loginFormURL) throws IOException; 141 142 /** 143 * Sets parameters which can be configured additionally for an authorization handler.<p> 144 * 145 * @param parameters the map of parameters 146 */ 147 void setParameters(Map<String, String> parameters); 148}