001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.oauth;
016    
017    import com.liferay.portal.kernel.oauth.OAuthException;
018    import com.liferay.portal.kernel.oauth.OAuthFactory;
019    import com.liferay.portal.kernel.oauth.OAuthManager;
020    import com.liferay.portal.kernel.oauth.OAuthRequest;
021    import com.liferay.portal.kernel.oauth.Token;
022    import com.liferay.portal.kernel.oauth.Verb;
023    import com.liferay.portal.kernel.oauth.Verifier;
024    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    @DoPrivileged
030    public class OAuthFactoryImpl implements OAuthFactory {
031    
032            public OAuthManager createOAuthManager(
033                            String key, String secret, String accessURL, String requestURL,
034                            String callbackURL, String scope)
035                    throws OAuthException {
036    
037                    try {
038                            return new OAuthManagerImpl(
039                                    key, secret, accessURL, requestURL, callbackURL, scope);
040                    }
041                    catch (Exception e) {
042                            throw new OAuthException(e);
043                    }
044            }
045    
046            public OAuthRequest createOAuthRequest(Verb verb, String url)
047                    throws OAuthException {
048    
049                    try {
050                            return new OAuthRequestImpl(
051                                    new org.scribe.model.OAuthRequest(
052                                            VerbTranslator.translate(verb), url));
053                    }
054                    catch (Exception e) {
055                            throw new OAuthException(e);
056                    }
057            }
058    
059            public Token createToken(String token, String secret)
060                    throws OAuthException {
061    
062                    try {
063                            return new TokenImpl(new org.scribe.model.Token(token, secret));
064                    }
065                    catch (Exception e) {
066                            throw new OAuthException(e);
067                    }
068            }
069    
070            public Verifier createVerifier(String verifier) throws OAuthException {
071                    try {
072                            return new VerifierImpl(new org.scribe.model.Verifier(verifier));
073                    }
074                    catch (Exception e) {
075                            throw new OAuthException(e);
076                    }
077            }
078    
079    }