use of org.apache.syncope.common.lib.to.SAML2IdPTO in project syncope by apache.
the class SAML2ITCase method setIdPMapping.
@Test
public void setIdPMapping() {
assumeTrue(SAML2SPDetector.isSAML2SPAvailable());
Optional<SAML2IdPTO> ssoCircleOpt = saml2IdPService.list().stream().filter(o -> "https://idp.ssocircle.com".equals(o.getEntityID())).findFirst();
assertTrue(ssoCircleOpt.isPresent());
SAML2IdPTO ssoCircle = ssoCircleOpt.get();
assertNotNull(ssoCircle);
assertFalse(ssoCircle.isCreateUnmatching());
assertNull(ssoCircle.getUserTemplate());
assertFalse(ssoCircle.getItems().isEmpty());
assertNotNull(ssoCircle.getConnObjectKeyItem());
assertNotEquals("email", ssoCircle.getConnObjectKeyItem().getIntAttrName());
assertNotEquals("EmailAddress", ssoCircle.getConnObjectKeyItem().getExtAttrName());
ssoCircle.setCreateUnmatching(true);
UserTO userTemplate = new UserTO();
userTemplate.setRealm("'/'");
ssoCircle.setUserTemplate(userTemplate);
ssoCircle.getItems().clear();
ItemTO keyMapping = new ItemTO();
keyMapping.setIntAttrName("email");
keyMapping.setExtAttrName("EmailAddress");
ssoCircle.setConnObjectKeyItem(keyMapping);
saml2IdPService.update(ssoCircle);
ssoCircle = saml2IdPService.read(ssoCircle.getKey());
assertTrue(ssoCircle.isCreateUnmatching());
assertEquals(userTemplate, ssoCircle.getUserTemplate());
assertEquals("email", ssoCircle.getConnObjectKeyItem().getIntAttrName());
assertEquals("EmailAddress", ssoCircle.getConnObjectKeyItem().getExtAttrName());
}
use of org.apache.syncope.common.lib.to.SAML2IdPTO in project syncope by apache.
the class SAML2IdPLogic method importIdPs.
private List<SAML2IdPTO> importIdPs(final InputStream input) throws Exception {
List<EntityDescriptor> idpEntityDescriptors = new ArrayList<>();
Element root = OpenSAMLUtil.getParserPool().parse(new InputStreamReader(input)).getDocumentElement();
if (SAMLConstants.SAML20MD_NS.equals(root.getNamespaceURI()) && EntityDescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(root.getLocalName())) {
idpEntityDescriptors.add((EntityDescriptor) OpenSAMLUtil.fromDom(root));
} else if (SAMLConstants.SAML20MD_NS.equals(root.getNamespaceURI()) && EntitiesDescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(root.getLocalName())) {
NodeList children = root.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (SAMLConstants.SAML20MD_NS.equals(child.getNamespaceURI()) && EntityDescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(child.getLocalName())) {
NodeList descendants = child.getChildNodes();
for (int j = 0; j < descendants.getLength(); j++) {
Node descendant = descendants.item(j);
if (SAMLConstants.SAML20MD_NS.equals(descendant.getNamespaceURI()) && IDPSSODescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(descendant.getLocalName())) {
idpEntityDescriptors.add((EntityDescriptor) OpenSAMLUtil.fromDom((Element) child));
}
}
}
}
}
List<SAML2IdPTO> result = new ArrayList<>(idpEntityDescriptors.size());
for (EntityDescriptor idpEntityDescriptor : idpEntityDescriptors) {
SAML2IdPTO idpTO = new SAML2IdPTO();
idpTO.setEntityID(idpEntityDescriptor.getEntityID());
idpTO.setName(idpEntityDescriptor.getEntityID());
idpTO.setUseDeflateEncoding(false);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
saml2rw.write(new OutputStreamWriter(baos), idpEntityDescriptor, false);
idpTO.setMetadata(Base64.getEncoder().encodeToString(baos.toByteArray()));
}
ItemTO connObjectKeyItem = new ItemTO();
connObjectKeyItem.setIntAttrName("username");
connObjectKeyItem.setExtAttrName("NameID");
idpTO.setConnObjectKeyItem(connObjectKeyItem);
SAML2IdPEntity idp = cache.put(idpEntityDescriptor, idpTO);
if (idp.getSSOLocation(SAML2BindingType.POST) != null) {
idpTO.setBindingType(SAML2BindingType.POST);
} else if (idp.getSSOLocation(SAML2BindingType.REDIRECT) != null) {
idpTO.setBindingType(SAML2BindingType.REDIRECT);
} else {
throw new IllegalArgumentException("Neither POST nor REDIRECT artifacts supported by " + idp.getId());
}
result.add(idpTO);
}
return result;
}
use of org.apache.syncope.common.lib.to.SAML2IdPTO in project syncope by apache.
the class SAML2IdPsResource method newResourceResponse.
@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
ResourceResponse response = new ResourceResponse();
response.setContentType(MediaType.APPLICATION_JSON);
response.setTextEncoding(StandardCharsets.UTF_8.name());
try {
final ArrayNode result = MAPPER.createArrayNode();
for (SAML2IdPTO idp : SyncopeEnduserSession.get().getService(SAML2IdPService.class).list()) {
ObjectNode idpNode = MAPPER.createObjectNode();
idpNode.put("name", idp.getName());
idpNode.put("entityID", idp.getEntityID());
idpNode.put("logout", idp.isLogoutSupported());
result.add(idpNode);
}
response.setWriteCallback(new AbstractResource.WriteCallback() {
@Override
public void writeData(final Attributes attributes) throws IOException {
attributes.getResponse().write(MAPPER.writeValueAsString(result));
}
});
response.setStatusCode(Response.Status.OK.getStatusCode());
} catch (Exception e) {
LOG.error("Error retrieving available SAML 2.0 Identity Providers", e);
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "ErrorMessage{{ " + e.getMessage() + "}}");
}
return response;
}
use of org.apache.syncope.common.lib.to.SAML2IdPTO in project syncope by apache.
the class SAML2IdPLogic method importFromMetadata.
@PreAuthorize("hasRole('" + SAML2SPEntitlement.IDP_IMPORT + "')")
public List<String> importFromMetadata(final InputStream input) {
check();
List<String> imported = new ArrayList<>();
try {
for (SAML2IdPTO idpTO : importIdPs(input)) {
SAML2IdP idp = idpDAO.save(binder.create(idpTO));
imported.add(idp.getKey());
}
} catch (SyncopeClientException e) {
throw e;
} catch (Exception e) {
LOG.error("Unexpected error while importing IdP metadata", e);
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidEntity);
sce.getElements().add(e.getMessage());
throw sce;
}
return imported;
}
use of org.apache.syncope.common.lib.to.SAML2IdPTO in project syncope by apache.
the class SAML2IdPsDirectoryPanel method getActions.
@Override
public ActionsPanel<SAML2IdPTO> getActions(final IModel<SAML2IdPTO> model) {
final ActionsPanel<SAML2IdPTO> panel = super.getActions(model);
panel.add(new ActionLink<SAML2IdPTO>() {
private static final long serialVersionUID = -7978723352517770645L;
@Override
public void onClick(final AjaxRequestTarget target, final SAML2IdPTO ignore) {
SAML2IdPTO object = restClient.read(model.getObject().getKey());
metadataModal.header(Model.of(object.getName() + " - Metadata"));
metadataModal.setContent(new XMLEditorPanel(metadataModal, Model.of(new String(Base64.decodeBase64(object.getMetadata()))), true, pageRef));
metadataModal.show(true);
target.add(metadataModal);
}
}, ActionLink.ActionType.HTML, SAML2SPEntitlement.IDP_READ);
panel.add(new ActionLink<SAML2IdPTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final SAML2IdPTO ignore) {
SAML2IdPTO object = restClient.read(model.getObject().getKey());
send(SAML2IdPsDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(object, target));
}
}, ActionLink.ActionType.EDIT, SAML2SPEntitlement.IDP_UPDATE);
panel.add(new ActionLink<SAML2IdPTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final SAML2IdPTO ignore) {
final SAML2IdPTO object = restClient.read(model.getObject().getKey());
UserTemplateWizardBuilder builder = new UserTemplateWizardBuilder(object.getUserTemplate(), new AnyTypeRestClient().read(AnyTypeKind.USER.name()).getClasses(), new UserFormLayoutInfo(), pageRef) {
private static final long serialVersionUID = -7978723352517770634L;
@Override
protected Serializable onApplyInternal(final AnyWrapper<UserTO> modelObject) {
object.setUserTemplate(modelObject.getInnerObject());
restClient.update(object);
return modelObject;
}
};
templateModal.header(Model.of(StringUtils.capitalize(new StringResourceModel("template.title", SAML2IdPsDirectoryPanel.this).getString())));
templateModal.setContent(builder.build(BaseModal.CONTENT_ID));
templateModal.show(true);
target.add(templateModal);
}
}, ActionLink.ActionType.TEMPLATE, SAML2SPEntitlement.IDP_UPDATE);
panel.add(new ActionLink<SAML2IdPTO>() {
private static final long serialVersionUID = -5467832321897812767L;
@Override
public void onClick(final AjaxRequestTarget target, final SAML2IdPTO ignore) {
try {
restClient.delete(model.getObject().getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
LOG.error("While deleting object {}", model.getObject().getKey(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
}, ActionLink.ActionType.DELETE, SAML2SPEntitlement.IDP_DELETE, true);
return panel;
}
Aggregations