001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * Contributors: 014 * Thomas Roger <troger@nuxeo.com> 015 */ 016 017package org.nuxeo.ecm.user.center; 018 019import static org.jboss.seam.ScopeType.CONVERSATION; 020 021import java.io.Serializable; 022import java.util.Collections; 023import java.util.HashMap; 024import java.util.List; 025import java.util.Map; 026import java.util.Set; 027 028import org.jboss.seam.annotations.In; 029import org.jboss.seam.annotations.Name; 030import org.jboss.seam.annotations.Scope; 031import org.nuxeo.ecm.core.api.DocumentModel; 032import org.nuxeo.ecm.core.api.NuxeoPrincipal; 033import org.nuxeo.ecm.directory.Session; 034import org.nuxeo.ecm.directory.api.DirectoryService; 035import org.nuxeo.ecm.platform.oauth.tokens.OAuthTokenStoreImpl; 036import org.nuxeo.runtime.api.Framework; 037 038/** 039 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 040 */ 041@Name("authorizedApplicationsActions") 042@Scope(CONVERSATION) 043public class AuthorizedApplicationsActions implements Serializable { 044 045 private static final long serialVersionUID = 1L; 046 047 @In 048 protected NuxeoPrincipal currentUser; 049 050 public List<DocumentModel> getAuthorizedApplications() { 051 DirectoryService directoryService = Framework.getService(DirectoryService.class); 052 try (Session session = directoryService.open(OAuthTokenStoreImpl.DIRECTORY_NAME)) { 053 Map<String, Serializable> queryFilter = getQueryFilter(); 054 Set<String> emptySet = Collections.emptySet(); 055 return session.query(queryFilter, emptySet, null, true); 056 } 057 } 058 059 protected Map<String, Serializable> getQueryFilter() { 060 Map<String, Serializable> filter = new HashMap<String, Serializable>(); 061 filter.put("clientToken", new Integer(0)); 062 filter.put("nuxeoLogin", currentUser.getName()); 063 return filter; 064 } 065 066 public void revokeAccess(String id) { 067 DirectoryService directoryService = Framework.getService(DirectoryService.class); 068 try (Session session = directoryService.open(OAuthTokenStoreImpl.DIRECTORY_NAME)) { 069 session.deleteEntry(id); 070 } 071 } 072 073}