Search in sources :

Example 21 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship in project oxTrust by GluuFederation.

the class TrustService method removeTrustRelationship.

public void removeTrustRelationship(GluuSAMLTrustRelationship trustRelationship) {
    log.info("Removing TR " + trustRelationship.getInum());
    String[] clusterMembers = appConfiguration.getClusteredInums();
    String applianceInum = appConfiguration.getApplianceInum();
    if (clusterMembers == null || clusterMembers.length == 0) {
        log.debug("there is no cluster configuration. Assuming standalone appliance.");
        clusterMembers = new String[] { applianceInum };
    }
    String dn = trustRelationship.getDn();
    for (String clusterMember : clusterMembers) {
        String clusteredDN = StringHelper.replaceLast(dn, applianceInum, clusterMember);
        trustRelationship.setDn(clusteredDN);
        GluuSAMLTrustRelationship tr = new GluuSAMLTrustRelationship();
        tr.setDn(trustRelationship.getDn());
        if (containsTrustRelationship(tr)) {
            log.debug("Removing TR" + clusteredDN);
            ldapEntryManager.remove(trustRelationship);
        }
    }
    trustRelationship.setDn(dn);
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship)

Example 22 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship in project oxTrust by GluuFederation.

the class TrustService method updateTrustRelationship.

public void updateTrustRelationship(GluuSAMLTrustRelationship trustRelationship) {
    log.debug("Updating TR " + trustRelationship.getInum());
    String[] clusterMembers = appConfiguration.getClusteredInums();
    String applianceInum = appConfiguration.getApplianceInum();
    if (clusterMembers == null || clusterMembers.length == 0) {
        log.debug("there is no cluster configuration. Assuming standalone appliance.");
        clusterMembers = new String[] { applianceInum };
    }
    String dn = trustRelationship.getDn();
    for (String clusterMember : clusterMembers) {
        String clusteredDN = StringHelper.replaceLast(dn, applianceInum, clusterMember);
        trustRelationship.setDn(clusteredDN);
        GluuSAMLTrustRelationship tr = new GluuSAMLTrustRelationship();
        tr.setDn(trustRelationship.getDn());
        if (containsTrustRelationship(tr)) {
            log.trace("Updating TR" + clusteredDN);
            ldapEntryManager.merge(trustRelationship);
        } else {
            OrganizationalUnit ou = new OrganizationalUnit();
            ou.setDn(getDnForTrustRelationShip(null));
            if (!ldapEntryManager.contains(ou)) {
                ldapEntryManager.persist(ou);
            }
            ldapEntryManager.persist(trustRelationship);
        }
    }
    trustRelationship.setDn(dn);
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) OrganizationalUnit(org.gluu.oxtrust.model.OrganizationalUnit)

Example 23 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship in project oxTrust by GluuFederation.

the class TrustService method removeAttribute.

/**
	 * Remove attribute
	 * 
	 * @param attribute
	 *            Attribute
	 */
public boolean removeAttribute(GluuAttribute attribute) {
    log.info("Attribute removal started");
    log.trace("Removing attribute from trustRelationships");
    List<GluuSAMLTrustRelationship> trustRelationships = getAllTrustRelationships();
    log.trace(String.format("Iterating '%d' trustRelationships", trustRelationships.size()));
    for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
        log.trace(String.format("Analyzing '%s'.", trustRelationship.getDisplayName()));
        List<String> customAttrs = trustRelationship.getReleasedAttributes();
        if (customAttrs != null) {
            for (String attrDN : customAttrs) {
                log.trace(String.format("'%s' has custom attribute '%s'", trustRelationship.getDisplayName(), attrDN));
                if (attrDN.equals(attribute.getDn())) {
                    log.trace(String.format("'%s' matches '%s'.  deleting it.", attrDN, attribute.getDn()));
                    List<String> updatedAttrs = new ArrayList<String>();
                    updatedAttrs.addAll(customAttrs);
                    updatedAttrs.remove(attrDN);
                    if (updatedAttrs.size() == 0) {
                        trustRelationship.setReleasedAttributes(null);
                    } else {
                        trustRelationship.setReleasedAttributes(updatedAttrs);
                    }
                    updateTrustRelationship(trustRelationship);
                    break;
                }
            }
        }
    }
    attributeService.removeAttribute(attribute);
    return true;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) ArrayList(java.util.ArrayList)

Example 24 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method addGluuSP.

/**
	 * Adds Trust relationship for own shibboleth SP and restarts services after
	 * done.
	 * 
	 * @author �Oleksiy Tataryn�
	 */
