Search in sources :

Example 1 with IdentityZoneManager

use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager in project uaa by cloudfoundry.

the class UaaClientAuthenticationProviderTest method setUpForClientTests.

@BeforeEach
void setUpForClientTests() {
    IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
    when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(IdentityZone.getUaaZoneId());
    jdbcClientDetailsService = new MultitenantJdbcClientDetailsService(jdbcTemplate, mockIdentityZoneManager, passwordEncoder);
    ClientDetailsUserDetailsService clientDetailsService = new ClientDetailsUserDetailsService(jdbcClientDetailsService);
    client = createClient();
    authenticationProvider = new ClientDetailsAuthenticationProvider(clientDetailsService, passwordEncoder);
}
Also used : MultitenantJdbcClientDetailsService(org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService) ClientDetailsUserDetailsService(org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with IdentityZoneManager

use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager in project uaa by cloudfoundry.

the class PasswordResetEndpointTest method setUp.

@BeforeEach
void setUp() {
    mockScimUserProvisioning = mock(ScimUserProvisioning.class);
    mockExpiringCodeStore = mock(ExpiringCodeStore.class);
    mockPasswordValidator = mock(PasswordValidator.class);
    RandomValueStringGenerator randomValueStringGenerator = new RandomValueStringGenerator();
    currentZoneId = "currentZoneId-" + randomValueStringGenerator.generate();
    IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
    when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(currentZoneId);
    ResetPasswordService resetPasswordService = new UaaResetPasswordService(mockScimUserProvisioning, mockExpiringCodeStore, mockPasswordValidator, mock(MultitenantClientServices.class), mock(ResourcePropertySource.class), mockIdentityZoneManager);
    PasswordResetEndpoint controller = new PasswordResetEndpoint(resetPasswordService, mockExpiringCodeStore, mockIdentityZoneManager);
    mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
    PasswordChange change = new PasswordChange("id001", "user@example.com", yesterday, null, null);
    when(mockExpiringCodeStore.generateCode(eq("id001"), any(Timestamp.class), anyString(), anyString())).thenReturn(new ExpiringCode("secret_code", new Timestamp(System.currentTimeMillis() + UaaResetPasswordService.PASSWORD_RESET_LIFETIME), "id001", null));
    when(mockExpiringCodeStore.generateCode(eq(JsonUtils.writeValueAsString(change)), any(Timestamp.class), anyString(), anyString())).thenReturn(new ExpiringCode("secret_code", new Timestamp(System.currentTimeMillis() + UaaResetPasswordService.PASSWORD_RESET_LIFETIME), JsonUtils.writeValueAsString(change), null));
}
Also used : ScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning) Timestamp(java.sql.Timestamp) MultitenantClientServices(org.cloudfoundry.identity.uaa.zone.MultitenantClientServices) ResourcePropertySource(org.springframework.core.io.support.ResourcePropertySource) ExpiringCode(org.cloudfoundry.identity.uaa.codestore.ExpiringCode) PasswordChange(org.cloudfoundry.identity.uaa.scim.endpoints.PasswordChange) PasswordValidator(org.cloudfoundry.identity.uaa.scim.validate.PasswordValidator) ExpiringCodeStore(org.cloudfoundry.identity.uaa.codestore.ExpiringCodeStore) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with IdentityZoneManager

use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager in project uaa by cloudfoundry.

the class ClientAdminBootstrapTests method setUpClientAdminTests.

