OAuth2AuthorizationServerImpl.java
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.jackrabbit.api.security.user.Authorizable
* org.apache.sling.jcr.api.SlingRepository
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.oauth.server.impl;
import com.adobe.granite.oauth.server.OAuth2AuthorizationServer;
import com.adobe.granite.oauth.server.impl.helper.OAuth2Helper;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service
@Component(metatype=0)
public class OAuth2AuthorizationServerImpl
implements OAuth2AuthorizationServer {
private final Logger logger;
@Reference
private SlingRepository repository;
public OAuth2AuthorizationServerImpl() {
this.logger = LoggerFactory.getLogger(this.getClass());
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public String getClientName(String clientId) {
Session oauthServiceSession = null;
try {
oauthServiceSession = this.repository.loginService(null, null);
Authorizable user = OAuth2Helper.getOAuthClientAuthorizable(oauthServiceSession, clientId);
if (user != null) {
String string = OAuth2Helper.getOAuthClientPropertyValue(user, clientId, "oauth:clientName");
return string;
}
this.logger.debug("getClientName: Invalid value {} for parameter client_id", (Object)clientId);
String string = null;
return string;
}
catch (Exception e) {
this.logger.error("exception while retrieving clientId, returning clientID ", (Throwable)e);
String string = null;
return string;
}
finally {
if (oauthServiceSession != null) {
oauthServiceSession.logout();
}
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
}