001    /**
002     * Copyright (c) 2000-2012 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    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class OAuthFactoryImpl implements OAuthFactory {
029    
030            public OAuthManager createOAuthManager(
031                            String key, String secret, String accessURL, String requestURL,
032                            String callbackURL, String scope)
033                    throws OAuthException {
034    
035                    try {
036                            return new OAuthManagerImpl(
037                                    key, secret, accessURL, requestURL, callbackURL, scope);
038                    }
039                    catch (Exception e) {
040                            throw new OAuthException(e);
041                    }
042            }
043    
044            public OAuthRequest createOAuthRequest(Verb verb, String url)
045                    throws OAuthException {
046    
047                    try {
048                            return new OAuthRequestImpl(
049                                    new org.scribe.model.OAuthRequest(
050                                            VerbTranslator.translate(verb), url));
051                    }
052                    catch (Exception e) {
053                            throw new OAuthException(e);
054                    }
055            }
056    
057            public Token createToken(String token, String secret)
058                    throws OAuthException {
059    
060                    try {
061                            return new TokenImpl(new org.scribe.model.Token(token, secret));
062                    }
063                    catch (Exception e) {
064                            throw new OAuthException(e);
065                    }
066            }
067    
068            public Verifier createVerifier(String verifier) throws OAuthException {
069                    try {
070                            return new VerifierImpl(new org.scribe.model.Verifier(verifier));
071                    }
072                    catch (Exception e) {
073                            throw new OAuthException(e);
074                    }
075            }
076    
077    }