001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.opencmis.bindings; 020 021import java.io.Serializable; 022import java.security.Principal; 023import java.util.HashMap; 024import java.util.Map; 025 026import javax.servlet.http.HttpServletRequest; 027 028import org.apache.chemistry.opencmis.commons.server.CallContext; 029import org.apache.chemistry.opencmis.server.shared.CallContextHandler; 030 031/** 032 * Call Context Handler for Nuxeo authentication that extracts the relevant user name. 033 * <p> 034 * Configured as a "callContextHandler" servlet parameter in the AtomPub and JSON servlets. 035 * <p> 036 * Authentication happened earlier in the chain through Nuxeo's authentication filter, and a JAAS context has already 037 * been set up. For SOAP, authentication happened through {@link NuxeoCmisAuthHandler} instead of the standard Nuxeo 038 * filter. 039 * <p> 040 * There is no password available, as authentication is opaque and may use SSO. 041 */ 042public class NuxeoAuthCallContextHandler implements CallContextHandler, Serializable { 043 044 private static final long serialVersionUID = 1L; 045 046 @Override 047 public Map<String, String> getCallContextMap(HttpServletRequest request) { 048 Principal principal = request.getUserPrincipal(); 049 Map<String, String> result = new HashMap<String, String>(); 050 if (principal != null) { 051 result.put(CallContext.USERNAME, principal.getName()); 052 } 053 return result; 054 } 055 056}