Search in sources :

Example 1 with IdentityZoneProvisioning

use of org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning in project uaa by cloudfoundry.

the class TokenMvcMockTests method testDefaultZone_Jwt_Revocable.

@Test
void testDefaultZone_Jwt_Revocable() throws Exception {
    IdentityZoneProvisioning zoneProvisioning = webApplicationContext.getBean(IdentityZoneProvisioning.class);
    IdentityZone defaultZone = zoneProvisioning.retrieve(IdentityZone.getUaaZoneId());
    try {
        defaultZone.getConfig().getTokenPolicy().setJwtRevocable(true);
        zoneProvisioning.update(defaultZone);
        Map<String, String> parameters = new HashedMap();
        Map<String, Object> tokenResponse = testRevocablePasswordGrantTokenForDefaultZone(parameters);
        validateRevocableJwtToken(tokenResponse, defaultZone);
    } finally {
        defaultZone.getConfig().getTokenPolicy().setJwtRevocable(false);
        zoneProvisioning.update(defaultZone);
    }
}
Also used : IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) IdentityZoneProvisioning(org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning) Matchers.containsString(org.hamcrest.Matchers.containsString) HashedMap(org.apache.commons.collections.map.HashedMap) Test(org.junit.jupiter.api.Test)

Example 2 with IdentityZoneProvisioning

use of org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning in project uaa by cloudfoundry.

the class TokenMvcMockTests method testNonDefaultZone_Jwt_Revocable.

@Test
void testNonDefaultZone_Jwt_Revocable() throws Exception {
    String username = generator.generate() + "@test.org";
    String subdomain = "testzone" + generator.generate();
    String clientId = "testclient" + generator.generate();
    createNonDefaultZone(username, subdomain, clientId);
    IdentityZoneProvisioning zoneProvisioning = webApplicationContext.getBean(IdentityZoneProvisioning.class);
    IdentityZone defaultZone = zoneProvisioning.retrieveBySubdomain(subdomain);
    try {
        defaultZone.getConfig().getTokenPolicy().setJwtRevocable(true);
        zoneProvisioning.update(defaultZone);
        MockHttpServletRequestBuilder post = post("/oauth/token").with(httpBasic(clientId, SECRET)).header("Host", subdomain + ".localhost").param("username", username).param("password", "secret").param(OAuth2Utils.GRANT_TYPE, "password").param(OAuth2Utils.CLIENT_ID, clientId);
        Map<String, Object> tokenResponse = JsonUtils.readValue(mockMvc.perform(post).andDo(print()).andExpect(status().isOk()).andReturn().getResponse().getContentAsString(), new TypeReference<Map<String, Object>>() {
        });
        validateRevocableJwtToken(tokenResponse, defaultZone);
    } finally {
        defaultZone.getConfig().getTokenPolicy().setJwtRevocable(false);
        zoneProvisioning.update(defaultZone);
    }
}
Also used : IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) IdentityZoneProvisioning(org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) LinkedHashMap(java.util.LinkedHashMap) MultiValueMap(org.springframework.util.MultiValueMap) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 3 with IdentityZoneProvisioning

use of org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning in project uaa by cloudfoundry.

the class MockMvcUtils method getZoneConfiguration.

public static IdentityZoneConfiguration getZoneConfiguration(ApplicationContext context, String zoneId) {
    IdentityZoneProvisioning provisioning = context.getBean(IdentityZoneProvisioning.class);
    IdentityZone uaaZone = provisioning.retrieve(zoneId);
    return uaaZone.getConfig();
}
Also used : IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) IdentityZoneProvisioning(org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning)

Example 4 with IdentityZoneProvisioning

use of org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning in project uaa by cloudfoundry.

the class MockMvcUtils method setZoneConfiguration.

public static void setZoneConfiguration(ApplicationContext context, String zoneId, IdentityZoneConfiguration configuration) {
    IdentityZoneProvisioning provisioning = context.getBean(IdentityZoneProvisioning.class);
    IdentityZone uaaZone = provisioning.retrieve(zoneId);
    uaaZone.setConfig(configuration);
    provisioning.update(uaaZone);
}
Also used : IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) IdentityZoneProvisioning(org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning)

Example 5 with IdentityZoneProvisioning

use of org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning in project uaa by cloudfoundry.

the class KeyInfoServiceTests method configureDefaultZoneKeys.

private void configureDefaultZoneKeys(Map<String, String> keys) {
    IdentityZoneHolder.clear();
    IdentityZoneProvisioning provisioning = mock(IdentityZoneProvisioning.class);
    IdentityZoneHolder.setProvisioning(provisioning);
    IdentityZone zone = IdentityZone.getUaa();
    IdentityZoneConfiguration config = new IdentityZoneConfiguration();
    TokenPolicy tokenPolicy = new TokenPolicy();
    tokenPolicy.setKeys(keys);
    config.setTokenPolicy(tokenPolicy);
    zone.setConfig(config);
    when(provisioning.retrieve("uaa")).thenReturn(zone);
}
Also used : IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) IdentityZoneProvisioning(org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning) TokenPolicy(org.cloudfoundry.identity.uaa.zone.TokenPolicy) IdentityZoneConfiguration(org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration)

Aggregations

IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)10 IdentityZoneProvisioning (org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning)10 IdentityZoneConfiguration (org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration)5 TokenPolicy (org.cloudfoundry.identity.uaa.zone.TokenPolicy)5 Test (org.junit.jupiter.api.Test)3 HashedMap (org.apache.commons.collections.map.HashedMap)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 KeyInfo (org.cloudfoundry.identity.uaa.oauth.KeyInfo)1 MultitenantJdbcClientDetailsService (org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService)1 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)1 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1 MultiValueMap (org.springframework.util.MultiValueMap)1