001 /* 002 * Copyright 2008-2009 the original author or authors. 003 * The contents of this file are subject to the Mozilla Public License 004 * Version 1.1 (the "License"); you may not use this file except in 005 * compliance with the License. You may obtain a copy of the License at 006 * http://www.mozilla.org/MPL/ 007 * 008 * Software distributed under the License is distributed on an "AS IS" 009 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 010 * License for the specific language governing rights and limitations 011 * under the License. 012 */ 013 014 package com.mtgi.analytics; 015 016 import java.security.AccessController; 017 import java.security.Principal; 018 import java.util.Set; 019 020 import javax.security.auth.Subject; 021 022 public class JAASSessionContext implements SessionContext { 023 024 public String getContextSessionId() { 025 //TODO: ? 026 return null; 027 } 028 029 public String getContextUserId() { 030 Subject subj = Subject.getSubject(AccessController.getContext()); 031 if (subj == null) 032 return null; 033 Set<Principal> princ = subj.getPrincipals(); 034 if (princ == null || princ.isEmpty()) 035 return null; 036 return princ.iterator().next().getName(); 037 } 038 039 }