@BeforeEach
void setUpClientAdminTests() {
    randomValueStringGenerator = new RandomValueStringGenerator();
    IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
    when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(IdentityZone.getUaaZoneId());
    multitenantJdbcClientDetailsService = spy(new MultitenantJdbcClientDetailsService(jdbcTemplate, mockIdentityZoneManager, passwordEncoder));
    clientMetadataProvisioning = new JdbcClientMetadataProvisioning(multitenantJdbcClientDetailsService, jdbcTemplate);
    autoApproveId = "autoapprove-" + randomValueStringGenerator.generate().toLowerCase();
    clients = new HashMap<>();
    clientAdminBootstrap = new ClientAdminBootstrap(passwordEncoder, multitenantJdbcClientDetailsService, clientMetadataProvisioning, true, clients, Collections.singleton(autoApproveId), Collections.emptySet(), null);
    mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
    clientAdminBootstrap.setApplicationEventPublisher(mockApplicationEventPublisher);
}
Also used : MultitenantJdbcClientDetailsService(org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with IdentityZoneManager

use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager in project uaa by cloudfoundry.

the class CodeStoreEndpointsTests method setUp.

@BeforeEach
void setUp(@Autowired JdbcTemplate jdbcTemplate) {
    currentTime = new AtomicLong(System.currentTimeMillis());
    spiedExpiringCodeStore = spy(new JdbcExpiringCodeStore(jdbcTemplate.getDataSource(), new TimeService() {

        @Override
        public long getCurrentTimeMillis() {
            return currentTime.get();
        }
    }));
    currentIdentityZoneId = createDummyIdentityZone(jdbcTemplate);
    final IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
    when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(currentIdentityZoneId);
    codeStoreEndpoints = new CodeStoreEndpoints(spiedExpiringCodeStore, null, mockIdentityZoneManager);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TimeService(org.cloudfoundry.identity.uaa.util.TimeService) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with IdentityZoneManager

use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager in project uaa by cloudfoundry.

the class TokenRevocationEndpointTests method setupForTokenRevocation.

@BeforeEach
void setupForTokenRevocation() {
    String zoneId = IdentityZoneHolder.get().getId();
    RandomValueStringGenerator generator = new RandomValueStringGenerator();
    String clientId = generator.generate().toLowerCase();
    client = new BaseClientDetails(clientId, "", "some.scopes", "client_credentials", "authorities");
    client.addAdditionalInformation(TOKEN_SALT, "pre-salt");
    IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
    when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(IdentityZone.getUaaZoneId());
    clientService = spy(new MultitenantJdbcClientDetailsService(jdbcTemplate, mockIdentityZoneManager, passwordEncoder));
    clientService.addClientDetails(client, zoneId);
    ScimUserProvisioning userProvisioning = new JdbcScimUserProvisioning(jdbcTemplate, new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter), passwordEncoder);
    JdbcRevocableTokenProvisioning provisioning = spy(new JdbcRevocableTokenProvisioning(jdbcTemplate, limitSqlAdapter, new TimeServiceImpl()));
    endpoint = spy(new TokenRevocationEndpoint(clientService, userProvisioning, provisioning));
    ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
    endpoint.setApplicationEventPublisher(publisher);
    SecurityContextHolder.getContext().setAuthentication(new UaaOauth2Authentication("token-value", zoneId, mock(OAuth2Request.class), new UaaAuthentication(new UaaPrincipal("id", "username", "username@test.com", OriginKeys.UAA, "", zoneId), Collections.emptyList(), mock(UaaAuthenticationDetails.class))));
    provisioning.create(new RevocableToken().setClientId(client.getClientId()).setTokenId("token-id").setUserId(null).setResponseType(RevocableToken.TokenType.ACCESS_TOKEN).setValue("value").setIssuedAt(System.currentTimeMillis()), zoneId);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) MultitenantJdbcClientDetailsService(org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService) JdbcRevocableTokenProvisioning(org.cloudfoundry.identity.uaa.oauth.token.JdbcRevocableTokenProvisioning) JdbcPagingListFactory(org.cloudfoundry.identity.uaa.resources.jdbc.JdbcPagingListFactory) UaaAuthenticationDetails(org.cloudfoundry.identity.uaa.authentication.UaaAuthenticationDetails) JdbcScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimUserProvisioning) ScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning) JdbcScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimUserProvisioning) UaaAuthentication(org.cloudfoundry.identity.uaa.authentication.UaaAuthentication) UaaPrincipal(org.cloudfoundry.identity.uaa.authentication.UaaPrincipal) RevocableToken(org.cloudfoundry.identity.uaa.oauth.token.RevocableToken) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

IdentityZoneManager (org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager)10 BeforeEach (org.junit.jupiter.api.BeforeEach)9 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)6 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)5 ScimUserProvisioning (org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning)3 MultitenantClientServices (org.cloudfoundry.identity.uaa.zone.MultitenantClientServices)3 MultitenantJdbcClientDetailsService (org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService)3 JdbcApprovalStore (org.cloudfoundry.identity.uaa.approval.JdbcApprovalStore)2 ExpiringCodeStore (org.cloudfoundry.identity.uaa.codestore.ExpiringCodeStore)2 RevocableToken (org.cloudfoundry.identity.uaa.oauth.token.RevocableToken)2 PasswordValidator (org.cloudfoundry.identity.uaa.scim.validate.PasswordValidator)2 UaaUserDatabase (org.cloudfoundry.identity.uaa.user.UaaUserDatabase)2 TimeServiceImpl (org.cloudfoundry.identity.uaa.util.TimeServiceImpl)2 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)2 Lists (com.google.common.collect.Lists)1 Timestamp (java.sql.Timestamp)1 Instant (java.time.Instant)1 java.util (java.util)1 EMPTY_LIST (java.util.Collections.EMPTY_LIST)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1