Skip to content

Commit 98b35bf

Browse files
committed
Delete token web script
1 parent 8d2425c commit 98b35bf

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.sharextras.oauth.repo.webscripts;
2+
3+
import java.io.IOException;
4+
5+
import org.alfresco.service.cmr.oauth2.OAuth2CredentialsStoreService;
6+
import org.springframework.extensions.webscripts.AbstractWebScript;
7+
import org.springframework.extensions.webscripts.Status;
8+
import org.springframework.extensions.webscripts.WebScriptException;
9+
import org.springframework.extensions.webscripts.WebScriptRequest;
10+
import org.springframework.extensions.webscripts.WebScriptResponse;
11+
12+
/**
13+
* Delete an OAuth 2.0 ticket from the credentials store.
14+
*
15+
* @author Will Abson
16+
*/
17+
public class DeleteOAuthToken extends AbstractWebScript
18+
{
19+
20+
// Services
21+
private OAuth2CredentialsStoreService oauth2CredentialsStoreService;
22+
23+
public void setOauth2CredentialsStoreService(OAuth2CredentialsStoreService oauth2CredentialsStoreService)
24+
{
25+
this.oauth2CredentialsStoreService = oauth2CredentialsStoreService;
26+
}
27+
28+
@Override
29+
public void execute(WebScriptRequest req, WebScriptResponse resp)
30+
throws IOException
31+
{
32+
String keyName = req.getServiceMatch().getTemplateVars().get("name");
33+
34+
if (keyName == null || "".equals(keyName))
35+
{
36+
throw new WebScriptException("A key name must be specified");
37+
}
38+
39+
boolean result = oauth2CredentialsStoreService.deletePersonalOAuth2Credentials(keyName);
40+
41+
if (!result)
42+
{
43+
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Could not find credentials with name " + keyName);
44+
}
45+
}
46+
47+
}

share-oauth-repo/src/main/resources/alfresco/extension/tokenstore-webscripts-context.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@
1616
</property>
1717
</bean>
1818

19+
<bean id="webscript.org.sharextras.slingshot.oauth.oauth-token.delete"
20+
class="org.sharextras.oauth.repo.webscripts.DeleteOAuthToken" parent="webscript">
21+
<property name="oauth2CredentialsStoreService">
22+
<ref bean="oauth2CredentialsStoreService" />
23+
</property>
24+
</bean>
25+
1926
</beans>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<webscript>
2+
<shortname>OAuth2-delete-token</shortname>
3+
<description>Script to delete an OAuth 2.0 token</description>
4+
<url>/extras/oauth2/token/{name}</url>
5+
<authentication>user</authentication>
6+
<format default="json">any</format>
7+
</webscript>

0 commit comments

Comments
 (0)