Class OAuthContextUtils
- java.lang.Object
-
- org.apache.cxf.rs.security.oauth2.utils.OAuthContextUtils
-
public final class OAuthContextUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertClient(org.apache.cxf.jaxrs.ext.MessageContext mc, String client)static voidassertRole(org.apache.cxf.jaxrs.ext.MessageContext mc, String role)static OAuthContextgetContext(org.apache.cxf.jaxrs.ext.MessageContext mc)static booleanisUserInRole(org.apache.cxf.jaxrs.ext.MessageContext mc, String role)static StringresolveClient(org.apache.cxf.jaxrs.ext.MessageContext mc)static List<OAuthPermission>resolvePermissions(org.apache.cxf.jaxrs.ext.MessageContext mc)static StringresolveTokenKey(org.apache.cxf.jaxrs.ext.MessageContext mc)static StringresolveUserId(org.apache.cxf.jaxrs.ext.MessageContext mc)static StringresolveUserName(org.apache.cxf.jaxrs.ext.MessageContext mc)static List<String>resolveUserRoles(org.apache.cxf.jaxrs.ext.MessageContext mc)
-
-
-
Method Detail
-
resolveUserId
public static String resolveUserId(org.apache.cxf.jaxrs.ext.MessageContext mc)
- Parameters:
mc- theMessageContext- Returns:
- the id of the UserSubject of the logged in user or resource owner
- Throws:
WebApplicationException- with Status 401 if not authenticated
-
resolveUserName
public static String resolveUserName(org.apache.cxf.jaxrs.ext.MessageContext mc)
- Parameters:
mc- theMessageContext- Returns:
- the name of the UserSubject of the logged in user or resource owner
- Throws:
WebApplicationException- with Status 401 if not authenticated
-
resolveUserRoles
public static List<String> resolveUserRoles(org.apache.cxf.jaxrs.ext.MessageContext mc)
- Parameters:
mc- theMessageContext- Returns:
- the list of roles of the logged in user or resource owner
- Throws:
WebApplicationException- with Status 401 if not authenticated
-
isUserInRole
public static boolean isUserInRole(org.apache.cxf.jaxrs.ext.MessageContext mc, String role)- Parameters:
mc- theMessageContextrole- the user role to check- Returns:
- true if user has given role; false otherwise
- Throws:
WebApplicationException- with Status 401 if not authenticated
-
assertRole
public static void assertRole(org.apache.cxf.jaxrs.ext.MessageContext mc, String role)- Parameters:
mc- theMessageContextrole- the role to check- Throws:
WebApplicationException- with Status 401 if not authenticatedWebApplicationException- with Status 403 if user doesn't have needed role
-
resolvePermissions
public static List<OAuthPermission> resolvePermissions(org.apache.cxf.jaxrs.ext.MessageContext mc)
- Parameters:
mc- theMessageContext- Returns:
- the list of permissions of the used access token
- Throws:
WebApplicationException- with Status 401 if not authenticated
-
resolveTokenKey
public static String resolveTokenKey(org.apache.cxf.jaxrs.ext.MessageContext mc)
- Parameters:
mc- theMessageContext- Returns:
- the token key used to access
- Throws:
WebApplicationException- with Status 401 if not authenticated
-
resolveClient
public static String resolveClient(org.apache.cxf.jaxrs.ext.MessageContext mc)
- Parameters:
mc- theMessageContext- Returns:
- the client registration id
- Throws:
WebApplicationException- with Status 401 if not authenticated
-
assertClient
public static void assertClient(org.apache.cxf.jaxrs.ext.MessageContext mc, String client)- Parameters:
mc- theMessageContextclient- the desired client registration id- Throws:
WebApplicationException- with Status 403 if the current client id is not valid
-
getContext
public static OAuthContext getContext(org.apache.cxf.jaxrs.ext.MessageContext mc)
- Parameters:
mc- theMessageContext- Returns:
- the
OAuthContextof the givenMessageContext - Throws:
WebApplicationException- with Status 401 if not authenticated
-
-