001 /*
002 * JBoss, Home of Professional Open Source.
003 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
004 * as indicated by the @author tags. See the copyright.txt file in the
005 * distribution for a full listing of individual contributors.
006 *
007 * This is free software; you can redistribute it and/or modify it
008 * under the terms of the GNU Lesser General Public License as
009 * published by the Free Software Foundation; either version 2.1 of
010 * the License, or (at your option) any later version.
011 *
012 * This software 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 * You should have received a copy of the GNU Lesser General Public
018 * License along with this software; if not, write to the Free
019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021 */
022 package org.jboss.dna.graph;
023
024 import java.security.AccessControlContext;
025 import java.security.AccessController;
026 import javax.security.auth.Subject;
027 import javax.security.auth.callback.CallbackHandler;
028 import javax.security.auth.login.LoginContext;
029 import javax.security.auth.login.LoginException;
030 import javax.security.auth.spi.LoginModule;
031
032 /**
033 * A factory for creating {@link ExecutionContext} instances. Each execution context is affiliated with a JAAS {@link Subject},
034 * and thus the factory methods take the same parameters that the JAAS {@link LoginContext} take.
035 *
036 * @author Randall Hauch
037 * @author John Verhaeg
038 */
039 public interface ExecutionContextFactory {
040
041 /**
042 * Creates an {@link ExecutionContext} using a snapshot of the {@link AccessControlContext access control context} obtained
043 * from the current calling context.
044 *
045 * @return the execution context; never <code>null</code>.
046 * @see AccessController#getContext()
047 */
048 ExecutionContext create();
049
050 /**
051 * Creates an {@link ExecutionContext} using the supplied {@link AccessControlContext access control context}.
052 *
053 * @param accessControlContext An access control context.
054 * @return the execution context; never <code>null</code>.
055 * @throws IllegalArgumentException if <code>accessControlContext</code> is <code>null</code>.
056 */
057 ExecutionContext create( AccessControlContext accessControlContext );
058
059 /**
060 * Create an {@link ExecutionContext} for the supplied {@link LoginContext}.
061 *
062 * @param loginContext the JAAS login context
063 * @return the execution context
064 * @throws IllegalArgumentException if the <code>loginContext</code> is null
065 */
066 ExecutionContext create( LoginContext loginContext );
067
068 /**
069 * @param name the name of the JAAS login context
070 * @return the execution context
071 * @throws IllegalArgumentException if the <code>name</code> is null
072 * @throws LoginException if there <code>name</code> is invalid (or there is no login context named "other"), or if the
073 * default callback handler JAAS property was not set or could not be loaded
074 */
075 ExecutionContext create( String name ) throws LoginException;
076
077 /**
078 * @param name the name of the JAAS login context
079 * @param subject the subject to authenticate
080 * @return the execution context
081 * @throws LoginException if there <code>name</code> is invalid (or there is no login context named "other"), if the default
082 * callback handler JAAS property was not set or could not be loaded, or if the <code>subject</code> is null or
083 * unknown
084 */
085 ExecutionContext create( String name,
086 Subject subject ) throws LoginException;
087
088 /**
089 * @param name the name of the JAAS login context
090 * @param callbackHandler the callback handler that will be used by {@link LoginModule}s to communicate with the user.
091 * @return the execution context
092 * @throws LoginException if there <code>name</code> is invalid (or there is no login context named "other"), or if the
093 * <code>callbackHandler</code> is null
094 */
095 ExecutionContext create( String name,
096 CallbackHandler callbackHandler ) throws LoginException;
097
098 /**
099 * @param name the name of the JAAS login context
100 * @param subject the subject to authenticate
101 * @param callbackHandler the callback handler that will be used by {@link LoginModule}s to communicate with the user.
102 * @return the execution context
103 * @throws LoginException if there <code>name</code> is invalid (or there is no login context named "other"), if the default
104 * callback handler JAAS property was not set or could not be loaded, if the <code>subject</code> is null or unknown,
105 * or if the <code>callbackHandler</code> is null
106 */
107 ExecutionContext create( String name,
108 Subject subject,
109 CallbackHandler callbackHandler ) throws LoginException;
110
111 }