Skip to content

Commit a3fad31

Browse files
author
Kousuke Ebihara
committed
added the opCheckAllowedAccessWebAPI filter to authenticate using OAuth or IP limitation
1 parent 8907bbb commit a3fad31

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

apps/api/modules/feeds/actions/actions.class.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class feedsActions extends sfActions
1919
{
2020
public function preExecute()
2121
{
22-
$list = Doctrine::getTable('SnsConfig')->get('op_web_api_plugin_ip_list', '127.0.0.1');
23-
$this->forward404Unless(in_array(@$_SERVER['REMOTE_ADDR'], explode("\n", $list)));
24-
2522
$this->getResponse()->setHttpHeader('Content-Type', 'application/atom+xml');
2623

2724
$request = sfContext::getInstance()->getRequest();

apps/api/modules/feeds/config/filters.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
rendering: ~
22

33
check_oauth:
4-
class: opCheckOAuthAccessTokenFilter
4+
class: opCheckAllowedAccessWebAPI
55

66
security: ~
77

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the OpenPNE package.
5+
* (c) OpenPNE Project (http://www.openpne.jp/)
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file and the NOTICE file that were distributed with this source code.
9+
*/
10+
11+
/**
12+
* opCheckAllowedAccessWebAPI
13+
*
14+
* @package OpenPNE
15+
* @subpackage filter
16+
* @author Kousuke Ebihara <[email protected]>
17+
*/
18+
class opCheckAllowedAccessWebAPI extends opCheckOAuthAccessTokenFilter
19+
{
20+
public function execute($filterChain)
21+
{
22+
if (Doctrine::getTable('SnsConfig')->get('op_web_api_plugin_is_limit_ip', false))
23+
{
24+
$list = Doctrine::getTable('SnsConfig')->get('op_web_api_plugin_ip_list', '127.0.0.1');
25+
if (in_array(@$_SERVER['REMOTE_ADDR'], explode("\n", $list)))
26+
{
27+
sfContext::getInstance()->getUser()->setAuthenticated(true);
28+
}
29+
30+
$filterChain->execute();
31+
}
32+
else
33+
{
34+
parent::execute($filterChain);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)