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            @Override
033            public OAuthManager createOAuthManager(
034                            String key, String secret, String accessURL, String requestURL,
035                            String callbackURL, String scope)
036                    throws OAuthException {
037    
038                    try {
039                            return new OAuthManagerImpl(
040                                    key, secret, accessURL, requestURL, callbackURL, scope);
041                    }
042                    catch (Exception e) {
043                            throw new OAuthException(e);
044                    }
045            }
046    
047            @Override
048            public OAuthRequest createOAuthRequest(Verb verb, String url)
049                    throws OAuthException {
050    
051                    try {
052                            return new OAuthRequestImpl(
053                                    new org.scribe.model.OAuthRequest(
054                                            VerbTranslator.translate(verb), url));
055                    }
056                    catch (Exception e) {
057                            throw new OAuthException(e);
058                    }
059            }
060    
061            @Override
062            public Token createToken(String token, String secret)
063                    throws OAuthException {
064    
065                    try {
066                            return new TokenImpl(new org.scribe.model.Token(token, secret));
067                    }
068                    catch (Exception e) {
069                            throw new OAuthException(e);
070                    }
071            }
072    
073            @Override
074            public Verifier createVerifier(String verifier) throws OAuthException {
075                    try {
076                            return new VerifierImpl(new org.scribe.model.Verifier(verifier));
077                    }
078                    catch (Exception e) {
079                            throw new OAuthException(e);
080                    }
081            }
082    
083    }