public void addGluuSP() {
    String gluuSPInum = trustService.generateInumForNewTrustRelationship();
    String metadataFN = getSpNewMetadataFileName(gluuSPInum);
    GluuSAMLTrustRelationship gluuSP = new GluuSAMLTrustRelationship();
    gluuSP.setInum(gluuSPInum);
    gluuSP.setDisplayName("gluu SP on appliance");
    gluuSP.setDescription("Trust Relationship for the SP");
    gluuSP.setSpMetaDataSourceType(GluuMetadataSourceType.FILE);
    gluuSP.setSpMetaDataFN(metadataFN);
    //TODO: 
    gluuSP.setEntityId(StringHelper.removePunctuation(gluuSP.getInum()));
    gluuSP.setUrl(appConfiguration.getApplianceUrl());
    String certificate = "";
    boolean result = false;
    try {
        certificate = FileUtils.readFileToString(new File(appConfiguration.getGluuSpCert())).replaceAll("-{5}.*?-{5}", "");
        generateSpMetadataFile(gluuSP, certificate);
        result = isCorrectSpMetadataFile(gluuSP.getSpMetaDataFN());
    } catch (IOException e) {
        log.error("Failed to gluu SP read certificate file.", e);
    }
    GluuAppliance appliance = null;
    if (result) {
        gluuSP.setStatus(GluuStatus.ACTIVE);
        String inum = gluuSP.getInum();
        String dn = trustService.getDnForTrustRelationShip(inum);
        gluuSP.setDn(dn);
        List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
        List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.ADMIN);
        HashMap<String, GluuAttribute> attributesByDNs = attributeService.getAttributeMapByDNs(attributes);
        List<String> customAttributeDNs = new ArrayList<String>();
        List<String> attributeNames = new ArrayList<String>();
        for (String attributeName : appConfiguration.getGluuSpAttributes()) {
            GluuAttribute attribute = attributeService.getAttributeByName(attributeName, attributes);
            if (attribute != null) {
                customAttributeDNs.add(attribute.getDn());
            }
        }
        customAttributes.addAll(attributeService.getCustomAttributesByAttributeDNs(customAttributeDNs, attributesByDNs));
        gluuSP.setReleasedCustomAttributes(customAttributes);
        gluuSP.setReleasedAttributes(attributeNames);
        trustService.updateReleasedAttributes(gluuSP);
        trustService.addTrustRelationship(gluuSP);
        appliance = applianceService.getAppliance();
        appliance.setGluuSPTR(gluuSP.getInum());
    }
    if (result) {
        applianceService.updateAppliance(appliance);
        log.warn("gluuSP EntityID set to " + StringHelper.removePunctuation(gluuSP.getInum()) + ". Shibboleth3 configuration should be updated.");
    // applianceService.restartServices();
    } else {
        log.error("IDP configuration update failed. GluuSP was not generated.");
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) ArrayList(java.util.ArrayList) IOException(java.io.IOException) GluuAttribute(org.xdi.model.GluuAttribute) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File)

Example 25 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method initAttributes.

/*
	 * Init attributes
	 */
private void initAttributes(List<GluuSAMLTrustRelationship> trustRelationships) {
    List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.ADMIN);
    HashMap<String, GluuAttribute> attributesByDNs = attributeService.getAttributeMapByDNs(attributes);
    GluuAttribute uid = attributeService.getAttributeByName(OxTrustConstants.uid);
    // Load attributes definition
    for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
        // Add first attribute uid
        List<String> oldAttributes = trustRelationship.getReleasedAttributes();
        List<String> releasedAttributes = new ArrayList<String>();
        if (oldAttributes != null) {
            releasedAttributes.addAll(oldAttributes);
        }
        if (uid != null) {
            if (releasedAttributes.remove(uid.getDn())) {
                releasedAttributes.add(0, uid.getDn());
            }
        }
        // Resolve custom attributes by DNs
        trustRelationship.setReleasedCustomAttributes(attributeService.getCustomAttributesByAttributeDNs(releasedAttributes, attributesByDNs));
        // Set attribute meta-data
        attributeService.setAttributeMetadata(trustRelationship.getReleasedCustomAttributes(), attributes);
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) ArrayList(java.util.ArrayList) GluuAttribute(org.xdi.model.GluuAttribute)

Aggregations

GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)28 ArrayList (java.util.ArrayList)10 GluuAttribute (org.xdi.model.GluuAttribute)5 File (java.io.File)4 IOException (java.io.IOException)4 SubversionFile (org.gluu.oxtrust.model.SubversionFile)4 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)2 OrganizationalUnit (org.gluu.oxtrust.model.OrganizationalUnit)2 InvalidConfigurationException (org.xdi.util.exception.InvalidConfigurationException)2 Filter (com.unboundid.ldap.sdk.Filter)1 AttributeTypeDefinition (com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)1 FileInputStream (java.io.FileInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 LinkedList (java.util.LinkedList)1