Search in sources :

Example 1 with JdbcApprovalStore

use of org.cloudfoundry.identity.uaa.approval.JdbcApprovalStore in project uaa by cloudfoundry.

the class JdbcApprovalStoreTests method setUp.

@BeforeEach
void setUp() {
    generator = new RandomValueStringGenerator();
    defaultZoneId = "defaultZoneId-" + generator.generate();
    otherZoneId = "otherZoneId-" + generator.generate();
    Stream.of("u1", "u2", "u3").forEach(userId -> testAccounts.addUser(jdbcTemplate, userId, defaultZoneId));
    jdbcApprovalStore = new JdbcApprovalStore(jdbcTemplate);
    eventPublisher = TestApplicationEventPublisher.forEventClass(ApprovalModifiedEvent.class);
    jdbcApprovalStore.setApplicationEventPublisher(eventPublisher);
    addApproval(jdbcApprovalStore, "u1", "c1", "uaa.user", 6000, APPROVED, defaultZoneId);
    addApproval(jdbcApprovalStore, "u1", "c2", "uaa.admin", 12000, DENIED, defaultZoneId);
    addApproval(jdbcApprovalStore, "u2", "c1", "openid", 6000, APPROVED, defaultZoneId);
}
Also used : ApprovalModifiedEvent(org.cloudfoundry.identity.uaa.audit.event.ApprovalModifiedEvent) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) JdbcApprovalStore(org.cloudfoundry.identity.uaa.approval.JdbcApprovalStore) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with JdbcApprovalStore

use of org.cloudfoundry.identity.uaa.approval.JdbcApprovalStore in project uaa by cloudfoundry.

the class UserManagedAuthzApprovalHandlerTests method setUp.

@BeforeEach
void setUp(@Autowired JdbcTemplate jdbcTemplate) {
    RandomValueStringGenerator generator = new RandomValueStringGenerator();
    currentIdentityZoneId = "currentIdentityZoneId-" + generator.generate();
    approvalStore = new JdbcApprovalStore(jdbcTemplate);
    QueryableResourceManager<ClientDetails> mockClientDetailsService = mock(QueryableResourceManager.class);
    mockBaseClientDetails = mock(BaseClientDetails.class);
    when(mockClientDetailsService.retrieve("foo", currentIdentityZoneId)).thenReturn(mockBaseClientDetails);
    when(mockBaseClientDetails.getScope()).thenReturn(new HashSet<>(Arrays.asList("cloud_controller.read", "cloud_controller.write", "openid", "space.*.developer")));
    when(mockBaseClientDetails.getAutoApproveScopes()).thenReturn(Collections.emptySet());
    IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
    when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(currentIdentityZoneId);
    handler = new UserManagedAuthzApprovalHandler(approvalStore, mockClientDetailsService, mockIdentityZoneManager);
    userId = "userId-" + generator.generate();
    mockAuthentication = mock(AuthenticationWithGetId.class);
    when(mockAuthentication.isAuthenticated()).thenReturn(true);
    when(mockAuthentication.getId()).thenReturn(userId);
    nextWeek = new Date(LocalDateTime.now().plus(Duration.ofDays(7)).atZone(ZoneId.systemDefault()).toEpochSecond() * 1000);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) JdbcApprovalStore(org.cloudfoundry.identity.uaa.approval.JdbcApprovalStore) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with JdbcApprovalStore

use of org.cloudfoundry.identity.uaa.approval.JdbcApprovalStore in project uaa by cloudfoundry.

the class ApprovalsAdminEndpointsTests method initApprovalsAdminEndpointsTests.

@BeforeEach
void initApprovalsAdminEndpointsTests() {
    UaaTestAccounts testAccounts = UaaTestAccounts.standard(null);
    String id = UUID.randomUUID().toString();
    String userId = testAccounts.addUser(jdbcTemplate, id, IdentityZoneHolder.get().getId());
    IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
    when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(IdentityZone.getUaaZoneId());
    IdentityZone mockIdentityZone = mock(IdentityZone.class);
    when(mockIdentityZoneManager.getCurrentIdentityZone()).thenReturn(mockIdentityZone);
    when(mockIdentityZone.getConfig()).thenReturn(IdentityZone.getUaa().getConfig());
    UaaUserDatabase userDao = new JdbcUaaUserDatabase(jdbcTemplate, new TimeServiceImpl(), false, mockIdentityZoneManager);
    marissa = userDao.retrieveUserById(userId);
    assertNotNull(marissa);
    dao = new JdbcApprovalStore(jdbcTemplate);
    mockSecurityContextAccessor = mock(SecurityContextAccessor.class);
    when(mockSecurityContextAccessor.getUserName()).thenReturn(marissa.getUsername());
    when(mockSecurityContextAccessor.getUserId()).thenReturn(marissa.getId());
    when(mockSecurityContextAccessor.isUser()).thenReturn(true);
    MultitenantJdbcClientDetailsService clientDetailsService = new MultitenantJdbcClientDetailsService(jdbcTemplate, mockIdentityZoneManager, passwordEncoder);
    BaseClientDetails details = new BaseClientDetails("c1", "scim,clients", "read,write", "authorization_code, password, implicit, client_credentials", "update");
    details.setAutoApproveScopes(Collections.singletonList("true"));
    clientDetailsService.addClientDetails(details);
    endpoints = new ApprovalsAdminEndpoints(mockSecurityContextAccessor, dao, userDao, clientDetailsService);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) MultitenantJdbcClientDetailsService(org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService) JdbcUaaUserDatabase(org.cloudfoundry.identity.uaa.user.JdbcUaaUserDatabase) ApprovalsAdminEndpoints(org.cloudfoundry.identity.uaa.approval.ApprovalsAdminEndpoints) SecurityContextAccessor(org.cloudfoundry.identity.uaa.security.beans.SecurityContextAccessor) UaaTestAccounts(org.cloudfoundry.identity.uaa.test.UaaTestAccounts) JdbcUaaUserDatabase(org.cloudfoundry.identity.uaa.user.JdbcUaaUserDatabase) UaaUserDatabase(org.cloudfoundry.identity.uaa.user.UaaUserDatabase) JdbcApprovalStore(org.cloudfoundry.identity.uaa.approval.JdbcApprovalStore) IdentityZoneManager(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

JdbcApprovalStore (org.cloudfoundry.identity.uaa.approval.JdbcApprovalStore)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 IdentityZoneManager (org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager)2 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)2 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)2 ApprovalsAdminEndpoints (org.cloudfoundry.identity.uaa.approval.ApprovalsAdminEndpoints)1 ApprovalModifiedEvent (org.cloudfoundry.identity.uaa.audit.event.ApprovalModifiedEvent)1 SecurityContextAccessor (org.cloudfoundry.identity.uaa.security.beans.SecurityContextAccessor)1 UaaTestAccounts (org.cloudfoundry.identity.uaa.test.UaaTestAccounts)1 JdbcUaaUserDatabase (org.cloudfoundry.identity.uaa.user.JdbcUaaUserDatabase)1 UaaUserDatabase (org.cloudfoundry.identity.uaa.user.UaaUserDatabase)1 TimeServiceImpl (org.cloudfoundry.identity.uaa.util.TimeServiceImpl)1 IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)1 MultitenantJdbcClientDetailsService (org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService)1 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)1