/** * Tries to discover the grant type requested for the token associated with this request. * * @return the grant type if known, or null otherwise */ public String getGrantType() { if (getRequestParameters().containsKey(OAuth2Utils.GRANT_TYPE)) { return getRequestParameters().get(OAuth2Utils.GRANT_TYPE); } if (getRequestParameters().containsKey(OAuth2Utils.RESPONSE_TYPE)) { String response = getRequestParameters().get(OAuth2Utils.RESPONSE_TYPE); if (response.contains("token")) { return "implicit"; } } return null; }
boolean isOpaqueTokenRequired(OAuth2Authentication authentication) { Map<String, String> parameters = authentication.getOAuth2Request().getRequestParameters(); return OPAQUE.getStringValue().equals(parameters.get(REQUEST_TOKEN_FORMAT)) || GRANT_TYPE_USER_TOKEN.equals(parameters.get(GRANT_TYPE)); }
/** * Update the scope and create a new request. All the other properties are the same (including the request * parameters). * * @param scope the new scope * @return a new request with the narrowed scope */ public OAuth2Request narrowScope(Set<String> scope) { OAuth2Request request = new OAuth2Request(getRequestParameters(), getClientId(), authorities, approved, scope, resourceIds, redirectUri, responseTypes, extensions); request.refresh = this.refresh; return request; }
public OAuth2Request refresh(TokenRequest tokenRequest) { OAuth2Request request = new OAuth2Request(getRequestParameters(), getClientId(), authorities, approved, getScope(), resourceIds, redirectUri, responseTypes, extensions); request.refresh = tokenRequest; return request; }
String redirectUriApprovalParameter = pendingOAuth2Request.getRequestParameters().get( OAuth2Utils.REDIRECT_URI); .getRequestParameters());
protected byte[] serializeOauth2Authentication(OAuth2Authentication auth2Authentication) { Authentication userAuthentication = auth2Authentication.getUserAuthentication(); HashMap<String, Object> data = new HashMap<>(); if (userAuthentication!=null) { if (userAuthentication instanceof UaaAuthentication) { data.put(USER_AUTHENTICATION_UAA_AUTHENTICATION, JsonUtils.writeValueAsString(userAuthentication)); } else { data.put(USER_AUTHENTICATION_UAA_PRINCIPAL, JsonUtils.writeValueAsString(userAuthentication.getPrincipal())); data.put(USER_AUTHENTICATION_AUTHORITIES, UaaStringUtils.getStringsFromAuthorities(userAuthentication.getAuthorities())); } } data.put(OAUTH2_REQUEST_PARAMETERS, auth2Authentication.getOAuth2Request().getRequestParameters()); data.put(OAUTH2_REQUEST_CLIENT_ID, auth2Authentication.getOAuth2Request().getClientId()); data.put(OAUTH2_REQUEST_AUTHORITIES, UaaStringUtils.getStringsFromAuthorities(auth2Authentication.getOAuth2Request().getAuthorities())); data.put(OAUTH2_REQUEST_APPROVED, auth2Authentication.getOAuth2Request().isApproved()); data.put(OAUTH2_REQUEST_SCOPE, auth2Authentication.getOAuth2Request().getScope()); data.put(OAUTH2_REQUEST_RESOURCE_IDS, auth2Authentication.getOAuth2Request().getResourceIds()); data.put(OAUTH2_REQUEST_REDIRECT_URI, auth2Authentication.getOAuth2Request().getRedirectUri()); data.put(OAUTH2_REQUEST_RESPONSE_TYPES, auth2Authentication.getOAuth2Request().getResponseTypes()); //currently not serializing any of the //Map<String, Serializable > extensionProperties if (auth2Authentication.getOAuth2Request().getExtensions() != null && auth2Authentication.getOAuth2Request().getExtensions().size()>0) { logger.warn("[oauth_code] Unable to serialize extensions:"+auth2Authentication.getOAuth2Request().getExtensions()); } return JsonUtils.writeValueAsBytes(data); }
protected OAuth2Request(OAuth2Request other) { this(other.getRequestParameters(), other.getClientId(), other.getAuthorities(), other.isApproved(), other .getScope(), other.getResourceIds(), other.getRedirectUri(), other.getResponseTypes(), other .getExtensions()); }
public void setAuthentication(OAuth2Authentication authentication) { // pull apart the request and save its bits OAuth2Request o2Request = authentication.getOAuth2Request(); setAuthorities(o2Request.getAuthorities() == null ? null : new HashSet<>(o2Request.getAuthorities())); setClientId(o2Request.getClientId()); setExtensions(o2Request.getExtensions() == null ? null : new HashMap<>(o2Request.getExtensions())); setRedirectUri(o2Request.getRedirectUri()); setRequestParameters(o2Request.getRequestParameters() == null ? null : new HashMap<>(o2Request.getRequestParameters())); setResourceIds(o2Request.getResourceIds() == null ? null : new HashSet<>(o2Request.getResourceIds())); setResponseTypes(o2Request.getResponseTypes() == null ? null : new HashSet<>(o2Request.getResponseTypes())); setScope(o2Request.getScope() == null ? null : new HashSet<>(o2Request.getScope())); setApproved(o2Request.isApproved()); if (authentication.getUserAuthentication() != null) { this.userAuth = new SavedUserAuthentication(authentication.getUserAuthentication()); } else { this.userAuth = null; } }
@Test public void testTokenRetrievalWithAdditionalAuthorizationAttributes() throws Exception { Map additionalAuthorizationAttributesMap = Collections.singletonMap("test", 1); body.put(ClaimConstants.ADDITIONAL_AZ_ATTR, additionalAuthorizationAttributesMap); OAuth2Authentication result = services.loadAuthentication("FOO"); assertNotNull(result); assertEquals(JsonUtils.writeValueAsString(additionalAuthorizationAttributesMap), result.getOAuth2Request() .getRequestParameters().get(ClaimConstants.ADDITIONAL_AZ_ATTR)); } }
@Override public OAuth2Request createOAuth2Request(ClientDetails client) { OAuth2Request request = super.createOAuth2Request(client); return new OAuth2Request( request.getRequestParameters(), client.getClientId(), client.getAuthorities(), true, request.getScope(), resourceIds, request.getRedirectUri(), responseTypes, request.getExtensions()); } }
request.getRequestParameters(), request.getClientId(), UaaStringUtils.getAuthoritiesFromStrings(clientAuthorities),
PKCEAlgorithm alg = PKCEAlgorithm.parse((String) request.getExtensions().get(CODE_CHALLENGE_METHOD)); String verifier = request.getRequestParameters().get(CODE_VERIFIER);
@Test public void testTokenRetrieval() throws Exception { OAuth2Authentication result = services.loadAuthentication("FOO"); assertNotNull(result); assertEquals("remote", result.getOAuth2Request().getClientId()); assertEquals("olds", result.getUserAuthentication().getName()); assertEquals("HDGFJSHGDF", ((RemoteUserAuthentication) result.getUserAuthentication()).getId()); assertNotNull(result.getOAuth2Request().getRequestParameters()); assertNull(result.getOAuth2Request().getRequestParameters().get(ClaimConstants.ISS)); }
@Test public void testTokenRetrievalWithClaims() throws Exception { services.setStoreClaims(true); OAuth2Authentication result = services.loadAuthentication("FOO"); assertNotNull(result); assertEquals("remote", result.getOAuth2Request().getClientId()); assertEquals("olds", result.getUserAuthentication().getName()); assertEquals("HDGFJSHGDF", ((RemoteUserAuthentication) result.getUserAuthentication()).getId()); assertNotNull(result.getOAuth2Request().getRequestParameters()); assertNotNull(result.getOAuth2Request().getRequestParameters().get(ClaimConstants.ISS)); }
oAuth2Request.getScope(), authenticationMethods, oAuth2Request.getRequestParameters().get(REQUEST_AUTHORITIES), oAuth2Request.getResourceIds(), oAuth2Request.getClientId(), Map<String, String> requestParameters = oAuth2Request.getRequestParameters(); String grantType = requestParameters.get(GRANT_TYPE);
OAuth2Request request = factory.createTokenRequest(parameters, client).createOAuth2Request(recipient); assertEquals(recipient.getClientId(), request.getClientId()); assertEquals(recipient.getClientId(), request.getRequestParameters().get(CLIENT_ID)); assertEquals(client.getClientId(), request.getRequestParameters().get(TokenConstants.USER_TOKEN_REQUESTING_CLIENT_ID)); assertEquals(StringUtils.commaDelimitedListToSet("requested.scope"), new TreeSet<>(request.getScope())); assertEquals(StringUtils.commaDelimitedListToSet(recipient.getClientId()+",requested"), new TreeSet<>(request.getResourceIds())); assertEquals("44000", request.getRequestParameters().get("expires_in"));
private LaunchContext getLaunchContext(OAuth2Request authRequest){ String LAUNCH_PARAM = "launch"; Map<String, String> requestParams = authRequest.getRequestParameters(); LaunchContext launchContext = null; String launchIdParam = requestParams.get(LAUNCH_PARAM); if (launchIdParam != null) { launchContext = LaunchContextHolder.getLaunchContext(launchIdParam); } return launchContext; }
/** * Update the scope and create a new request. All the other properties are the same (including the request * parameters). * * @param scope the new scope * @return a new request with the narrowed scope */ public OAuth2Request narrowScope(Set<String> scope) { OAuth2Request request = new OAuth2Request(getRequestParameters(), getClientId(), authorities, approved, scope, resourceIds, redirectUri, responseTypes, extensions); request.refresh = this.refresh; return request; }
public OAuth2Request refresh(TokenRequest tokenRequest) { OAuth2Request request = new OAuth2Request(getRequestParameters(), getClientId(), authorities, approved, getScope(), resourceIds, redirectUri, responseTypes, extensions); request.refresh = tokenRequest; return request; }
protected OAuth2Request(OAuth2Request other) { this(other.getRequestParameters(), other.getClientId(), other.getAuthorities(), other.isApproved(), other .getScope(), other.getResourceIds(), other.getRedirectUri(), other.getResponseTypes(), other .getExtensions()); }