gluu
公開メンバ関数 | 限定公開メンバ関数 | 限定公開変数類 | 関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.gluu.oxtrust.service.uma.ApiUmaProtectionService クラス
org.gluu.oxtrust.service.uma.ApiUmaProtectionService の継承関係図
Inheritance graph
org.gluu.oxtrust.service.uma.ApiUmaProtectionService 連携図
Collaboration graph

公開メンバ関数

String getUmaResourceId ()
 
String getUmaScope ()
 
boolean isEnabled ()
 
Response processAuthorization (HttpHeaders headers, ResourceInfo resourceInfo)
 
Token getPatToken () throws UmaProtectionException
 
boolean isExistPatToken ()
 
List< String > getRequestedScopes (ResourceInfo resourceInfo)
 

限定公開メンバ関数

String getClientId ()
 
String getClientKeyStorePassword ()
 
String getClientKeyStoreFile ()
 
String getClientKeyId ()
 
boolean isEnabledUmaAuthentication ()
 
long computeAccessTokenExpirationTime (Integer expiresIn)
 
Response getErrorResponse (Response.Status status, String detail)
 

限定公開変数類

UmaPermissionService umaPermissionService
 

関数

Response processUmaAuthorization (String authorization, ResourceInfo resourceInfo) throws Exception
 

非公開メンバ関数

Response processTestModeAuthorization (String token) throws Exception
 

非公開変数類

Logger log
 
AppConfiguration appConfiguration
 
OpenIdService openIdService
 

静的非公開変数類

static final long serialVersionUID = 362749692619005003L
 

詳解

Provides service to protect APIs Rest service endpoints with UMA scope.

著者
Dmitry Ognyannikov

関数詳解

◆ computeAccessTokenExpirationTime()

long org.gluu.oxtrust.service.uma.BaseUmaProtectionService.computeAccessTokenExpirationTime ( Integer  expiresIn)
inlineprotectedinherited
128  {
129  // Compute "accessToken" expiration timestamp
130  Calendar calendar = Calendar.getInstance();
131  if (expiresIn != null) {
132  calendar.add(Calendar.SECOND, expiresIn);
133  calendar.add(Calendar.SECOND, -10); // Subtract 10 seconds to avoid expirations during executing request
134  }
135 
136  return calendar.getTimeInMillis();
137  }

◆ getClientId()

String org.gluu.oxtrust.service.uma.ApiUmaProtectionService.getClientId ( )
inlineprotected
47  {
48  return appConfiguration.getApiUmaClientId();
49  }
AppConfiguration appConfiguration
Definition: ApiUmaProtectionService.java:41

◆ getClientKeyId()

String org.gluu.oxtrust.service.uma.ApiUmaProtectionService.getClientKeyId ( )
inlineprotected
62  {
63  return appConfiguration.getApiUmaClientKeyId();
64  }
AppConfiguration appConfiguration
Definition: ApiUmaProtectionService.java:41

◆ getClientKeyStoreFile()

String org.gluu.oxtrust.service.uma.ApiUmaProtectionService.getClientKeyStoreFile ( )
inlineprotected
57  {
58  return appConfiguration.getApiUmaClientKeyStoreFile();
59  }
AppConfiguration appConfiguration
Definition: ApiUmaProtectionService.java:41

◆ getClientKeyStorePassword()

String org.gluu.oxtrust.service.uma.ApiUmaProtectionService.getClientKeyStorePassword ( )
inlineprotected
52  {
53  return appConfiguration.getApiUmaClientKeyStorePassword();
54  }
AppConfiguration appConfiguration
Definition: ApiUmaProtectionService.java:41

◆ getErrorResponse()

Response org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getErrorResponse ( Response.Status  status,
String  detail 
)
inlineprotectedinherited
147  {
148  return Response.status(status).entity(detail).build();
149  }

◆ getPatToken()

Token org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getPatToken ( ) throws UmaProtectionException
inlineinherited
57  {
59  return this.umaPat;
60  }
61 
62  lock.lock();
63  try {
65  return this.umaPat;
66  }
67 
69  } finally {
70  lock.unlock();
71  }
72 
73 
74  return this.umaPat;
75  }
final ReentrantLock lock
Definition: BaseUmaProtectionService.java:55
Token umaPat
Definition: BaseUmaProtectionService.java:52
boolean isValidPatToken(Token validatePatToken, long validatePatTokenExpiration)
Definition: BaseUmaProtectionService.java:139
long umaPatAccessTokenExpiration
Definition: BaseUmaProtectionService.java:53
void retrievePatToken()
Definition: BaseUmaProtectionService.java:91

