Search in sources :

Example 1 with JdbcIdentityProviderProvisioning

use of org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning in project uaa by cloudfoundry.

the class CheckIdpEnabledAuthenticationManagerTest method setupAuthManager.

@BeforeEach
void setupAuthManager(@Autowired JdbcTemplate jdbcTemplate) {
    TestUtils.cleanAndSeedDb(jdbcTemplate);
    identityProviderProvisioning = new JdbcIdentityProviderProvisioning(jdbcTemplate);
    MockUaaUserDatabase userDatabase = new MockUaaUserDatabase(u -> u.withId("id").withUsername("marissa").withEmail("test@test.org").withVerified(true).withPassword("koala"));
    PasswordEncoder encoder = mock(PasswordEncoder.class);
    when(encoder.matches(anyString(), anyString())).thenReturn(true);
    AuthzAuthenticationManager authzAuthenticationManager = new AuthzAuthenticationManager(userDatabase, encoder, identityProviderProvisioning, null);
    authzAuthenticationManager.setOrigin(OriginKeys.UAA);
    AccountLoginPolicy mockAccountLoginPolicy = mock(AccountLoginPolicy.class);
    when(mockAccountLoginPolicy.isAllowed(any(), any())).thenReturn(true);
    authzAuthenticationManager.setAccountLoginPolicy(mockAccountLoginPolicy);
    manager = new CheckIdpEnabledAuthenticationManager(authzAuthenticationManager, OriginKeys.UAA, identityProviderProvisioning);
    token = new UsernamePasswordAuthenticationToken("marissa", "koala");
}
Also used : MockUaaUserDatabase(org.cloudfoundry.identity.uaa.user.MockUaaUserDatabase) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) JdbcIdentityProviderProvisioning(org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with JdbcIdentityProviderProvisioning

use of org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning in project uaa by cloudfoundry.

the class IdentityProviderBootstrapTest method setup.

@BeforeEach
void setup() throws Exception {
    samlIdentityProviderDefinition = new SamlIdentityProviderDefinition();
    samlIdentityProviderDefinition.setAssertionConsumerIndex(0);
    samlIdentityProviderDefinition.setIconUrl("iconUrl");
    samlIdentityProviderDefinition.setIdpEntityAlias("alias");
    samlIdentityProviderDefinition.setLinkText("text");
    samlIdentityProviderDefinition.setMetaDataLocation("http://location");
    samlIdentityProviderDefinition.setNameID("nameId");
    samlIdentityProviderDefinition.setShowSamlLink(true);
    samlIdentityProviderDefinition.setMetadataTrustCheck(true);
    samlIdentityProviderDefinition1 = samlIdentityProviderDefinition.clone();
    samlIdentityProviderDefinition1.setIdpEntityAlias("alias2");
    samlIdentityProviderDefinition1.setMetaDataLocation("http://location2");
    oauthProvider = new RawExternalOAuthIdentityProviderDefinition();
    setCommonProperties(oauthProvider);
    oidcProvider = new OIDCIdentityProviderDefinition();
    setCommonProperties(oidcProvider);
    oauthProviderConfig = new HashMap<>();
    oauthProviderConfig.put(OAUTH20, oauthProvider);
    oauthProviderConfig.put(OIDC10, oidcProvider);
    configurator = mock(BootstrapSamlIdentityProviderData.class);
    publisher = mock(ApplicationEventPublisher.class);
    provisioning = new JdbcIdentityProviderProvisioning(jdbcTemplate);
    environment = new MockEnvironment();
    bootstrap = new IdentityProviderBootstrap(provisioning, environment);
    bootstrap.setApplicationEventPublisher(publisher);
}
Also used : BootstrapSamlIdentityProviderData(org.cloudfoundry.identity.uaa.provider.saml.BootstrapSamlIdentityProviderData) MockEnvironment(org.springframework.mock.env.MockEnvironment) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) SamlIdentityProviderDefinition(org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition) RawExternalOAuthIdentityProviderDefinition(org.cloudfoundry.identity.uaa.provider.RawExternalOAuthIdentityProviderDefinition) OIDCIdentityProviderDefinition(org.cloudfoundry.identity.uaa.provider.OIDCIdentityProviderDefinition) JdbcIdentityProviderProvisioning(org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning) IdentityProviderBootstrap(org.cloudfoundry.identity.uaa.impl.config.IdentityProviderBootstrap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with JdbcIdentityProviderProvisioning

use of org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning in project uaa by cloudfoundry.

the class LoginSamlAuthenticationProviderTests method configureProvider.

@BeforeEach
void configureProvider() throws SAMLException, SecurityException, DecryptionException, ValidationException {
    identityZoneManager = new IdentityZoneManagerImpl();
    RequestContextHolder.resetRequestAttributes();
    MockHttpServletRequest request = new MockHttpServletRequest(mock(ServletContext.class));
    MockHttpServletResponse response = new MockHttpServletResponse();
    ServletWebRequest servletWebRequest = new ServletWebRequest(request, response);
    RequestContextHolder.setRequestAttributes(servletWebRequest);
    ScimGroupProvisioning groupProvisioning = new JdbcScimGroupProvisioning(jdbcTemplate, new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter));
    identityZoneManager.getCurrentIdentityZone().getConfig().getUserConfig().setDefaultGroups(Collections.singletonList("uaa.user"));
    groupProvisioning.createOrGet(new ScimGroup(null, "uaa.user", identityZoneManager.getCurrentIdentityZone().getId()), identityZoneManager.getCurrentIdentityZone().getId());
    providerDefinition = new SamlIdentityProviderDefinition();
    userProvisioning = new JdbcScimUserProvisioning(jdbcTemplate, new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter), passwordEncoder);
    uaaSamlUser = groupProvisioning.create(new ScimGroup(null, UAA_SAML_USER, IdentityZone.getUaaZoneId()), identityZoneManager.getCurrentIdentityZone().getId());
    uaaSamlAdmin = groupProvisioning.create(new ScimGroup(null, UAA_SAML_ADMIN, IdentityZone.getUaaZoneId()), identityZoneManager.getCurrentIdentityZone().getId());
    ScimGroup uaaSamlTest = groupProvisioning.create(new ScimGroup(null, UAA_SAML_TEST, IdentityZone.getUaaZoneId()), identityZoneManager.getCurrentIdentityZone().getId());
    JdbcScimGroupMembershipManager membershipManager = new JdbcScimGroupMembershipManager(jdbcTemplate, new TimeServiceImpl(), userProvisioning, null);
    membershipManager.setScimGroupProvisioning(groupProvisioning);
    ScimUserBootstrap bootstrap = new ScimUserBootstrap(userProvisioning, groupProvisioning, membershipManager, Collections.emptyList(), false, Collections.emptyList());
    externalManager = new JdbcScimGroupExternalMembershipManager(jdbcTemplate);
    externalManager.setScimGroupProvisioning(groupProvisioning);
    externalManager.mapExternalGroup(uaaSamlUser.getId(), SAML_USER, OriginKeys.SAML, identityZoneManager.getCurrentIdentityZone().getId());
    externalManager.mapExternalGroup(uaaSamlAdmin.getId(), SAML_ADMIN, OriginKeys.SAML, identityZoneManager.getCurrentIdentityZone().getId());
    externalManager.mapExternalGroup(uaaSamlTest.getId(), SAML_TEST, OriginKeys.SAML, identityZoneManager.getCurrentIdentityZone().getId());
    consumer = mock(WebSSOProfileConsumer.class);
    SAMLCredential credential = getUserCredential("marissa-saml", "Marissa", "Bloggs", "marissa.bloggs@test.com", "1234567890");
    when(consumer.processAuthenticationResponse(any())).thenReturn(credential);
    TimeService timeService = mock(TimeService.class);
    userDatabase = new JdbcUaaUserDatabase(jdbcTemplate, timeService, false, identityZoneManager);
    providerProvisioning = new JdbcIdentityProviderProvisioning(jdbcTemplate);
    publisher = new CreateUserPublisher(bootstrap);
    authprovider = new LoginSamlAuthenticationProvider(identityZoneManager, userDatabase, providerProvisioning, externalManager);
    authprovider.setApplicationEventPublisher(publisher);
    authprovider.setConsumer(consumer);
    authprovider.setSamlLogger(samlLogger);
    provider = new IdentityProvider();
    provider.setIdentityZoneId(IdentityZone.getUaaZoneId());
    provider.setOriginKey(OriginKeys.SAML);
    provider.setName("saml-test");
    provider.setActive(true);
    provider.setType(OriginKeys.SAML);
    providerDefinition.setMetaDataLocation(String.format(IDP_META_DATA, OriginKeys.SAML));
    providerDefinition.setIdpEntityAlias(OriginKeys.SAML);
    provider.setConfig(providerDefinition);
    provider = providerProvisioning.create(provider, identityZoneManager.getCurrentIdentityZone().getId());
}
Also used : JdbcScimGroupExternalMembershipManager(org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupExternalMembershipManager) TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) JdbcPagingListFactory(org.cloudfoundry.identity.uaa.resources.jdbc.JdbcPagingListFactory) JdbcUaaUserDatabase(org.cloudfoundry.identity.uaa.user.JdbcUaaUserDatabase) JdbcScimGroupMembershipManager(org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupMembershipManager) IdentityZoneManagerImpl(org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManagerImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JdbcScimGroupProvisioning(org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupProvisioning) TimeService(org.cloudfoundry.identity.uaa.util.TimeService) JdbcScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimUserProvisioning) IdentityProvider(org.cloudfoundry.identity.uaa.provider.IdentityProvider) ScimGroupProvisioning(org.cloudfoundry.identity.uaa.scim.ScimGroupProvisioning) JdbcScimGroupProvisioning(org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupProvisioning) JdbcIdentityProviderProvisioning(org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning) WebSSOProfileConsumer(org.springframework.security.saml.websso.WebSSOProfileConsumer) ScimUserBootstrap(org.cloudfoundry.identity.uaa.scim.bootstrap.ScimUserBootstrap) SAMLCredential(org.springframework.security.saml.SAMLCredential) SamlIdentityProviderDefinition(org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition) ServletContext(javax.servlet.ServletContext) ScimGroup(org.cloudfoundry.identity.uaa.scim.ScimGroup) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

