use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager 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);
}
use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager in project uaa by cloudfoundry.
the class UaaResetPasswordServiceTests method setUp.
@BeforeEach
void setUp() {
SecurityContextHolder.clearContext();
scimUserProvisioning = mock(ScimUserProvisioning.class);
codeStore = mock(ExpiringCodeStore.class);
passwordValidator = mock(PasswordValidator.class);
clientDetailsService = mock(MultitenantClientServices.class);
RandomValueStringGenerator randomValueStringGenerator = new RandomValueStringGenerator();
currentZoneId = "currentZoneId-" + randomValueStringGenerator.generate();
IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(currentZoneId);
ResourcePropertySource resourcePropertySource = mock(ResourcePropertySource.class);
uaaResetPasswordService = new UaaResetPasswordService(scimUserProvisioning, codeStore, passwordValidator, clientDetailsService, resourcePropertySource, mockIdentityZoneManager);
}
use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager in project uaa by cloudfoundry.
the class TokenValidationTest method setup.
@Before
public void setup() {
String defaultKeyId = "some-key-id";
IdentityZone uaaZone = IdentityZone.getUaa();
uaaZone.getConfig().getTokenPolicy().setKeys(map(entry(defaultKeyId, macSigningKeySecret)));
IdentityZoneProvisioning identityZoneProvisioning = mock(IdentityZoneProvisioning.class);
when(identityZoneProvisioning.retrieve(anyString())).thenReturn(uaaZone);
IdentityZoneHolder.setProvisioning(identityZoneProvisioning);
header = map(entry("alg", "HS256"), entry("kid", defaultKeyId));
content = map(entry("jti", "8b14f193-8212-4af2-9927-e3ae903f94a6"), entry("nonce", "04e2e934200b4b9fbe5d4e70ae18ba8e"), entry("sub", "a7f07bf6-e720-4652-8999-e980189cef54"), entry("scope", Collections.singletonList("acme.dev")), entry("client_id", "app"), entry("cid", "app"), entry("azp", "app"), entry("grant_type", GRANT_TYPE_AUTHORIZATION_CODE), entry("user_id", "a7f07bf6-e720-4652-8999-e980189cef54"), entry("origin", "uaa"), entry("user_name", "marissa"), entry("email", "marissa@test.org"), entry("auth_time", 1458953554), entry("rev_sig", "fa1c787d"), entry("iat", 1458953932), entry("exp", 1458997132), entry("iss", "http://localhost:8080/uaa/oauth/token"), entry("zid", "uaa"), entry("aud", Arrays.asList("app", "acme")), entry("revocable", true));
signer = new MacSigner(macSigningKeySecret);
IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(IdentityZone.getUaaZoneId());
inMemoryMultitenantClientServices = new InMemoryMultitenantClientServices(mockIdentityZoneManager);
uaaClient = new BaseClientDetails("app", "acme", "acme.dev", GRANT_TYPE_AUTHORIZATION_CODE, "");
uaaClient.addAdditionalInformation(REQUIRED_USER_GROUPS, Collections.emptyList());
inMemoryMultitenantClientServices.setClientDetailsStore(IdentityZone.getUaaZoneId(), Collections.singletonMap(CLIENT_ID, uaaClient));
revocableTokenProvisioning = mock(RevocableTokenProvisioning.class);
when(revocableTokenProvisioning.retrieve("8b14f193-8212-4af2-9927-e3ae903f94a6", IdentityZoneHolder.get().getId())).thenReturn(new RevocableToken().setValue(UaaTokenUtils.constructToken(header, content, signer)));
userDb = new MockUaaUserDatabase(u -> u.withUsername("marissa").withId(USER_ID).withEmail("marissa@test.org").withAuthorities(Collections.singletonList(new SimpleGrantedAuthority("acme.dev"))));
uaaUser = userDb.retrieveUserById(USER_ID);
uaaUserGroups = uaaUser.getAuthorities().stream().map(a -> a.getAuthority()).collect(Collectors.toList());
}
use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager in project uaa by cloudfoundry.
the class UaaUserApprovalHandlerTests method setUp.
@BeforeEach
void setUp() {
final RandomValueStringGenerator generator = new RandomValueStringGenerator();
final MultitenantClientServices mockMultitenantClientServices = mock(MultitenantClientServices.class);
final AuthorizationServerTokenServices mockAuthorizationServerTokenServices = mock(AuthorizationServerTokenServices.class);
final IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
final String currentIdentityZoneId = "currentIdentityZoneId-" + generator.generate();
when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(currentIdentityZoneId);
handler = new UaaUserApprovalHandler(mockMultitenantClientServices, null, mockAuthorizationServerTokenServices, mockIdentityZoneManager);
authorizationRequest = new AuthorizationRequest("client", Collections.singletonList("read"));
userAuthentication = new UsernamePasswordAuthenticationToken("joe", "", AuthorityUtils.commaSeparatedStringToAuthorityList("USER"));
client = new BaseClientDetails("client", "none", "read,write", GRANT_TYPE_AUTHORIZATION_CODE, "uaa.none");
when(mockMultitenantClientServices.loadClientByClientId("client", currentIdentityZoneId)).thenReturn(client);
}
use of org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager 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);
}
Aggregations