Class OIDCCMServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- edu.uiuc.ncsa.security.servlet.AbstractServlet
-
- org.oa4mp.server.api.storage.servlet.EnvServlet
-
- org.oa4mp.server.loader.oauth2.cm.oidc_cm.OIDCCMServlet
-
- All Implemented Interfaces:
edu.uiuc.ncsa.security.core.Logable
,Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
public class OIDCCMServlet extends EnvServlet
Note that in all of these calls, the assumption is that an admin client has been requested and approved out of band. The identifier and secret of that are used to make the bearer token that allows access to the calls in this API. This implements both RFC 7591 and part of RFC 7592. Mostly we do not allow the setting of client secrets via tha API and since we do not store them (only a hash of them) we cannot return them. If a secret is lost, the only option is to register a new client.
Nota Bene: RFC 7592 is not intended to become a specification since there is too much variance in how this can operate.Created by Jeff Gaynor
on 11/28/18 at 10:04 AM- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
API_VERSION_5_4
static String
API_VERSION_5_5
static String
API_VERSION_KEY
static String
API_VERSION_LATEST
static String
API_VERSION_NONE
They sent nothing explicit.static String
APPROVAL_STATUS
static String
ERSATZ_CLIENT_PROVISIONERS
static String
FORWARD_REQUEST_SCOPES_TO_PROXY
static String
IS_SERVICE_CLIENT
static String
PROXY_CLAIMS_LIST
static String
PROXY_REQUEST_SCOPES
static String
QUERY_PARAMETER
protected SecureRandom
secureRandom
static String
SERVICE_CLIENT_USERS
-
Fields inherited from class org.oa4mp.server.api.storage.servlet.EnvServlet
ERROR_NOTIFICATION_BODY_KEY, ERROR_NOTIFICATION_SUBJECT_KEY, notificationListeners, storeUpdatesDone
-
-
Constructor Summary
Constructors Constructor Description OIDCCMServlet()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
areAllGrantsSupported(net.sf.json.JSONArray proposedGrants, String[] supportedGrants)
protected void
checkAdminPermission(AdminClient adminClient, OA2Client client)
Checks that this client exists on the system and that if it exists, the admin client actually owns it.protected boolean
checkJAEntry(net.sf.json.JSONArray jsonArray, String entry)
JSONArray does not check its contains sanely against strings at times.protected HashMap<String,String>
defaultReplacements(javax.servlet.http.HttpServletRequest req, AdminClient adminClient, OA2Client client)
protected void
doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
Remove the given client in toto.void
doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
Return information about the client.protected void
doIt(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
protected void
doIt2(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
The workhorse method for POST.void
doPost(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
protected void
doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
Update a client.protected void
fireMessage(boolean isAnonymous, OA2SE oa2SE, HashMap<String,String> replacements)
protected String
formatIdentifiable(edu.uiuc.ncsa.security.core.Store store, edu.uiuc.ncsa.security.core.Identifiable identifiable)
protected AdminClient
getAndCheckAdminClient(javax.servlet.http.HttpServletRequest request)
Pulls the id and secret from the header then verifies the secret and if it passes, returns the client.protected OA2Client
getAndCheckOA2Client(javax.servlet.http.HttpServletRequest request)
protected OA2Client
getClient(javax.servlet.http.HttpServletRequest req)
Get the client from the request.static String
getDefaultAPIVersion()
edu.uiuc.ncsa.security.util.jwk.JWKUtil2
getJwkUtil()
protected OA2SE
getOA2SE()
protected net.sf.json.JSON
getPayload(javax.servlet.http.HttpServletRequest httpServletRequest, edu.uiuc.ncsa.security.core.util.MetaDebugUtil adminDebugger)
PermissionServer
getPermissionServer()
We want to be able to manage the permissions associated with a standard client and an admin client.protected String
getVersion(CMConfig cmConfig, javax.servlet.http.HttpServletRequest req)
protected void
handleGrants(OA2Client client, net.sf.json.JSONObject jsonRequest, OA2ClientKeys keys)
protected void
handleResponseTypes(OA2Client client, net.sf.json.JSONObject jsonRequest, OA2ClientKeys keys)
TL;DR: we support the grant types for the authorization_code flow so only code and id_token.protected long
lifetimeFromParameter(Object raw)
So clients can send strings of values with units, e.g.protected long
lifetimeFromSec(long lifetime)
protected long
lifetimeToSec(long lifetime)
Used in serializing the client to JSON.protected OA2Client
processRegistrationRequest(net.sf.json.JSONObject jsonRequest, AdminClient adminClient, boolean isAnonymous, OA2Client client, String version)
static void
setDefaultAPIVersion(String defaultAPIVersion)
void
setJwkUtil(edu.uiuc.ncsa.security.util.jwk.JWKUtil2 jwkUtil)
void
storeUpdates()
This will be invoked at init before anything else and should include code to seamlessly upgrade stores from earlier versions.protected net.sf.json.JSONArray
toJA(net.sf.json.JSONObject obj, String key)
Some attribute scan come over the wire as either arrays of string or as blank delimited strings, e.g.protected net.sf.json.JSONArray
toJSONArray(net.sf.json.JSONObject jsonRequest, String key, OA2Client client)
protected net.sf.json.JSONObject
toJSONObject(OA2Client client, String version, boolean isGet)
Take a client and turn it in to a response object.protected net.sf.json.JSONObject
toJSONObject5_4(OA2Client client, boolean isGet)
protected net.sf.json.JSONObject
toJSONObject5_5(OA2Client client, boolean isGet)
protected OA2Client
updateClient(OA2Client client, AdminClient adminClient, boolean isAnonymous, net.sf.json.JSONObject jsonRequest, boolean newClient, String version)
-
Methods inherited from class org.oa4mp.server.api.storage.servlet.EnvServlet
addNotificationListener, loadEnvironment, loadProperties2, processStoreCheck, removeNotificationListener
-
Methods inherited from class edu.uiuc.ncsa.security.servlet.AbstractServlet
checkContentType, CONST, debug, doPing, error, error, getConfigurationLoader, getEnvironment, getExceptionHandler, getInitialization, getMyLogger, getRequestIPAddress, handleException, info, init, isDebugOn, logOK, logOK, printAllParameters, printAllParameters, resetState, setConfigurationLoader, setDebugOn, setEnvironment, setExceptionHandler, setInitialization, warn
-
Methods inherited from class javax.servlet.http.HttpServlet
doHead, doOptions, doTrace, getLastModified, service, service
-
-
-
-
Field Detail
-
PROXY_CLAIMS_LIST
public static final String PROXY_CLAIMS_LIST
- See Also:
- Constant Field Values
-
FORWARD_REQUEST_SCOPES_TO_PROXY
public static final String FORWARD_REQUEST_SCOPES_TO_PROXY
- See Also:
- Constant Field Values
-
PROXY_REQUEST_SCOPES
public static final String PROXY_REQUEST_SCOPES
- See Also:
- Constant Field Values
-
IS_SERVICE_CLIENT
public static final String IS_SERVICE_CLIENT
- See Also:
- Constant Field Values
-
SERVICE_CLIENT_USERS
public static final String SERVICE_CLIENT_USERS
- See Also:
- Constant Field Values
-
ERSATZ_CLIENT_PROVISIONERS
public static final String ERSATZ_CLIENT_PROVISIONERS
- See Also:
- Constant Field Values
-
APPROVAL_STATUS
public static final String APPROVAL_STATUS
- See Also:
- Constant Field Values
-
API_VERSION_LATEST
public static final String API_VERSION_LATEST
- See Also:
- Constant Field Values
-
API_VERSION_NONE
public static final String API_VERSION_NONE
They sent nothing explicit.- See Also:
- Constant Field Values
-
API_VERSION_5_4
public static final String API_VERSION_5_4
- See Also:
- Constant Field Values
-
API_VERSION_5_5
public static final String API_VERSION_5_5
- See Also:
- Constant Field Values
-
API_VERSION_KEY
public static final String API_VERSION_KEY
- See Also:
- Constant Field Values
-
QUERY_PARAMETER
public static final String QUERY_PARAMETER
- See Also:
- Constant Field Values
-
secureRandom
protected SecureRandom secureRandom
-
-
Method Detail
-
storeUpdates
public void storeUpdates() throws IOException, SQLException
Description copied from class:EnvServlet
This will be invoked at init before anything else and should include code to seamlessly upgrade stores from earlier versions. For instance, if a new column needs to be added to a table. This pre-supposes that the current user has the correct permissions to alter the table, btw. This also updates the internal flagEnvServlet.storeUpdatesDone
which should be checks in overrides. If you override this method and call super, let super manage this flag. If it is true, do not execute your method.- Specified by:
storeUpdates
in classEnvServlet
- Throws:
IOException
SQLException
-
getOA2SE
protected OA2SE getOA2SE()
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws javax.servlet.ServletException, IOException
Return information about the client. Note that we do not return the client secret in this call, since among other reasons, we do not have it.- Overrides:
doGet
in classedu.uiuc.ncsa.security.servlet.AbstractServlet
- Parameters:
httpServletRequest
-httpServletResponse
-- Throws:
javax.servlet.ServletException
IOException
-
formatIdentifiable
protected String formatIdentifiable(edu.uiuc.ncsa.security.core.Store store, edu.uiuc.ncsa.security.core.Identifiable identifiable)
-
defaultReplacements
protected HashMap<String,String> defaultReplacements(javax.servlet.http.HttpServletRequest req, AdminClient adminClient, OA2Client client)
-
toJSONObject
protected net.sf.json.JSONObject toJSONObject(OA2Client client, String version, boolean isGet)
Take a client and turn it in to a response object. This is used by both GET do PUT (which is supposed to return the same output as GET when done with its updates)- Parameters:
client
-- Returns:
-
toJSONObject5_5
protected net.sf.json.JSONObject toJSONObject5_5(OA2Client client, boolean isGet)
-
toJSONObject5_4
protected net.sf.json.JSONObject toJSONObject5_4(OA2Client client, boolean isGet)
-
getDefaultAPIVersion
public static String getDefaultAPIVersion()
-
setDefaultAPIVersion
public static void setDefaultAPIVersion(String defaultAPIVersion)
-
lifetimeToSec
protected long lifetimeToSec(long lifetime)
Used in serializing the client to JSON. lifetime that are positive are divided by 1000 to convert from milliseconds to seconds.
If they are non-positive, however, they are returned as is since negative values are overloaded.- Parameters:
lifetime
-- Returns:
-
lifetimeFromSec
protected long lifetimeFromSec(long lifetime)
-
doDelete
protected void doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
Remove the given client in toto.- Overrides:
doDelete
in classjavax.servlet.http.HttpServlet
- Parameters:
req
-resp
-- Throws:
javax.servlet.ServletException
IOException
-
checkAdminPermission
protected void checkAdminPermission(AdminClient adminClient, OA2Client client)
Checks that this client exists on the system and that if it exists, the admin client actually owns it.- Parameters:
adminClient
-client
-
-
getVersion
protected String getVersion(CMConfig cmConfig, javax.servlet.http.HttpServletRequest req)
-
doPut
protected void doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
Update a client. Note that as per the specification, all values that are sent over-write existing values and omitted values are taken to mean the stored value is unset.- Overrides:
doPut
in classjavax.servlet.http.HttpServlet
- Parameters:
req
-resp
-- Throws:
javax.servlet.ServletException
IOException
-
doPost
public void doPost(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws javax.servlet.ServletException, IOException
- Overrides:
doPost
in classedu.uiuc.ncsa.security.servlet.AbstractServlet
- Throws:
javax.servlet.ServletException
IOException
-
getPermissionServer
public PermissionServer getPermissionServer()
We want to be able to manage the permissions associated with a standard client and an admin client.- Returns:
-
getAndCheckAdminClient
protected AdminClient getAndCheckAdminClient(javax.servlet.http.HttpServletRequest request) throws Throwable
Pulls the id and secret from the header then verifies the secret and if it passes, returns the client.- Parameters:
request
-- Returns:
- Throws:
Throwable
-
getAndCheckOA2Client
protected OA2Client getAndCheckOA2Client(javax.servlet.http.HttpServletRequest request) throws Throwable
- Throws:
Throwable
-
doIt
protected void doIt(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws Throwable
- Specified by:
doIt
in classedu.uiuc.ncsa.security.servlet.AbstractServlet
- Throws:
Throwable
-
doIt2
protected void doIt2(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws Throwable
The workhorse method for POST.- Parameters:
httpServletRequest
-httpServletResponse
-- Throws:
Throwable
-
getPayload
protected net.sf.json.JSON getPayload(javax.servlet.http.HttpServletRequest httpServletRequest, edu.uiuc.ncsa.security.core.util.MetaDebugUtil adminDebugger) throws IOException
- Throws:
IOException
-
getClient
protected OA2Client getClient(javax.servlet.http.HttpServletRequest req)
Get the client from the request. Note that this may return null if no such client exists and it is up to the calling method to decide if this is ok.- Parameters:
req
-- Returns:
-
updateClient
protected OA2Client updateClient(OA2Client client, AdminClient adminClient, boolean isAnonymous, net.sf.json.JSONObject jsonRequest, boolean newClient, String version)
-
lifetimeFromParameter
protected long lifetimeFromParameter(Object raw)
So clients can send strings of values with units, e.g. "1 month". OA4MP supports this for its own values.- Parameters:
raw
-- Returns:
-
toJSONArray
protected net.sf.json.JSONArray toJSONArray(net.sf.json.JSONObject jsonRequest, String key, OA2Client client)
-
handleResponseTypes
protected void handleResponseTypes(OA2Client client, net.sf.json.JSONObject jsonRequest, OA2ClientKeys keys)
TL;DR: we support the grant types for the authorization_code flow so only code and id_token. We explicitly reject every other response_type at this point, in particular, we reject the value of "token" which is only for the implicit flow.- Parameters:
client
-jsonRequest
-keys
-
-
checkJAEntry
protected boolean checkJAEntry(net.sf.json.JSONArray jsonArray, String entry)
JSONArray does not check its contains sanely against strings at times.- Parameters:
jsonArray
-entry
-- Returns:
-
areAllGrantsSupported
protected boolean areAllGrantsSupported(net.sf.json.JSONArray proposedGrants, String[] supportedGrants)
-
handleGrants
protected void handleGrants(OA2Client client, net.sf.json.JSONObject jsonRequest, OA2ClientKeys keys)
-
toJA
protected net.sf.json.JSONArray toJA(net.sf.json.JSONObject obj, String key)
Some attribute scan come over the wire as either arrays of string or as blank delimited strings, e.g. scopes and grant types. Just figure it out and hand back the array. Note this will remove duplicates.- Parameters:
obj
-key
-- Returns:
-
processRegistrationRequest
protected OA2Client processRegistrationRequest(net.sf.json.JSONObject jsonRequest, AdminClient adminClient, boolean isAnonymous, OA2Client client, String version)
-
fireMessage
protected void fireMessage(boolean isAnonymous, OA2SE oa2SE, HashMap<String,String> replacements)
-
getJwkUtil
public edu.uiuc.ncsa.security.util.jwk.JWKUtil2 getJwkUtil()
-
setJwkUtil
public void setJwkUtil(edu.uiuc.ncsa.security.util.jwk.JWKUtil2 jwkUtil)
-
-