use of org.maxkey.authz.oauth2.provider.AuthorizationRequest in project uaa by cloudfoundry.
the class UaaTokenServicesTests method ensureJKUHeaderIsSetWhenBuildingAnAccessToken.
@Test
void ensureJKUHeaderIsSetWhenBuildingAnAccessToken() {
AuthorizationRequest authorizationRequest = constructAuthorizationRequest(clientId, GRANT_TYPE_CLIENT_CREDENTIALS, Strings.split(clientScopes, ','));
OAuth2Authentication authentication = new OAuth2Authentication(authorizationRequest.createOAuth2Request(), null);
OAuth2AccessToken accessToken = tokenServices.createAccessToken(authentication);
Jwt decode = JwtHelper.decode(accessToken.getValue());
assertThat(decode.getHeader().getJku(), is("https://uaa.some.test.domain.com:555/uaa/token_keys"));
}
use of org.maxkey.authz.oauth2.provider.AuthorizationRequest in project uaa by cloudfoundry.
the class UaaTokenServicesTests method constructAuthorizationRequest.
private AuthorizationRequest constructAuthorizationRequest(String clientId, String grantType, String... scopes) {
AuthorizationRequest authorizationRequest = new AuthorizationRequest(clientId, Arrays.asList(scopes));
Map<String, String> azParameters = new HashMap<>(authorizationRequest.getRequestParameters());
azParameters.put(GRANT_TYPE, grantType);
authorizationRequest.setRequestParameters(azParameters);
return authorizationRequest;
}
use of org.maxkey.authz.oauth2.provider.AuthorizationRequest in project uaa by cloudfoundry.
the class MultitenantJdbcClientDetailsServiceTests method authenticateAsUserAndReturnOldAuth.
private static Authentication authenticateAsUserAndReturnOldAuth(String userId) {
Authentication authentication = new OAuth2Authentication(new AuthorizationRequest("client", Collections.singletonList("read")).createOAuth2Request(), UaaAuthenticationTestFactory.getAuthentication(userId, "joe", "joe@test.org"));
Authentication currentAuth = SecurityContextHolder.getContext().getAuthentication();
SecurityContextHolder.getContext().setAuthentication(authentication);
return currentAuth;
}
use of org.maxkey.authz.oauth2.provider.AuthorizationRequest in project uaa by cloudfoundry.
the class UaaAuthorizationEndpointTest method testBuildRedirectURI_doesNotIncludeSessionStateWhenNotPromptNone.
@Test
public void testBuildRedirectURI_doesNotIncludeSessionStateWhenNotPromptNone() {
AuthorizationRequest authorizationRequest = new AuthorizationRequest();
authorizationRequest.setRedirectUri("http://example.com/somepath");
authorizationRequest.setResponseTypes(new HashSet<String>() {
{
add("code");
add("token");
add("id_token");
}
});
authorizationRequest.setState("California");
CompositeToken accessToken = new CompositeToken("TOKEN_VALUE+=");
accessToken.setIdTokenValue("idTokenValue");
UaaPrincipal principal = new UaaPrincipal("userid", "username", "email", "origin", "extid", "zoneid");
UaaAuthenticationDetails details = new UaaAuthenticationDetails(true, "clientid", "origin", "SOMESESSIONID");
Authentication authUser = new UaaAuthentication(principal, Collections.emptyList(), details);
accessToken.setExpiration(Calendar.getInstance().getTime());
OAuth2Request storedOAuth2Request = mock(OAuth2Request.class);
when(oAuth2RequestFactory.createOAuth2Request(any())).thenReturn(storedOAuth2Request);
when(authorizationCodeServices.createAuthorizationCode(any())).thenReturn("ABCD");
String result = uaaAuthorizationEndpoint.buildRedirectURI(authorizationRequest, accessToken, authUser);
assertThat(result, containsString("http://example.com/somepath#"));
assertThat(result, containsString("token_type=bearer"));
assertThat(result, containsString("access_token=TOKEN_VALUE+%3D"));
assertThat(result, containsString("id_token=idTokenValue"));
assertThat(result, containsString("code=ABCD"));
assertThat(result, containsString("state=California"));
assertThat(result, containsString("expires_in="));
assertThat(result, containsString("scope=null"));
}
use of org.maxkey.authz.oauth2.provider.AuthorizationRequest in project uaa by cloudfoundry.
the class UaaAuthorizationEndpointTest method testApproveWithModifiedClientId.
@Test(expected = InvalidRequestException.class)
public void testApproveWithModifiedClientId() {
AuthorizationRequest authorizationRequest = getAuthorizationRequest("foo", "http://anywhere.com", "state-1234", "read", Collections.singleton("code"));
model.put(UaaAuthorizationEndpoint.AUTHORIZATION_REQUEST, authorizationRequest);
model.put(UaaAuthorizationEndpoint.ORIGINAL_AUTHORIZATION_REQUEST, uaaAuthorizationEndpoint.unmodifiableMap(authorizationRequest));
// Modify authorization request
authorizationRequest.setClientId("bar");
Map<String, String> approvalParameters = new HashMap<>();
approvalParameters.put("user_oauth_approval", "true");
uaaAuthorizationEndpoint.approveOrDeny(approvalParameters, model, sessionStatus, principal);
}
Aggregations