Java Code Examples for org.keycloak.representations.idm.RealmRepresentation#addIdentityProvider()

The following examples show how to use org.keycloak.representations.idm.RealmRepresentation#addIdentityProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkedAccountsRestServiceTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void configureTestRealm(RealmRepresentation testRealm) {
    testRealm.getUsers().add(UserBuilder.create().username("no-account-access").password("password").build());
    testRealm.getUsers().add(UserBuilder.create().username("view-account-access").role("account", "view-profile").password("password").build());
    
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                                          .providerId("github")
                                          .alias("github")
                                          .setAttribute("guiOrder", "2")
                                          .build());
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                                          .providerId("saml")
                                          .alias("mysaml")
                                          .setAttribute("guiOrder", "0")
                                          .build());
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                                          .providerId("oidc")
                                          .alias("myoidc")
                                          .displayName("MyOIDC")
                                          .setAttribute("guiOrder", "1")
                                          .build());
    
    addGitHubIdentity(testRealm);
}
 
Example 2
Source File: LoginPageTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void configureTestRealm(RealmRepresentation testRealm) {
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
            .providerId("github")
            .alias("github")
            .build());
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
            .providerId("saml")
            .alias("mysaml")
            .build());
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
            .providerId("oidc")
            .alias("myoidc")
            .displayName("MyOIDC")
            .build());

}
 
Example 3
Source File: HiddenProviderTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void configureTestRealm(RealmRepresentation testRealm) {        
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                                          .providerId("oidc")
                                          .alias("visible-oidc")
                                          .displayName("VisibleOIDC")
                                          .build());
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                                          .providerId("oidc")
                                          .alias("hidden-oidc")
                                          .displayName("HiddenOIDC")
                                          .hideOnLoginPage()
                                          .build());
}
 
Example 4
Source File: LinkedAccountsTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    super.addTestRealms(testRealms);
    RealmRepresentation realm1 = testRealms.get(0);

    realm1.addIdentityProvider(createIdentityProviderRepresentation(SOCIAL_IDP_ALIAS,
            GoogleIdentityProviderFactory.PROVIDER_ID));

    String oidcRoot = getAuthServerRoot() + "realms/" + REALM2_NAME + "/protocol/openid-connect/";

    IdentityProviderRepresentation systemIdp = createIdentityProviderRepresentation(SYSTEM_IDP_ALIAS,
            OIDCIdentityProviderFactory.PROVIDER_ID);
    systemIdp.getConfig().put("clientId", CLIENT_ID);
    systemIdp.getConfig().put("clientSecret", CLIENT_SECRET);
    systemIdp.getConfig().put("clientAuthMethod", OIDCLoginProtocol.CLIENT_SECRET_POST);
    systemIdp.getConfig().put("authorizationUrl", oidcRoot + "auth");
    systemIdp.getConfig().put("tokenUrl", oidcRoot + "token");
    realm1.addIdentityProvider(systemIdp);

    ClientRepresentation client = ClientBuilder.create()
            .clientId(CLIENT_ID)
            .secret(CLIENT_SECRET)
            .redirectUris(getAuthServerRoot() + "realms/" + TEST + "/broker/" + SYSTEM_IDP_ALIAS + "/endpoint")
            .build();

    // using REALM2 as an identity provider
    RealmRepresentation realm2 = new RealmRepresentation();
    realm2.setId(REALM2_NAME);
    realm2.setRealm(REALM2_NAME);
    realm2.setEnabled(true);
    realm2.setClients(Collections.singletonList(client));
    realm2.setUsers(Collections.singletonList(homerUser));
    testRealms.add(realm2);
}
 
Example 5
Source File: AccountFormServiceTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public void configureTestRealm(RealmRepresentation testRealm) {
    //UserRepresentation user = findUserInRealmRep(testRealm, "test-user@localhost");
    //ClientRepresentation accountApp = findClientInRealmRep(testRealm, ACCOUNT_MANAGEMENT_CLIENT_ID);
    UserRepresentation user2 = UserBuilder.create()
            .enabled(true)
            .username("test-user-no-access@localhost")
            .email("test-user-no-access@localhost")
            .password("password")
            .build();
    UserRepresentation realmAdmin = UserBuilder.create()
            .enabled(true)
            .username("realm-admin")
            .password("password")
            .role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.REALM_ADMIN)
            .role(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID, AccountRoles.MANAGE_ACCOUNT)
            .build();

    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                                          .providerId("github")
                                          .alias("github")
                                          .build());
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                                          .providerId("saml")
                                          .alias("mysaml")
                                          .build());
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                                          .providerId("oidc")
                                          .alias("myoidc")
                                          .displayName("MyOIDC")
                                          .build());
    testRealm.addIdentityProvider(IdentityProviderBuilder.create()
                                          .providerId("oidc")
                                          .alias("myhiddenoidc")
                                          .displayName("MyHiddenOIDC")
                                          .hideOnLoginPage()
                                          .build());

    RealmBuilder.edit(testRealm)
                .user(user2)
                .user(realmAdmin);

    if (AUTH_SERVER_SSL_REQUIRED) {
        // Some scenarios here use redirections, so we need to fix the base url
        findTestApp(testRealm)
              .setBaseUrl(String.format("%s/auth/realms/master/app/auth", getAuthServerContextRoot()));
    }
}