Search in sources :

Example 41 with GluuSAMLTrustRelationship

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

the class SamlTestScenary method run.

/**
 * Run tests.
 *
 * @throws APITestException
 * @throws OxTrustAPIException
 */
public void run() throws APITestException, OxTrustAPIException {
    TrustRelationshipClient samlClient = client.getTrustRelationshipClient();
    GluuSAMLTrustRelationship trGenerated = generateRandomeSingleTrustRelationship();
    // test create()
    String inum = samlClient.create(trGenerated);
    // test read()
    GluuSAMLTrustRelationship trReaded = samlClient.read(inum);
    // TODO: compare etities
    trReaded.setDescription("description changed");
    // test update()
    samlClient.update(trReaded, inum);
    // test list()
    List<SAMLTrustRelationshipShort> trustRelationships = samlClient.list();
    if (!checkListForTrustRelationship(trustRelationships, inum))
        throw new APITestException("TrustRelationship really not saved");
    // test delete()
    samlClient.delete(inum);
    trustRelationships = samlClient.list();
    if (checkListForTrustRelationship(trustRelationships, inum))
        throw new APITestException("TrustRelationship really not deleted");
// TODO: all API calls
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) APITestException(org.gluu.oxtrust.api.test.APITestException) TrustRelationshipClient(org.gluu.oxtrust.api.client.saml.TrustRelationshipClient) SAMLTrustRelationshipShort(org.gluu.oxtrust.api.saml.SAMLTrustRelationshipShort)

Example 42 with GluuSAMLTrustRelationship

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

the class ShibbolethInitializer method createShibbolethConfiguration.

public boolean createShibbolethConfiguration() {
    boolean createConfig = appConfiguration.isConfigGeneration();
    log.info("IDP config generation is set to " + createConfig);
    if (createConfig) {
        String gluuSPInum;
        GluuSAMLTrustRelationship gluuSP;
        try {
            gluuSPInum = applianceService.getAppliance().getGluuSPTR();
            // log.info("########## gluuSPInum = " + gluuSPInum);
            gluuSP = new GluuSAMLTrustRelationship();
            gluuSP.setDn(trustService.getDnForTrustRelationShip(gluuSPInum));
        } catch (EntryPersistenceException ex) {
            log.error("Failed to determine SP inum", ex);
            return false;
        }
        // log.info("########## gluuSP.getDn() = " + gluuSP.getDn());
        boolean servicesNeedRestarting = false;
        // if (gluuSPInum == null || ! trustService.containsTrustRelationship(gluuSP)) {
        // 
        // log.info("No trust relationships exist in LDAP. Adding gluuSP");
        // GluuAppliance appliance = applianceService.getAppliance();
        // appliance.setGluuSPTR(null);
        // applianceService.updateAppliance(appliance);
        // shibboleth3ConfService.addGluuSP();
        // servicesNeedRestarting = true;
        // }
        gluuSP = trustService.getRelationshipByInum(applianceService.getAppliance().getGluuSPTR());
        List<GluuSAMLTrustRelationship> trustRelationships = trustService.getAllActiveTrustRelationships();
        /*
			if (trustRelationships != null && !trustRelationships.isEmpty()) {
				for (GluuSAMLTrustRelationship gluuSAMLTrustRelationship : trustRelationships) {
					log.info("########## gluuSAMLTrustRelationship.getDn() = " + gluuSAMLTrustRelationship.getDn());
				}
			}
			*/
        String shibbolethVersion = appConfiguration.getShibbolethVersion();
        log.info("########## shibbolethVersion = " + shibbolethVersion);
        shibboleth3ConfService.generateMetadataFiles(gluuSP);
        shibboleth3ConfService.generateConfigurationFiles(trustRelationships);
        shibboleth3ConfService.removeUnusedCredentials();
        shibboleth3ConfService.removeUnusedMetadata();
        if (servicesNeedRestarting) {
            applianceService.restartServices();
        }
    }
    return true;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException)

Example 43 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("Analyzing '%s'.", trustRelationship.getDisplayName());
        List<String> customAttrs = trustRelationship.getReleasedAttributes();
        if (customAttrs != null) {
            for (String attrDN : customAttrs) {
                log.trace("'%s' has custom attribute '%s'", trustRelationship.getDisplayName(), attrDN);
                if (attrDN.equals(attribute.getDn())) {
                    log.trace("'%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 44 with GluuSAMLTrustRelationship

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

the class TrustRelationshipInventoryAction method setCustomAttributes.

private void setCustomAttributes(List<GluuSAMLTrustRelationship> trustRelationships) {
    List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.ADMIN);
    HashMap<String, GluuAttribute> attributesByDNs = attributeService.getAttributeMapByDNs(attributes);
    for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
        trustRelationship.setReleasedCustomAttributes(attributeService.getCustomAttributesByAttributeDNs(trustRelationship.getReleasedAttributes(), attributesByDNs));
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) GluuAttribute(org.gluu.model.GluuAttribute)

Example 45 with GluuSAMLTrustRelationship

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

the class UpdateTrustRelationshipAction method saveTR.

private void saveTR(boolean isUpdate) {
    log.trace("Saving Trust Relationship");
    if (isUpdate) {
        String oldLogoutRedirectUri = trustService.getRelationshipByDn(trustRelationship.getDn()).getSpLogoutURL();
        String newLogoutRedirectUri = trustRelationship.getSpLogoutURL();
        boolean oxClientUpdateNeeded = (oldLogoutRedirectUri != null) && (newLogoutRedirectUri != null) && !newLogoutRedirectUri.equals(oldLogoutRedirectUri);
        boolean parentInactive = trustRelationship.getStatus().equals(GluuStatus.INACTIVE);
        if (!federatedSites.isEmpty()) {
            for (GluuSAMLTrustRelationship trust : federatedSites) {
                if (parentInactive) {
                    trust.setStatus(GluuStatus.INACTIVE);
                }
                updateReleasedAttributes(trust);
                trustService.updateTrustRelationship(trust);
            }
        }
        trustService.updateTrustRelationship(this.trustRelationship);
        oxTrustAuditService.audit("TR " + this.trustRelationship.getInum() + " **" + this.trustRelationship.getDisplayName() + "** UPDATED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
        if (oxClientUpdateNeeded) {
            OxAuthClient client = clientService.getClientByInum(appConfiguration.getOxAuthClientId());
            Set<String> updatedLogoutRedirectUris = new HashSet<String>();
            List<GluuSAMLTrustRelationship> trs = trustService.getAllTrustRelationships();
            if (trs != null && !trs.isEmpty()) {
                for (GluuSAMLTrustRelationship tr : trs) {
                    String logoutRedirectUri = tr.getSpLogoutURL();
                    if (logoutRedirectUri != null && !logoutRedirectUri.isEmpty()) {
                        updatedLogoutRedirectUris.add(logoutRedirectUri);
                    }
                }
            }
            if (updatedLogoutRedirectUris.isEmpty()) {
                client.setPostLogoutRedirectUris(null);
            } else {
                client.setPostLogoutRedirectUris(updatedLogoutRedirectUris.toArray(new String[0]));
            }
            clientService.updateClient(client);
        }
    } else {
        trustService.addTrustRelationship(this.trustRelationship);
        oxTrustAuditService.audit("TR " + this.trustRelationship.getInum() + " **" + this.trustRelationship.getDisplayName() + "** ADDED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) HashSet(java.util.HashSet)

Aggregations

GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)51 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)15 CertificateEncodingException (java.security.cert.CertificateEncodingException)11 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)10 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)6 List (java.util.List)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 VelocityContext (org.apache.velocity.VelocityContext)4 SubversionFile (org.gluu.oxtrust.model.SubversionFile)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 TreeSet (java.util.TreeSet)3 GluuAttribute (org.gluu.model.GluuAttribute)3