JdbcIdentityProviderProvisioning (org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 SamlIdentityProviderDefinition (org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition)2 ServletContext (javax.servlet.ServletContext)1 IdentityProviderBootstrap (org.cloudfoundry.identity.uaa.impl.config.IdentityProviderBootstrap)1 IdentityProvider (org.cloudfoundry.identity.uaa.provider.IdentityProvider)1 OIDCIdentityProviderDefinition (org.cloudfoundry.identity.uaa.provider.OIDCIdentityProviderDefinition)1 RawExternalOAuthIdentityProviderDefinition (org.cloudfoundry.identity.uaa.provider.RawExternalOAuthIdentityProviderDefinition)1 BootstrapSamlIdentityProviderData (org.cloudfoundry.identity.uaa.provider.saml.BootstrapSamlIdentityProviderData)1 JdbcPagingListFactory (org.cloudfoundry.identity.uaa.resources.jdbc.JdbcPagingListFactory)1 ScimGroup (org.cloudfoundry.identity.uaa.scim.ScimGroup)1 ScimGroupProvisioning (org.cloudfoundry.identity.uaa.scim.ScimGroupProvisioning)1 ScimUserBootstrap (org.cloudfoundry.identity.uaa.scim.bootstrap.ScimUserBootstrap)1 JdbcScimGroupExternalMembershipManager (org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupExternalMembershipManager)1 JdbcScimGroupMembershipManager (org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupMembershipManager)1 JdbcScimGroupProvisioning (org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupProvisioning)1 JdbcScimUserProvisioning (org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimUserProvisioning)1 JdbcUaaUserDatabase (org.cloudfoundry.identity.uaa.user.JdbcUaaUserDatabase)1 MockUaaUserDatabase (org.cloudfoundry.identity.uaa.user.MockUaaUserDatabase)1 TimeService (org.cloudfoundry.identity.uaa.util.TimeService)1