use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.
the class BrokerTest method testNoNameIDAndPrincipalFromAttribute.
@Test
public void testNoNameIDAndPrincipalFromAttribute() throws IOException {
final String userName = "newUser-" + UUID.randomUUID();
final RealmResource realm = adminClient.realm(REALM_NAME);
final IdentityProviderRepresentation rep = addIdentityProvider("https://saml.idp/");
rep.getConfig().put(SAMLIdentityProviderConfig.NAME_ID_POLICY_FORMAT, "undefined");
rep.getConfig().put(SAMLIdentityProviderConfig.PRINCIPAL_TYPE, SamlPrincipalType.ATTRIBUTE.toString());
rep.getConfig().put(SAMLIdentityProviderConfig.PRINCIPAL_ATTRIBUTE, "user");
try (IdentityProviderCreator idp = new IdentityProviderCreator(realm, rep)) {
new SamlClientBuilder().authnRequest(getAuthServerSamlEndpoint(REALM_NAME), SAML_CLIENT_ID_SALES_POST, SAML_ASSERTION_CONSUMER_URL_SALES_POST, POST).build().login().idp(SAML_BROKER_ALIAS).build().processSamlResponse(REDIRECT).transformObject(this::createAuthnResponse).transformObject(resp -> {
final ResponseType rt = (ResponseType) resp;
final AssertionType assertion = rt.getAssertions().get(0).getAssertion();
// Remove NameID from subject
assertion.getSubject().setSubType(null);
// Add attribute to get principal from
AttributeStatementType attrStatement = new AttributeStatementType();
AttributeType attribute = new AttributeType("user");
attribute.addAttributeValue(userName);
attrStatement.addAttribute(new ASTChoiceType(attribute));
rt.getAssertions().get(0).getAssertion().addStatement(attrStatement);
return rt;
}).targetAttributeSamlResponse().targetUri(getSamlBrokerUrl(REALM_NAME)).build().followOneRedirect().updateProfile().username(userName).firstName("someFirstName").lastName("someLastName").email("some@email.com").build().followOneRedirect().assertResponse(org.keycloak.testsuite.util.Matchers.statusCodeIsHC(200)).execute();
}
final UserRepresentation userRepresentation = realm.users().search(userName).stream().findFirst().get();
final List<UserSessionRepresentation> userSessions = realm.users().get(userRepresentation.getId()).getUserSessions();
assertThat(userSessions, hasSize(1));
}
use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.
the class PermissionsTest method identityProviders.
@Test
public void identityProviders() {
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().findAll();
}
}, Resource.IDENTITY_PROVIDER, false);
invoke(new InvocationWithResponse() {
public void invoke(RealmResource realm, AtomicReference<Response> response) {
response.set(realm.identityProviders().create(IdentityProviderBuilder.create().providerId("oidc").displayName("nosuch-foo").alias("foo").setAttribute("clientId", "foo").setAttribute("clientSecret", "foo").build()));
}
}, Resource.IDENTITY_PROVIDER, true);
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().get("nosuch").toRepresentation();
}
}, Resource.IDENTITY_PROVIDER, false);
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().get("nosuch").update(new IdentityProviderRepresentation());
}
}, Resource.IDENTITY_PROVIDER, true);
invoke(new InvocationWithResponse() {
public void invoke(RealmResource realm, AtomicReference<Response> response) {
response.set(realm.identityProviders().get("nosuch").export("saml"));
}
}, Resource.IDENTITY_PROVIDER, false);
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().get("nosuch").remove();
}
}, Resource.IDENTITY_PROVIDER, true);
invoke(new InvocationWithResponse() {
public void invoke(RealmResource realm, AtomicReference<Response> response) {
response.set(realm.identityProviders().get("nosuch").addMapper(new IdentityProviderMapperRepresentation()));
}
}, Resource.IDENTITY_PROVIDER, true);
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().get("nosuch").delete("nosuch");
}
}, Resource.IDENTITY_PROVIDER, true);
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().get("nosuch").getMappers();
}
}, Resource.IDENTITY_PROVIDER, false);
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().get("nosuch").getMapperById("nosuch");
}
}, Resource.IDENTITY_PROVIDER, false);
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().get("nosuch").getMapperTypes();
}
}, Resource.IDENTITY_PROVIDER, false);
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().importFrom(Collections.<String, Object>emptyMap());
}
}, Resource.IDENTITY_PROVIDER, true);
invoke(new Invocation() {
public void invoke(RealmResource realm) {
realm.identityProviders().importFrom(new MultipartFormDataOutput());
}
}, Resource.IDENTITY_PROVIDER, true);
}
use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.
the class IdentityProviderTest method createRep.
private IdentityProviderRepresentation createRep(String id, String providerId, boolean enabled, Map<String, String> config) {
IdentityProviderRepresentation idp = new IdentityProviderRepresentation();
idp.setAlias(id);
idp.setDisplayName(id);
idp.setProviderId(providerId);
idp.setEnabled(enabled);
if (config != null) {
idp.setConfig(config);
}
return idp;
}
use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.
the class IdentityProviderTest method testUpdate.
@Test
public void testUpdate() {
IdentityProviderRepresentation newIdentityProvider = createRep("update-identity-provider", "oidc");
newIdentityProvider.getConfig().put(IdentityProviderModel.SYNC_MODE, "IMPORT");
newIdentityProvider.getConfig().put("clientId", "clientId");
newIdentityProvider.getConfig().put("clientSecret", "some secret value");
create(newIdentityProvider);
IdentityProviderResource identityProviderResource = realm.identityProviders().get("update-identity-provider");
assertNotNull(identityProviderResource);
IdentityProviderRepresentation representation = identityProviderResource.toRepresentation();
assertNotNull(representation);
assertEquals("update-identity-provider", representation.getAlias());
representation.setAlias("changed-alias");
representation.setEnabled(false);
representation.setStoreToken(true);
representation.getConfig().put("clientId", "changedClientId");
identityProviderResource.update(representation);
AdminEventRepresentation event = assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.identityProviderPath("update-identity-provider"), representation, ResourceType.IDENTITY_PROVIDER);
assertFalse(event.getRepresentation().contains("some secret value"));
assertTrue(event.getRepresentation().contains(ComponentRepresentation.SECRET_VALUE));
identityProviderResource = realm.identityProviders().get(representation.getInternalId());
assertNotNull(identityProviderResource);
representation = identityProviderResource.toRepresentation();
assertFalse(representation.isEnabled());
assertTrue(representation.isStoreToken());
assertEquals("changedClientId", representation.getConfig().get("clientId"));
assertEquals("some secret value", testingClient.testing("admin-client-test").getIdentityProviderConfig("changed-alias").get("clientSecret"));
representation.getConfig().put("clientSecret", "${vault.key}");
identityProviderResource.update(representation);
event = assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.identityProviderPath(representation.getInternalId()), representation, ResourceType.IDENTITY_PROVIDER);
assertThat(event.getRepresentation(), containsString("${vault.key}"));
assertThat(event.getRepresentation(), not(containsString(ComponentRepresentation.SECRET_VALUE)));
assertThat(identityProviderResource.toRepresentation().getConfig(), hasEntry("clientSecret", "${vault.key}"));
assertEquals("${vault.key}", testingClient.testing("admin-client-test").getIdentityProviderConfig("changed-alias").get("clientSecret"));
}
use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.
the class IdentityProviderTest method testCreateWithReservedCharacterForAlias.
@Test
public void testCreateWithReservedCharacterForAlias() {
IdentityProviderRepresentation newIdentityProvider = createRep("ne$&w-identity-provider", "oidc");
newIdentityProvider.getConfig().put("clientId", "clientId");
newIdentityProvider.getConfig().put("clientSecret", "some secret value");
Response response = realm.identityProviders().create(newIdentityProvider);
Assert.assertEquals(400, response.getStatus());
}
Aggregations