◆ getRequestedScopes()

List<String> org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getRequestedScopes ( ResourceInfo  resourceInfo)
inlineinherited
181  {
182  Class<?> resourceClass = resourceInfo.getResourceClass();
183  ProtectedApi typeAnnotation = resourceClass.getAnnotation(ProtectedApi.class);
184  if (typeAnnotation == null) {
185  return Collections.emptyList();
186  }
187 
188  List<String> scopes = new ArrayList<String>();
189  scopes.addAll(getResourceScopes(typeAnnotation.scopes()));
190 
191  Method resourceMethod = resourceInfo.getResourceMethod();
192  ProtectedApi methodAnnotation = resourceMethod.getAnnotation(ProtectedApi.class);
193  if (methodAnnotation != null) {
194  scopes.addAll(getResourceScopes(methodAnnotation.scopes()));
195  }
196 
197  return scopes;
198  }
List< String > getResourceScopes(String[] scopes)
Definition: BaseUmaProtectionService.java:200

◆ getUmaResourceId()

String org.gluu.oxtrust.service.uma.ApiUmaProtectionService.getUmaResourceId ( )
inline
67  {
68  return appConfiguration.getApiUmaResourceId();
69  }
AppConfiguration appConfiguration
Definition: ApiUmaProtectionService.java:41

◆ getUmaScope()

String org.gluu.oxtrust.service.uma.ApiUmaProtectionService.getUmaScope ( )
inline
72  {
73  return appConfiguration.getApiUmaScope();
74  }
AppConfiguration appConfiguration
Definition: ApiUmaProtectionService.java:41

◆ isEnabled()

boolean org.gluu.oxtrust.service.uma.ApiUmaProtectionService.isEnabled ( )
inline
77  {
79  }
boolean isEnabledUmaAuthentication()
Definition: BaseUmaProtectionService.java:77

◆ isEnabledUmaAuthentication()

boolean org.gluu.oxtrust.service.uma.BaseUmaProtectionService.isEnabledUmaAuthentication ( )
inlineprotectedinherited
77  {
78  return (umaMetadata != null) && isExistPatToken();
79  }
boolean isExistPatToken()
Definition: BaseUmaProtectionService.java:81
UmaMetadata umaMetadata
Definition: BaseUmaProtectionService.java:44

◆ isExistPatToken()

boolean org.gluu.oxtrust.service.uma.BaseUmaProtectionService.isExistPatToken ( )
inlineinherited
81  {
82  try {
83  return getPatToken() != null;
84  } catch (UmaProtectionException ex) {
85  log.error("Failed to check UMA PAT token status", ex);
86  }
87 
88  return false;
89  }
Logger log
Definition: BaseUmaProtectionService.java:38
Token getPatToken()
Definition: BaseUmaProtectionService.java:57

◆ processAuthorization()

Response org.gluu.oxtrust.service.uma.ApiUmaProtectionService.processAuthorization ( HttpHeaders  headers,
ResourceInfo  resourceInfo 
)
inline
82  {
83  Response authorizationResponse = null;
84 
85  String authorization = headers.getHeaderString("Authorization");
86  log.info("==== API Service call intercepted ====");
87  log.info("Authorization header {} found", StringUtils.isEmpty(authorization) ? "not" : "");
88 
89  try {
90  //Test mode may be removed in upcoming versions of Gluu Server...
91  if (appConfiguration.isScimTestMode()) {
92  log.info("API Test Mode is ACTIVE");
93  authorizationResponse = processTestModeAuthorization(authorization);
94  }
95  else
96  if (isEnabled()){
97  log.info("API is protected by UMA");
98  authorizationResponse = processUmaAuthorization(authorization, resourceInfo);
99  }
100  else{
101  log.info("Please activate UMA or test mode to protect your API endpoints. Read the Gluu API docs to learn more");
102  authorizationResponse= getErrorResponse(Response.Status.UNAUTHORIZED, "API not protected");
103  }
104  }
105  catch (Exception e){
106  log.error(e.getMessage(), e);
107  authorizationResponse=getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
108  }
109 
110  return authorizationResponse;
111  }
Response processTestModeAuthorization(String token)
Definition: ApiUmaProtectionService.java:113
Response processUmaAuthorization(String authorization, ResourceInfo resourceInfo)
Definition: BaseUmaProtectionService.java:151
Logger log
Definition: ApiUmaProtectionService.java:38
Response getErrorResponse(Response.Status status, String detail)
Definition: BaseUmaProtectionService.java:147
boolean isEnabled()
Definition: ApiUmaProtectionService.java:77
AppConfiguration appConfiguration
Definition: ApiUmaProtectionService.java:41

