/** * Full constructor. Sets this TokenRequest's requestParameters map to an unmodifiable version of the one provided. * * @param requestParameters * @param clientId * @param scope * @param grantType */ public TokenRequest(Map<String, String> requestParameters, String clientId, Collection<String> scope, String grantType) { setClientId(clientId); setRequestParameters(requestParameters); setScope(scope); this.grantType = grantType; }
@Test public void missing_grant_type() throws Exception { SecurityContextHolder.getContext().setAuthentication(uaaAuthentication); exception.expect(InvalidGrantException.class); exception.expectMessage("Missing grant type"); requestParameters.remove(GRANT_TYPE); tokenRequest.setRequestParameters(requestParameters); granter.validateRequest(tokenRequest); }
@Test public void invalid_grant_type() throws Exception { SecurityContextHolder.getContext().setAuthentication(uaaAuthentication); exception.expect(InvalidGrantException.class); exception.expectMessage("Invalid grant type"); requestParameters.put(GRANT_TYPE, "password"); tokenRequest.setRequestParameters(requestParameters); granter.validateRequest(tokenRequest); }
@Test public void missing_request_parameters() throws Exception { SecurityContextHolder.getContext().setAuthentication(uaaAuthentication); exception.expect(InvalidGrantException.class); exception.expectMessage("Missing token request object"); tokenRequest.setRequestParameters(Collections.emptyMap()); granter.validateRequest(tokenRequest); }
protected void missing_parameter(String parameter) { when(authentication.isAuthenticated()).thenReturn(true); when(authentication.getUserAuthentication()).thenReturn(null); when(authentication.getUserAuthentication()).thenReturn(userAuthentication); when(userAuthentication.isAuthenticated()).thenReturn(true); requestParameters.remove(parameter); tokenRequest = new PublicTokenRequest(); tokenRequest.setClientId(receivingClient.getClientId()); tokenRequest.setRequestParameters(requestParameters); tokenRequest.setGrantType(requestParameters.get(GRANT_TYPE)); granter.validateRequest(tokenRequest); }
protected void missing_parameter(String parameter) { when(authentication.isAuthenticated()).thenReturn(true); when(authentication.getUserAuthentication()).thenReturn(null); when(authentication.getUserAuthentication()).thenReturn(userAuthentication); when(userAuthentication.isAuthenticated()).thenReturn(true); requestParameters.remove(parameter); tokenRequest = new PublicTokenRequest(); tokenRequest.setClientId(receivingClient.getClientId()); tokenRequest.setRequestParameters(requestParameters); tokenRequest.setGrantType(requestParameters.get(GRANT_TYPE)); granter.validateRequest(tokenRequest); }
@Before public void setup() { tokenServices = mock(AuthorizationServerTokenServices.class); clientDetailsService = mock(ClientServicesExtension.class); requestFactory = mock(OAuth2RequestFactory.class); authentication = mock(UaaOauth2Authentication.class); tokenStore = mock(RevocableTokenProvisioning.class); userAuthentication = mock(UaaAuthentication.class); granter = new UserTokenGranter( tokenServices, clientDetailsService, requestFactory, tokenStore ); SecurityContextHolder.getContext().setAuthentication(authentication); requestingClient = new BaseClientDetails("requestingId",null,"uaa.user",GRANT_TYPE_USER_TOKEN, null); receivingClient = new BaseClientDetails("receivingId",null,"test.scope",GRANT_TYPE_REFRESH_TOKEN, null); when(clientDetailsService.loadClientByClientId(eq(requestingClient.getClientId()), anyString())).thenReturn(requestingClient); when(clientDetailsService.loadClientByClientId(eq(receivingClient.getClientId()), anyString())).thenReturn(receivingClient); requestParameters = new HashMap<>(); requestParameters.put(USER_TOKEN_REQUESTING_CLIENT_ID, requestingClient.getClientId()); requestParameters.put(GRANT_TYPE, TokenConstants.GRANT_TYPE_USER_TOKEN); requestParameters.put(CLIENT_ID, receivingClient.getClientId()); tokenRequest = new PublicTokenRequest(); tokenRequest.setRequestParameters(requestParameters); }
requestParameters.put(OAuth2Utils.CLIENT_ID, client.getClientId()); requestParameters.put(GRANT_TYPE, GRANT_TYPE_JWT_BEARER); tokenRequest.setRequestParameters(requestParameters);
requestParameters.put(CLIENT_ID, receivingClient.getClientId()); tokenRequest = new PublicTokenRequest(); tokenRequest.setRequestParameters(requestParameters);
/** * Full constructor. Sets this TokenRequest's requestParameters map to an unmodifiable version of the one provided. * * @param requestParameters * @param clientId * @param scope * @param grantType */ public TokenRequest(Map<String, String> requestParameters, String clientId, Collection<String> scope, String grantType) { setClientId(clientId); setRequestParameters(requestParameters); setScope(scope); this.grantType = grantType; }