use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getClientMapperFacade.
public MapperFacade getClientMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
ClassMapBuilder<ClientSummary, ClientDetailsEntity> clientSummaryClassMap = mapperFactory.classMap(ClientSummary.class, ClientDetailsEntity.class);
clientSummaryClassMap.field("name", "clientName");
clientSummaryClassMap.field("description", "clientDescription");
clientSummaryClassMap.byDefault();
clientSummaryClassMap.register();
ClassMapBuilder<Client, ClientDetailsEntity> clientClassMap = mapperFactory.classMap(Client.class, ClientDetailsEntity.class);
clientClassMap.field("name", "clientName");
clientClassMap.field("description", "clientDescription");
clientClassMap.field("website", "clientWebsite");
clientClassMap.field("allowAutoDeprecate", "allowAutoDeprecate");
clientClassMap.fieldBToA("clientId", "id");
clientClassMap.fieldBToA("clientType", "clientType");
clientClassMap.fieldBToA("groupProfileId", "groupProfileId");
clientClassMap.fieldBToA("authenticationProviderId", "authenticationProviderId");
clientClassMap.fieldBToA("persistentTokensEnabled", "persistentTokensEnabled");
clientClassMap.customize(new CustomMapper<Client, ClientDetailsEntity>() {
/**
* On the way in, from Client to ClientDetailsEntity, we need to care about mapping the redirect uri's, since all config features will not change from UI requests
*/
@Override
public void mapAtoB(Client a, ClientDetailsEntity b, MappingContext context) {
Map<String, ClientRedirectUriEntity> existingRedirectUriEntitiesMap = new HashMap<String, ClientRedirectUriEntity>();
if (b.getClientRegisteredRedirectUris() != null && !b.getClientRegisteredRedirectUris().isEmpty()) {
existingRedirectUriEntitiesMap = ClientRedirectUriEntity.mapByUriAndType(b.getClientRegisteredRedirectUris());
}
if (b.getClientRegisteredRedirectUris() != null) {
b.getClientRegisteredRedirectUris().clear();
} else {
b.setClientRegisteredRedirectUris(new TreeSet<ClientRedirectUriEntity>());
}
if (a.getClientRedirectUris() != null) {
for (ClientRedirectUri cru : a.getClientRedirectUris()) {
String rUriKey = ClientRedirectUriEntity.getUriAndTypeKey(cru.getRedirectUri(), cru.getRedirectUriType());
if (existingRedirectUriEntitiesMap.containsKey(rUriKey)) {
ClientRedirectUriEntity existingEntity = existingRedirectUriEntitiesMap.get(rUriKey);
existingEntity.setLastModified(new Date());
existingEntity.setPredefinedClientScope(ScopePathType.getScopesAsSingleString(cru.getPredefinedClientScopes()));
existingEntity.setUriActType(cru.getUriActType());
existingEntity.setUriGeoArea(cru.getUriGeoArea());
b.getClientRegisteredRedirectUris().add(existingEntity);
} else {
ClientRedirectUriEntity newEntity = new ClientRedirectUriEntity();
newEntity.setClientDetailsEntity(b);
newEntity.setDateCreated(new Date());
newEntity.setLastModified(new Date());
newEntity.setPredefinedClientScope(ScopePathType.getScopesAsSingleString(cru.getPredefinedClientScopes()));
newEntity.setRedirectUri(cru.getRedirectUri());
newEntity.setRedirectUriType(cru.getRedirectUriType());
newEntity.setUriActType(cru.getUriActType());
newEntity.setUriGeoArea(cru.getUriGeoArea());
b.getClientRegisteredRedirectUris().add(newEntity);
}
}
}
}
/**
* On the way out, from ClientDetailsEntity to Client, we just need to care about mapping the redirect uri's and the primary client secret since all config features will not be visible on the UI
*/
@Override
public void mapBtoA(ClientDetailsEntity b, Client a, MappingContext context) {
if (b.getClientSecrets() != null) {
for (ClientSecretEntity entity : b.getClientSecrets()) {
if (entity.isPrimary()) {
a.setDecryptedSecret(encryptionManager.decryptForInternalUse(entity.getClientSecret()));
}
}
}
if (b.getRegisteredRedirectUri() != null) {
a.setClientRedirectUris(new HashSet<ClientRedirectUri>());
for (ClientRedirectUriEntity entity : b.getClientRegisteredRedirectUris()) {
ClientRedirectUri element = new ClientRedirectUri();
element.setRedirectUri(entity.getRedirectUri());
element.setRedirectUriType(entity.getRedirectUriType());
element.setUriActType(entity.getUriActType());
element.setUriGeoArea(entity.getUriGeoArea());
element.setPredefinedClientScopes(ScopePathType.getScopesFromSpaceSeparatedString(entity.getPredefinedClientScope()));
a.getClientRedirectUris().add(element);
}
}
}
});
clientClassMap.register();
return mapperFactory.getMapperFacade();
}
use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getClientMapperFacade.
public MapperFacade getClientMapperFacade() {
MapperFactory mapperFactory = getNewMapperFactory();
ClassMapBuilder<ClientSummary, ClientDetailsEntity> clientSummaryClassMap = mapperFactory.classMap(ClientSummary.class, ClientDetailsEntity.class);
clientSummaryClassMap.field("name", "clientName");
clientSummaryClassMap.field("description", "clientDescription");
clientSummaryClassMap.byDefault();
clientSummaryClassMap.register();
ClassMapBuilder<Client, ClientDetailsEntity> clientClassMap = mapperFactory.classMap(Client.class, ClientDetailsEntity.class);
clientClassMap.field("name", "clientName");
clientClassMap.field("description", "clientDescription");
clientClassMap.field("website", "clientWebsite");
clientClassMap.field("allowAutoDeprecate", "allowAutoDeprecate");
clientClassMap.fieldBToA("clientId", "id");
clientClassMap.fieldBToA("clientType", "clientType");
clientClassMap.fieldBToA("groupProfileId", "groupProfileId");
clientClassMap.fieldBToA("authenticationProviderId", "authenticationProviderId");
clientClassMap.fieldBToA("persistentTokensEnabled", "persistentTokensEnabled");
clientClassMap.customize(new CustomMapper<Client, ClientDetailsEntity>() {
/**
* On the way in, from Client to ClientDetailsEntity, we need to
* care about mapping the redirect uri's, since all config features
* will not change from UI requests
*/
@Override
public void mapAtoB(Client a, ClientDetailsEntity b, MappingContext context) {
Map<String, ClientRedirectUriEntity> existingRedirectUriEntitiesMap = new HashMap<String, ClientRedirectUriEntity>();
if (b.getClientRegisteredRedirectUris() != null && !b.getClientRegisteredRedirectUris().isEmpty()) {
existingRedirectUriEntitiesMap = ClientRedirectUriEntity.mapByUriAndType(b.getClientRegisteredRedirectUris());
}
if (b.getClientRegisteredRedirectUris() != null) {
b.getClientRegisteredRedirectUris().clear();
} else {
b.setClientRegisteredRedirectUris(new TreeSet<ClientRedirectUriEntity>());
}
if (a.getClientRedirectUris() != null) {
for (ClientRedirectUri cru : a.getClientRedirectUris()) {
String rUriKey = ClientRedirectUriEntity.getUriAndTypeKey(cru);
if (existingRedirectUriEntitiesMap.containsKey(rUriKey)) {
ClientRedirectUriEntity existingEntity = existingRedirectUriEntitiesMap.get(rUriKey);
existingEntity.setLastModified(new Date());
existingEntity.setPredefinedClientScope(ScopePathType.getScopesAsSingleString(cru.getPredefinedClientScopes()));
existingEntity.setUriActType(cru.getUriActType());
existingEntity.setUriGeoArea(cru.getUriGeoArea());
b.getClientRegisteredRedirectUris().add(existingEntity);
} else {
ClientRedirectUriEntity newEntity = new ClientRedirectUriEntity();
newEntity.setClientDetailsEntity(b);
newEntity.setDateCreated(new Date());
newEntity.setLastModified(new Date());
newEntity.setPredefinedClientScope(ScopePathType.getScopesAsSingleString(cru.getPredefinedClientScopes()));
newEntity.setRedirectUri(cru.getRedirectUri());
newEntity.setRedirectUriType(cru.getRedirectUriType());
newEntity.setUriActType(cru.getUriActType());
newEntity.setUriGeoArea(cru.getUriGeoArea());
b.getClientRegisteredRedirectUris().add(newEntity);
}
}
}
}
/**
* On the way out, from ClientDetailsEntity to Client, we just need
* to care about mapping the redirect uri's and the primary client
* secret since all config features will not be visible on the UI
*/
@Override
public void mapBtoA(ClientDetailsEntity b, Client a, MappingContext context) {
if (b.getClientSecrets() != null) {
for (ClientSecretEntity entity : b.getClientSecrets()) {
if (entity.isPrimary()) {
a.setDecryptedSecret(encryptionManager.decryptForInternalUse(entity.getClientSecret()));
}
}
}
if (b.getRegisteredRedirectUri() != null) {
a.setClientRedirectUris(new HashSet<ClientRedirectUri>());
for (ClientRedirectUriEntity entity : b.getClientRegisteredRedirectUris()) {
ClientRedirectUri element = new ClientRedirectUri();
element.setRedirectUri(entity.getRedirectUri());
element.setRedirectUriType(entity.getRedirectUriType());
element.setUriActType(entity.getUriActType());
element.setUriGeoArea(entity.getUriGeoArea());
element.setPredefinedClientScopes(ScopePathType.getScopesFromSpaceSeparatedString(entity.getPredefinedClientScope()));
a.getClientRedirectUris().add(element);
}
}
}
});
clientClassMap.register();
return mapperFactory.getMapperFacade();
}
use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity in project ORCID-Source by ORCID.
the class ClientDetailsManagerImpl method getClientRegisteredRedirectUris.
private SortedSet<ClientRedirectUriEntity> getClientRegisteredRedirectUris(Set<RedirectUri> clientRegisteredRedirectUris, ClientDetailsEntity clientDetailsEntity) {
SortedSet<ClientRedirectUriEntity> clientRedirectUriEntities = new TreeSet<ClientRedirectUriEntity>();
for (RedirectUri clientRegisteredRedirectUri : clientRegisteredRedirectUris) {
ClientRedirectUriEntity clientRedirectUriEntity = new ClientRedirectUriEntity();
clientRedirectUriEntity.setClientDetailsEntity(clientDetailsEntity);
clientRedirectUriEntity.setRedirectUri(clientRegisteredRedirectUri.getValue());
clientRedirectUriEntity.setRedirectUriType(clientRegisteredRedirectUri.getType().value());
List<ScopePathType> scopesForRedirect = clientRegisteredRedirectUri.getScope();
String clientPredefinedScopes = scopesForRedirect != null ? ScopePathType.getScopesAsSingleString(scopesForRedirect) : null;
clientRedirectUriEntity.setPredefinedClientScope(clientPredefinedScopes);
clientRedirectUriEntity.setUriActType(clientRegisteredRedirectUri.getActType());
clientRedirectUriEntity.setUriGeoArea(clientRegisteredRedirectUri.getGeoArea());
clientRedirectUriEntities.add(clientRedirectUriEntity);
}
return clientRedirectUriEntities;
}
use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity in project ORCID-Source by ORCID.
the class ThirdPartyLinkManagerImpl method generateImportWizzardForm.
private List<ImportWizzardClientForm> generateImportWizzardForm(RedirectUriType rut, Locale locale) {
List<ClientRedirectUriEntity> entitiesWithPredefinedScopes = clientRedirectDao.findClientDetailsWithRedirectScope();
List<ImportWizzardClientForm> clients = new ArrayList<ImportWizzardClientForm>();
for (ClientRedirectUriEntity entity : entitiesWithPredefinedScopes) {
if (rut.value().equals(entity.getRedirectUriType())) {
if (rut.value().equals(entity.getRedirectUriType())) {
ClientDetailsEntity clientDetails = entity.getClientDetailsEntity();
ImportWizzardClientForm clientForm = new ImportWizzardClientForm();
clientForm.setId(clientDetails.getId());
clientForm.setName(clientDetails.getClientName());
clientForm.setDescription(clientDetails.getClientDescription());
clientForm.setRedirectUri(entity.getRedirectUri());
clientForm.setScopes(entity.getPredefinedClientScope());
if (RedirectUriType.IMPORT_WORKS_WIZARD.equals(rut)) {
if (!PojoUtil.isEmpty(entity.getUriActType())) {
JsonNode node = JsonUtils.readTree(entity.getUriActType());
List<String> elements = new ArrayList<String>();
if (node.has("import-works-wizard")) {
node.get("import-works-wizard").forEach(x -> {
String value = x.asText();
switch(value) {
case "Articles":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.work_type.articles", locale));
break;
case "Data":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.work_type.books", locale));
break;
case "Books":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.work_type.data", locale));
break;
case "Student Publications":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.work_type.student_publications", locale));
break;
default:
elements.add(value);
break;
}
});
}
clientForm.setActTypes(elements);
}
if (!PojoUtil.isEmpty(entity.getUriActType())) {
JsonNode node = JsonUtils.readTree(entity.getUriGeoArea());
List<String> elements = new ArrayList<String>();
if (node.has("import-works-wizard")) {
node.get("import-works-wizard").forEach(x -> {
String value = x.asText();
switch(value) {
case "Africa":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.africa", locale));
break;
case "Asia":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.asia", locale));
break;
case "Australia":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.australia", locale));
break;
case "Europe":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.europe", locale));
break;
case "Global":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.global", locale));
break;
case "North America":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.north_america", locale));
break;
case "South America":
elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.south_america", locale));
break;
default:
elements.add(value);
break;
}
});
}
clientForm.setGeoAreas(elements);
}
}
clients.add(clientForm);
}
}
}
return clients;
}
use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity in project ORCID-Source by ORCID.
the class ClientManagerReadOnlyTest method getClientDetailsEntity.
private ClientDetailsEntity getClientDetailsEntity(String randomString) {
Date now = new Date();
ClientDetailsEntity entity = new ClientDetailsEntity();
entity.setAllowAutoDeprecate(true);
entity.setAuthenticationProviderId("authentication-provider-id " + randomString);
entity.setClientDescription("description " + randomString);
entity.setClientName("client-name " + randomString);
entity.setClientType(ClientType.CREATOR);
entity.setClientWebsite("client-website " + randomString);
entity.setDateCreated(now);
entity.setEmailAccessReason("email-access-reason " + randomString);
entity.setGroupProfileId("group-profile-id " + randomString);
entity.setId(randomString);
entity.setLastModified(now);
entity.setPersistentTokensEnabled(true);
entity.setClientSecretForJpa("secret-1 " + randomString);
entity.setClientSecretForJpa("secret-2 " + randomString);
entity.setClientSecretForJpa("secret-3 " + randomString);
HashSet<ClientAuthorisedGrantTypeEntity> clientAuthorisedGrantTypeEntities = new HashSet<ClientAuthorisedGrantTypeEntity>();
ClientAuthorisedGrantTypeEntity cagt1 = new ClientAuthorisedGrantTypeEntity();
cagt1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cagt1.setDateCreated(now);
cagt1.setGrantType("grant-type-1 " + randomString);
cagt1.setLastModified(now);
ClientAuthorisedGrantTypeEntity cagt2 = new ClientAuthorisedGrantTypeEntity();
cagt2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cagt2.setDateCreated(now);
cagt2.setGrantType("grant-type-2 " + randomString);
cagt2.setLastModified(now);
ClientAuthorisedGrantTypeEntity cagt3 = new ClientAuthorisedGrantTypeEntity();
cagt3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cagt3.setDateCreated(now);
cagt3.setGrantType("grant-type-3 " + randomString);
cagt3.setLastModified(now);
clientAuthorisedGrantTypeEntities.add(cagt1);
clientAuthorisedGrantTypeEntities.add(cagt2);
clientAuthorisedGrantTypeEntities.add(cagt3);
entity.setClientAuthorizedGrantTypes(clientAuthorisedGrantTypeEntities);
List<ClientGrantedAuthorityEntity> clientGrantedAuthorityEntities = new ArrayList<ClientGrantedAuthorityEntity>();
ClientGrantedAuthorityEntity cga1 = new ClientGrantedAuthorityEntity();
cga1.setAuthority("authority-1 " + randomString);
cga1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cga1.setDateCreated(now);
cga1.setLastModified(now);
ClientGrantedAuthorityEntity cga2 = new ClientGrantedAuthorityEntity();
cga2.setAuthority("authority-2 " + randomString);
cga2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cga2.setDateCreated(now);
cga2.setLastModified(now);
ClientGrantedAuthorityEntity cga3 = new ClientGrantedAuthorityEntity();
cga3.setAuthority("authority-3 " + randomString);
cga3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cga3.setDateCreated(now);
cga3.setLastModified(now);
clientGrantedAuthorityEntities.add(cga1);
clientGrantedAuthorityEntities.add(cga2);
clientGrantedAuthorityEntities.add(cga3);
entity.setClientGrantedAuthorities(clientGrantedAuthorityEntities);
SortedSet<ClientRedirectUriEntity> clientRegisteredRedirectUris = new TreeSet<ClientRedirectUriEntity>();
ClientRedirectUriEntity rUri1 = new ClientRedirectUriEntity();
rUri1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
rUri1.setDateCreated(now);
rUri1.setLastModified(now);
rUri1.setPredefinedClientScope(ScopePathType.ACTIVITIES_READ_LIMITED.value());
rUri1.setRedirectUri("redirect-uri-1 " + randomString);
rUri1.setRedirectUriType("type-1 " + randomString);
rUri1.setUriActType("uri-act-type-1 " + randomString);
rUri1.setUriGeoArea("uri-geo-area-1 " + randomString);
ClientRedirectUriEntity rUri2 = new ClientRedirectUriEntity();
rUri2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
rUri2.setDateCreated(now);
rUri2.setLastModified(now);
rUri2.setPredefinedClientScope(ScopePathType.ACTIVITIES_UPDATE.value());
rUri2.setRedirectUri("redirect-uri-2 " + randomString);
rUri2.setRedirectUriType("type-2 " + randomString);
rUri2.setUriActType("uri-act-type-2 " + randomString);
rUri2.setUriGeoArea("uri-geo-area-2 " + randomString);
ClientRedirectUriEntity rUri3 = new ClientRedirectUriEntity();
rUri3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
rUri3.setDateCreated(now);
rUri3.setLastModified(now);
rUri3.setPredefinedClientScope(ScopePathType.AFFILIATIONS_CREATE.value());
rUri3.setRedirectUri("redirect-uri-3 " + randomString);
rUri3.setRedirectUriType("type-3 " + randomString);
rUri3.setUriActType("uri-act-type-3 " + randomString);
rUri3.setUriGeoArea("uri-geo-area-3 " + randomString);
clientRegisteredRedirectUris.add(rUri1);
clientRegisteredRedirectUris.add(rUri2);
clientRegisteredRedirectUris.add(rUri3);
entity.setClientRegisteredRedirectUris(clientRegisteredRedirectUris);
Set<ClientResourceIdEntity> clientResourceIds = new HashSet<ClientResourceIdEntity>();
ClientResourceIdEntity cri1 = new ClientResourceIdEntity();
cri1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cri1.setDateCreated(now);
cri1.setLastModified(now);
cri1.setResourceId("resource-id-1 " + randomString);
ClientResourceIdEntity cri2 = new ClientResourceIdEntity();
cri2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cri2.setDateCreated(now);
cri2.setLastModified(now);
cri2.setResourceId("resource-id-2 " + randomString);
ClientResourceIdEntity cri3 = new ClientResourceIdEntity();
cri3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cri3.setDateCreated(now);
cri3.setLastModified(now);
cri3.setResourceId("resource-id-3 " + randomString);
clientResourceIds.add(cri1);
clientResourceIds.add(cri2);
clientResourceIds.add(cri3);
entity.setClientResourceIds(clientResourceIds);
Set<ClientScopeEntity> clientScopes = new HashSet<ClientScopeEntity>();
ClientScopeEntity cs1 = new ClientScopeEntity();
cs1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cs1.setDateCreated(now);
cs1.setLastModified(now);
cs1.setScopeType("scope-type-1 " + randomString);
ClientScopeEntity cs2 = new ClientScopeEntity();
cs2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cs2.setDateCreated(now);
cs2.setLastModified(now);
cs2.setScopeType("scope-type-2 " + randomString);
ClientScopeEntity cs3 = new ClientScopeEntity();
cs3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
cs3.setDateCreated(now);
cs3.setLastModified(now);
cs3.setScopeType("scope-type-3 " + randomString);
clientScopes.add(cs1);
clientScopes.add(cs2);
clientScopes.add(cs3);
entity.setClientScopes(clientScopes);
Set<CustomEmailEntity> customEmails = new HashSet<CustomEmailEntity>();
CustomEmailEntity ce1 = new CustomEmailEntity();
ce1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
ce1.setContent("content-1 " + randomString);
ce1.setDateCreated(now);
ce1.setEmailType(EmailType.ACCOUNT_DEPRECATED);
ce1.setHtml(true);
ce1.setLastModified(now);
ce1.setSender("sender-1 " + randomString);
ce1.setSubject("subject-1 " + randomString);
CustomEmailEntity ce2 = new CustomEmailEntity();
ce2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
ce2.setContent("content-2 " + randomString);
ce2.setDateCreated(now);
ce2.setEmailType(EmailType.ACCOUNT_DEPRECATED);
ce2.setHtml(true);
ce2.setLastModified(now);
ce2.setSender("sender-2 " + randomString);
ce2.setSubject("subject-2 " + randomString);
CustomEmailEntity ce3 = new CustomEmailEntity();
ce3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
ce3.setContent("content-3 " + randomString);
ce3.setDateCreated(now);
ce3.setEmailType(EmailType.ACCOUNT_DEPRECATED);
ce3.setHtml(true);
ce3.setLastModified(now);
ce3.setSender("sender-3 " + randomString);
ce3.setSubject("subject-3 " + randomString);
customEmails.add(ce1);
customEmails.add(ce2);
customEmails.add(ce3);
entity.setCustomEmails(customEmails);
return entity;
}
Aggregations