◆ processTestModeAuthorization()

Response org.gluu.oxtrust.service.uma.ApiUmaProtectionService.processTestModeAuthorization ( String  token) throws Exception
inlineprivate
113  {
114  Response response = null;
115 
116  if (StringUtils.isNotEmpty(token)) {
117  token = token.replaceFirst("Bearer\\s+", "");
118  log.debug("Validating token {}", token);
119 
120  String clientInfoEndpoint = openIdService.getOpenIdConfiguration().getClientInfoEndpoint();
121  ClientInfoClient clientInfoClient = new ClientInfoClient(clientInfoEndpoint);
122  ClientInfoResponse clientInfoResponse = clientInfoClient.execClientInfo(token);
123 
124  if (clientInfoResponse.getErrorType() != null) {
125  response = getErrorResponse(Status.UNAUTHORIZED, "Invalid token " + token);
126  log.debug("Error validating access token: {}", clientInfoResponse.getErrorDescription());
127  }
128  } else {
129  log.info("Request is missing authorization header");
130  // see section 3.12 RFC 7644
131  response = getErrorResponse(Status.INTERNAL_SERVER_ERROR, "No authorization header found");
132  }
133  return response;
134 
135  }
OpenIdConfigurationResponse getOpenIdConfiguration()
Definition: OpenIdService.java:66
String getClientInfoEndpoint()
Definition: OpenIdConfigurationResponse.java:228
Logger log
Definition: ApiUmaProtectionService.java:38
OpenIdService openIdService
Definition: ApiUmaProtectionService.java:44
Response getErrorResponse(Response.Status status, String detail)
Definition: BaseUmaProtectionService.java:147

◆ processUmaAuthorization()

Response org.gluu.oxtrust.service.uma.BaseUmaProtectionService.processUmaAuthorization ( String  authorization,
ResourceInfo  resourceInfo 
) throws Exception
inlinepackageinherited
151  {
152  List<String> scopes = getRequestedScopes(resourceInfo);
153 
154  Token patToken = null;
155  try {
156  patToken = getPatToken();
157  }
158  catch (UmaProtectionException ex) {
159  return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Failed to obtain PAT token");
160  }
161 
162  Pair<Boolean, Response> rptTokenValidationResult;
163  if (scopes.isEmpty()) {
164  rptTokenValidationResult = umaPermissionService.validateRptToken(patToken, authorization, getUmaResourceId(), scopes);
165  } else {
166  rptTokenValidationResult = umaPermissionService.validateRptToken(patToken, authorization, getUmaResourceId(), getUmaScope());
167  }
168 
169  if (rptTokenValidationResult.getFirst()) {
170  if (rptTokenValidationResult.getSecond() != null) {
171  return rptTokenValidationResult.getSecond();
172  }
173  }
174  else {
175  return getErrorResponse(Response.Status.UNAUTHORIZED, "Invalid GAT/RPT token");
176  }
177  return null;
178 
179  }
UmaPermissionService umaPermissionService
Definition: BaseUmaProtectionService.java:47
Token getPatToken()
Definition: BaseUmaProtectionService.java:57
Response getErrorResponse(Response.Status status, String detail)
Definition: BaseUmaProtectionService.java:147
List< String > getRequestedScopes(ResourceInfo resourceInfo)
Definition: BaseUmaProtectionService.java:181
Pair< Boolean, Response > validateRptToken(Token patToken, String authorization, String umaResourceId, String scopeId)
Definition: UmaPermissionService.java:105

メンバ詳解

◆ appConfiguration

AppConfiguration org.gluu.oxtrust.service.uma.ApiUmaProtectionService.appConfiguration
private

◆ log

Logger org.gluu.oxtrust.service.uma.ApiUmaProtectionService.log
private

◆ openIdService

OpenIdService org.gluu.oxtrust.service.uma.ApiUmaProtectionService.openIdService
private

◆ serialVersionUID

final long org.gluu.oxtrust.service.uma.ApiUmaProtectionService.serialVersionUID = 362749692619005003L
staticprivate

◆ umaPermissionService

UmaPermissionService org.gluu.oxtrust.service.uma.BaseUmaProtectionService.umaPermissionService
protectedinherited

このクラス詳解は次のファイルから抽出されました: