Search in sources :

Example 1 with CouchbaseConnectionConfiguration

use of io.jans.orm.couchbase.model.CouchbaseConnectionConfiguration in project jans by JanssenProject.

the class CouchbaseConfService method getOrCreateIDPAuthConfs.

private List<IDPAuthConf> getOrCreateIDPAuthConfs(List<IDPAuthConf> existing, List<CouchbaseConnectionConfiguration> confs) {
    if (existing == null) {
        existing = Lists.newArrayList();
    }
    for (CouchbaseConnectionConfiguration conf : confs) {
        Optional<IDPAuthConf> existingConf = existing.stream().filter(o -> o.getName() != null && o.getName().equals(conf.getConfigId())).findFirst();
        final IDPAuthConf idpConf;
        if (existingConf.isEmpty()) {
            idpConf = new IDPAuthConf();
            existing.add(idpConf);
        } else {
            idpConf = existingConf.get();
        }
        if (shouldEncryptPassword(conf)) {
            try {
                conf.setUserPassword(encryptionService.encrypt(conf.getUserPassword()));
            } catch (StringEncrypter.EncryptionException e) {
                throw new RuntimeException("Unable to decrypt password.", e);
            }
        }
        idpConf.setType(AUTH);
        idpConf.setVersion(idpConf.getVersion() + 1);
        idpConf.setName(conf.getConfigId());
        idpConf.setEnabled(true);
        idpConf.setConfig(JacksonUtils.newMapper().valueToTree(conf));
    }
    return existing;
}
Also used : GluuConfiguration(io.jans.as.persistence.model.configuration.GluuConfiguration) EncryptionService(io.jans.as.common.service.common.EncryptionService) JacksonUtils(com.github.fge.jackson.JacksonUtils) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) List(java.util.List) Lists(com.google.common.collect.Lists) IDPAuthConf(io.jans.as.persistence.model.configuration.IDPAuthConf) CouchbaseConnectionConfiguration(io.jans.orm.couchbase.model.CouchbaseConnectionConfiguration) StringEncrypter(io.jans.util.security.StringEncrypter) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IDPAuthConf(io.jans.as.persistence.model.configuration.IDPAuthConf) StringEncrypter(io.jans.util.security.StringEncrypter) CouchbaseConnectionConfiguration(io.jans.orm.couchbase.model.CouchbaseConnectionConfiguration)

Example 2 with CouchbaseConnectionConfiguration

use of io.jans.orm.couchbase.model.CouchbaseConnectionConfiguration in project jans by JanssenProject.

the class CouchbaseConfigurationResource method patch.

@PATCH
@Path(ApiConstants.NAME_PARAM_PATH)
@Consumes(MediaType.APPLICATION_JSON_PATCH_JSON)
@ProtectedApi(scopes = { ApiAccessConstants.DATABASE_COUCHBASE_WRITE_ACCESS })
public Response patch(@PathParam(ApiConstants.NAME) String name, @NotNull String requestString) throws Exception {
    log.debug("COUCHBASE to be patched - name = " + name + " , requestString = " + requestString);
    CouchbaseConnectionConfiguration conf = findByName(name);
    log.info("Patch configuration by name " + name);
    conf = Jackson.applyPatch(requestString, conf);
    couchbaseConfService.save(conf);
    return Response.ok(conf).build();
}
Also used : CouchbaseConnectionConfiguration(io.jans.orm.couchbase.model.CouchbaseConnectionConfiguration) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Aggregations

CouchbaseConnectionConfiguration (io.jans.orm.couchbase.model.CouchbaseConnectionConfiguration)2 JacksonUtils (com.github.fge.jackson.JacksonUtils)1 Lists (com.google.common.collect.Lists)1 EncryptionService (io.jans.as.common.service.common.EncryptionService)1 GluuConfiguration (io.jans.as.persistence.model.configuration.GluuConfiguration)1 IDPAuthConf (io.jans.as.persistence.model.configuration.IDPAuthConf)1 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)1 StringEncrypter (io.jans.util.security.StringEncrypter)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1