Search in sources :

Example 11 with OxAuthClient

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

the class ClientPasswordAction method update.

public String update() {
    OxAuthClient client = clientService.getClientByDn(updateClientAction.getClient().getDn());
    try {
        client.setOxAuthClientSecret(newPassword);
    } catch (EncryptionException e) {
        log.error("Failed to encrypt password", e);
    }
    clientService.updateClient(client);
    // Update client password in action class
    updateClientAction.getClient().setEncodedClientSecret(client.getEncodedClientSecret());
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) EncryptionException(org.xdi.util.security.StringEncrypter.EncryptionException)

Example 12 with OxAuthClient

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

the class UpdateSectorIdentifierAction method updateClients.

private void updateClients(List<DisplayNameEntry> oldClientDisplayNameEntries, List<DisplayNameEntry> newClientDisplayNameEntries) throws Exception {
    log.debug("Old clients: {}", oldClientDisplayNameEntries);
    log.debug("New clients: {}", newClientDisplayNameEntries);
    String sectorIdentifierDn = this.sectorIdentifier.getDn();
    // Convert members to array of DNs
    String[] oldClientDns = convertToDNsArray(oldClientDisplayNameEntries);
    String[] newClientDns = convertToDNsArray(newClientDisplayNameEntries);
    Arrays.sort(oldClientDns);
    Arrays.sort(newClientDns);
    boolean[] retainOldClients = new boolean[oldClientDns.length];
    Arrays.fill(retainOldClients, false);
    List<String> addedMembers = new ArrayList<String>();
    List<String> removedMembers = new ArrayList<String>();
    List<String> existingMembers = new ArrayList<String>();
    // Add new values
    for (String value : newClientDns) {
        int idx = Arrays.binarySearch(oldClientDns, value);
        if (idx >= 0) {
            // Old members array contains member. Retain member
            retainOldClients[idx] = true;
        } else {
            // This is new member
            addedMembers.add(value);
        }
    }
    // Remove clients which we don't have in new clients
    for (int i = 0; i < oldClientDns.length; i++) {
        if (retainOldClients[i]) {
            existingMembers.add(oldClientDns[i]);
        } else {
            removedMembers.add(oldClientDns[i]);
        }
    }
    for (String dn : addedMembers) {
        OxAuthClient client = clientService.getClientByDn(dn);
        log.debug("Adding sector identifier {} to client {}", sectorIdentifierDn, client.getDisplayName());
        client.setSectorIdentifierUri(getSectorIdentifierUrl());
        clientService.updateClient(client);
    }
    for (String dn : removedMembers) {
        OxAuthClient client = clientService.getClientByDn(dn);
        log.debug("Removing sector identifier {} from client {}", sectorIdentifierDn, client.getDisplayName());
        client.setSectorIdentifierUri(null);
        clientService.updateClient(client);
    }
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) ArrayList(java.util.ArrayList)

Example 13 with OxAuthClient

use of org.gluu.oxtrust.model.OxAuthClient 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);
                }
                trustService.updateReleasedAttributes(trust);
                trustService.updateTrustRelationship(trust);
                svnSyncTimer.updateTrustRelationship(trust, identity.getCredentials().getUsername());
            }
        }
        trustService.updateTrustRelationship(this.trustRelationship);
        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);
        }
        svnSyncTimer.updateTrustRelationship(this.trustRelationship, identity.getCredentials().getUsername());
    } else {
        trustService.addTrustRelationship(this.trustRelationship);
        svnSyncTimer.addTrustRelationship(this.trustRelationship, identity.getCredentials().getUsername());
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) HashSet(java.util.HashSet)

Example 14 with OxAuthClient

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

the class UpdateResourceAction method acceptSelectClients.

public void acceptSelectClients() {
    Set<String> addedClientInums = getAddedClientsInums();
    for (SelectableEntity<OxAuthClient> availableClient : this.availableClients) {
        OxAuthClient oxAuthClient = availableClient.getEntity();
        String oxAuthClientInum = oxAuthClient.getInum();
        if (availableClient.isSelected() && !addedClientInums.contains(oxAuthClientInum)) {
            addClient(oxAuthClient);
        }
        if (!availableClient.isSelected() && addedClientInums.contains(oxAuthClientInum)) {
            removeClient(oxAuthClientInum);
        }
    }
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient)

Example 15 with OxAuthClient

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

the class ClientWebService method update.

@PUT
@Path("/update/{inum}")
@Produces(MediaType.TEXT_PLAIN)
public String update(@PathParam("inum") String inum, OxAuthClient client, @Context HttpServletResponse response) {
    try {
        // TODO
        clientService.updateClient(client);
        OxAuthClient updatedClient = clientService.getClientByInum(inum);
        ObjectMapper mapper = new ObjectMapper();
        String clientJson = mapper.writeValueAsString(updatedClient);
        return OxTrustConstants.RESULT_SUCCESS;
    } catch (Exception e) {
        logger.error("update() Exception", e);
        try {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "INTERNAL SERVER ERROR");
        } catch (Exception ex) {
        }
        return OxTrustConstants.RESULT_FAILURE;
    }
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)19 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 GET (javax.ws.rs.GET)3 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)2 URI (java.net.URI)1 PUT (javax.ws.rs.PUT)1 Response (javax.ws.rs.core.Response)1 ClientAssociation (org.gluu.oxtrust.model.association.ClientAssociation)1 Filter (org.gluu.search.filter.Filter)1 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)1 UmaResource (org.xdi.oxauth.model.uma.persistence.UmaResource)1 EncryptionException (org.xdi.util.security.StringEncrypter.EncryptionException)1