use of org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity in project ORCID-Source by ORCID.
the class AddGrantTypeToExistingClients method updateGrantTypes.
private void updateGrantTypes(ClientDetailsEntity clientDetails) {
for (String grantType : grantTypes) {
boolean alreadyHaveGrantType = false;
for (String existingGrantType : clientDetails.getAuthorizedGrantTypes()) {
if (grantType.equals(existingGrantType)) {
alreadyHaveGrantType = true;
break;
}
}
if (!alreadyHaveGrantType) {
ClientAuthorisedGrantTypeEntity newGrantType = new ClientAuthorisedGrantTypeEntity();
newGrantType.setGrantType(grantType);
newGrantType.setClientDetailsEntity(clientDetails);
clientDetails.getClientAuthorizedGrantTypes().add(newGrantType);
clientDetailsManager.merge(clientDetails);
clientsUpdated += 1;
System.out.println("Client " + clientDetails.getId() + " has been updated");
} else {
System.out.println("Client " + clientDetails.getId() + " already have the " + grantType + " scope");
}
}
}
use of org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity in project ORCID-Source by ORCID.
the class OrcidSSOManagerImplTest method testGrantSSOAccessToUser.
@Test
@Rollback(true)
public void testGrantSSOAccessToUser() {
HashSet<String> uris = new HashSet<String>();
uris.add("http://1.com");
uris.add("http://2.com");
orcidSSOManager.grantSSOAccess(orcid1, "My App", "My Description", "MyWebsite", uris);
ClientDetailsEntity clientDetails = orcidSSOManager.getUserCredentials(orcid1);
assertNotNull(clientDetails);
assertNotNull(clientDetails.getAuthorizedGrantTypes());
assertTrue(clientDetails.getAuthorizedGrantTypes().contains("authorization_code"));
assertNotNull(clientDetails.getClientRegisteredRedirectUris());
assertEquals(clientDetails.getClientRegisteredRedirectUris().size(), 2);
for (ClientRedirectUriEntity redirectUri : clientDetails.getClientRegisteredRedirectUris()) {
assertTrue(redirectUri.getRedirectUri().equals("http://1.com") || redirectUri.getRedirectUri().equals("http://2.com"));
assertTrue(redirectUri.getRedirectUriType().equals(RedirectUriType.SSO_AUTHENTICATION.value()));
}
Set<ClientAuthorisedGrantTypeEntity> grantTypeList = clientDetails.getClientAuthorizedGrantTypes();
assertEquals(3, grantTypeList.size());
Set<String> grantTypes = clientDetails.getAuthorizedGrantTypes();
assertTrue(grantTypes.contains("authorization_code"));
assertTrue(grantTypes.contains("client_credentials"));
assertTrue(grantTypes.contains("refresh_token"));
List<ClientGrantedAuthorityEntity> grantedAuthList = clientDetails.getClientGrantedAuthorities();
assertEquals(1, grantedAuthList.size());
for (ClientGrantedAuthorityEntity grantedAuth : grantedAuthList) {
assertEquals(grantedAuth.getAuthority(), "ROLE_PUBLIC");
}
}
use of org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity in project ORCID-Source by ORCID.
the class ClientDetailsManagerImpl method getClientAuthorizedGrantTypes.
private Set<ClientAuthorisedGrantTypeEntity> getClientAuthorizedGrantTypes(Set<String> clientAuthorizedGrantTypes, ClientDetailsEntity clientDetailsEntity) {
Set<ClientAuthorisedGrantTypeEntity> clientAuthorisedGrantTypeEntities = new HashSet<ClientAuthorisedGrantTypeEntity>(clientAuthorizedGrantTypes.size());
for (String clientAuthorisedGrantType : clientAuthorizedGrantTypes) {
ClientAuthorisedGrantTypeEntity grantTypeEntity = new ClientAuthorisedGrantTypeEntity();
grantTypeEntity.setClientDetailsEntity(clientDetailsEntity);
grantTypeEntity.setGrantType(clientAuthorisedGrantType);
clientAuthorisedGrantTypeEntities.add(grantTypeEntity);
}
return clientAuthorisedGrantTypeEntities;
}
Aggregations