use of org.orcid.jaxb.model.clientgroup.ClientType in project ORCID-Source by ORCID.
the class SetUpClientsAndUsers method createClient.
private void createClient(Map<String, String> params) {
Set<String> clientResourceIds = new HashSet<String>();
clientResourceIds.add("orcid");
Set<String> clientAuthorizedGrantTypes = new HashSet<String>();
clientAuthorizedGrantTypes.add("client_credentials");
clientAuthorizedGrantTypes.add("authorization_code");
clientAuthorizedGrantTypes.add("refresh_token");
ClientType clientType = ClientType.PREMIUM_CREATOR;
if (params.containsKey(CLIENT_TYPE)) {
clientType = ClientType.fromValue(params.get(CLIENT_TYPE));
}
Set<RedirectUri> redirectUrisToAdd = new HashSet<RedirectUri>();
RedirectUri redirectUri = new RedirectUri(params.get(REDIRECT_URI));
if (clientType.equals(ClientType.PUBLIC_CLIENT)) {
redirectUri.setType(RedirectUriType.SSO_AUTHENTICATION);
} else {
redirectUri.setType(RedirectUriType.DEFAULT);
}
redirectUrisToAdd.add(redirectUri);
List<String> clientGrantedAuthorities = new ArrayList<String>();
clientGrantedAuthorities.add("ROLE_CLIENT");
String name = params.get(CLIENT_NAME);
String description = params.get(CLIENT_DESCRIPTION);
String website = params.get(CLIENT_WEBSITE);
String clientId = params.get(CLIENT_ID);
String clientSecret = encryptionManager.encryptForInternalUse(params.get(CLIENT_SECRET));
String memberId = params.get(MEMBER_ID);
Set<String> scopes = null;
if (clientType.equals(ClientType.PUBLIC_CLIENT)) {
scopes = new HashSet<String>(Arrays.asList(ScopePathType.AUTHENTICATE.value(), ScopePathType.READ_PUBLIC.value()));
} else {
scopes = orcidClientGroupManager.premiumCreatorScopes();
if (params.containsKey(ADD_ORCID_INTERNAL_SCOPES)) {
scopes.add(ScopePathType.INTERNAL_PERSON_LAST_MODIFIED.value());
}
//Add scopes to allow group read and update
scopes.add(ScopePathType.GROUP_ID_RECORD_READ.value());
scopes.add(ScopePathType.GROUP_ID_RECORD_UPDATE.value());
//Add notifications scope
scopes.add(ScopePathType.PREMIUM_NOTIFICATION.value());
//Add openid scope
scopes.add(ScopePathType.OPENID.value());
}
clientDetailsManager.populateClientDetailsEntity(clientId, memberId, name, description, null, website, clientSecret, clientType, scopes, clientResourceIds, clientAuthorizedGrantTypes, redirectUrisToAdd, clientGrantedAuthorities, true);
}
use of org.orcid.jaxb.model.clientgroup.ClientType in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method updateClientTypeDueGroupTypeUpdate.
/**
* Updates the client type and client scopes of all clients that belongs to
* the given group
*
* @param groupProfileEntity
* the group profile
*/
@Transactional
private void updateClientTypeDueGroupTypeUpdate(ProfileEntity groupProfileEntity) {
Set<ClientDetailsEntity> clients = groupProfileEntity.getClients();
ClientType clientType = this.getClientType(groupProfileEntity.getGroupType());
for (ClientDetailsEntity client : clients) {
Set<String> newSetOfScopes = this.createScopes(clientType);
Set<ClientScopeEntity> existingScopes = client.getClientScopes();
Iterator<ClientScopeEntity> scopesIterator = existingScopes.iterator();
while (scopesIterator.hasNext()) {
ClientScopeEntity clientScopeEntity = scopesIterator.next();
if (newSetOfScopes.contains(clientScopeEntity.getScopeType())) {
newSetOfScopes.remove(clientScopeEntity.getScopeType());
} else {
clientScopeDao.deleteScope(client.getClientId(), clientScopeEntity.getScopeType());
}
}
// Insert the new scopes
for (String newScope : newSetOfScopes) {
ClientScopeEntity clientScopeEntity = new ClientScopeEntity();
clientScopeEntity.setClientDetailsEntity(client);
clientScopeEntity.setScopeType(newScope);
clientScopeEntity.setDateCreated(new Date());
clientScopeEntity.setLastModified(new Date());
clientScopeDao.persist(clientScopeEntity);
}
// Update client type
clientDetailsDao.updateClientType(clientType, client.getClientId());
// Update last modified
clientDetailsDao.updateLastModified(client.getClientId());
}
}
Aggregations