gluu
公開メンバ関数 | 限定公開メンバ関数 | 限定公開変数類 | 関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.gluu.oxtrust.service.uma.ScimUmaProtectionService クラス
org.gluu.oxtrust.service.uma.ScimUmaProtectionService の継承関係図
Inheritance graph
org.gluu.oxtrust.service.uma.ScimUmaProtectionService 連携図
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
 

非公開メンバ関数

boolean isScimEnabled ()
 
Response processTestModeAuthorization (String token) throws Exception
 

非公開変数類

Logger log
 
AppConfiguration appConfiguration
 
ApplianceService applianceService
 
JsonConfigurationService jsonConfigurationService
 
OpenIdService openIdService
 

静的非公開変数類

static final long serialVersionUID = -5447131971095468865L
 

詳解

Provides service to protect SCIM UMA Rest service endpoints

著者
Yuriy Movchan Date: 12/06/2016

関数詳解

◆ 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.ScimUmaProtectionService.getClientId ( )
inlineprotected
56  {
57  return appConfiguration.getScimUmaClientId();
58  }
AppConfiguration appConfiguration
Definition: ScimUmaProtectionService.java:45

◆ getClientKeyId()

String org.gluu.oxtrust.service.uma.ScimUmaProtectionService.getClientKeyId ( )
inlineprotected
68  {
69  return appConfiguration.getScimUmaClientKeyId();
70  }
AppConfiguration appConfiguration
Definition: ScimUmaProtectionService.java:45

◆ getClientKeyStoreFile()

String org.gluu.oxtrust.service.uma.ScimUmaProtectionService.getClientKeyStoreFile ( )
inlineprotected
64  {
65  return appConfiguration.getScimUmaClientKeyStoreFile();
66  }
AppConfiguration appConfiguration
Definition: ScimUmaProtectionService.java:45

◆ getClientKeyStorePassword()

String org.gluu.oxtrust.service.uma.ScimUmaProtectionService.getClientKeyStorePassword ( )
inlineprotected
60  {
61  return appConfiguration.getScimUmaClientKeyStorePassword();
62  }
AppConfiguration appConfiguration
Definition: ScimUmaProtectionService.java:45

◆ 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.ScimUmaProtectionService.getUmaResourceId ( )
inline
72  {
73  return appConfiguration.getScimUmaResourceId();
74  }
AppConfiguration appConfiguration
Definition: ScimUmaProtectionService.java:45

◆ getUmaScope()

String org.gluu.oxtrust.service.uma.ScimUmaProtectionService.getUmaScope ( )
inline
76  {
77  return appConfiguration.getScimUmaScope();
78  }
AppConfiguration appConfiguration
Definition: ScimUmaProtectionService.java:45

◆ isEnabled()

boolean org.gluu.oxtrust.service.uma.ScimUmaProtectionService.isEnabled ( )
inline
80  {
82  }
boolean isEnabledUmaAuthentication()
Definition: BaseUmaProtectionService.java:77
boolean isScimEnabled()
Definition: ScimUmaProtectionService.java:84

◆ 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

◆ isScimEnabled()

boolean org.gluu.oxtrust.service.uma.ScimUmaProtectionService.isScimEnabled ( )
inlineprivate
84  {
85  GluuAppliance appliance = applianceService.getAppliance();
86  GluuBoolean scimEnabled = appliance.getScimEnabled();
87 
88  return GluuBoolean.ENABLED.equals(scimEnabled) || GluuBoolean.TRUE.equals(scimEnabled);
89  }
GluuBoolean getScimEnabled()
Definition: GluuAppliance.java:502
GluuAppliance getAppliance(String[] returnAttributes)
Definition: ApplianceService.java:111
ApplianceService applianceService
Definition: ScimUmaProtectionService.java:48

◆ processAuthorization()

Response org.gluu.oxtrust.service.uma.ScimUmaProtectionService.processAuthorization ( HttpHeaders  headers,
ResourceInfo  resourceInfo 
)
inline

This method checks whether the authorization header is present and valid before scim service methods can be actually called.

引数
headersAn object holding HTTP headers
uriInfoAn object that allows access to request URI information
戻り値
A null value if the authorization was successful, otherwise a Response object is returned signaling an authorization error
99  {
100 
101  //Comment this method body if you want to skip the authorization check and proceed straight to use your SCIM service.
102  //This is useful under certain circumstances while doing development
103  //log.warn("Bypassing protection TEMPORARILY");
104 
105  Response authorizationResponse = null;
106  String authorization = headers.getHeaderString("Authorization");
107  log.info("==== SCIM Service call intercepted ====");
108  log.info("Authorization header {} found", StringUtils.isEmpty(authorization) ? "not" : "");
109 
110  try {
111  //Test mode may be removed in upcoming versions of Gluu Server...
112  if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
113  log.info("SCIM Test Mode is ACTIVE");
114  authorizationResponse = processTestModeAuthorization(authorization);
115  }
116  else
117  if (isEnabled()){
118  log.info("SCIM is protected by UMA");
119  authorizationResponse = processUmaAuthorization(authorization, resourceInfo);
120  }
121  else{
122  log.info("Please activate UMA or test mode to protect your SCIM endpoints. Read the Gluu SCIM docs to learn more");
123  authorizationResponse= getErrorResponse(Response.Status.UNAUTHORIZED, "SCIM API not protected");
124  }
125  }
126  catch (Exception e){
127  log.error(e.getMessage(), e);
128  authorizationResponse=getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
129  }
130  return authorizationResponse;
131 
132  }
AppConfiguration getOxTrustappConfiguration()
Definition: JsonConfigurationService.java:58
Logger log
Definition: ScimUmaProtectionService.java:42
boolean isEnabled()
Definition: ScimUmaProtectionService.java:80
Response processUmaAuthorization(String authorization, ResourceInfo resourceInfo)
Definition: BaseUmaProtectionService.java:151
Response getErrorResponse(Response.Status status, String detail)
Definition: BaseUmaProtectionService.java:147
Response processTestModeAuthorization(String token)
Definition: ScimUmaProtectionService.java:134
JsonConfigurationService jsonConfigurationService
Definition: ScimUmaProtectionService.java:51

◆ processTestModeAuthorization()

Response org.gluu.oxtrust.service.uma.ScimUmaProtectionService.processTestModeAuthorization ( String  token) throws Exception
inlineprivate
134  {
135 
136  Response response = null;
137 
138  if (StringUtils.isNotEmpty(token)) {
139  token=token.replaceFirst("Bearer\\s+","");
140  log.debug("Validating token {}", token);
141 
142  String clientInfoEndpoint=openIdService.getOpenIdConfiguration().getClientInfoEndpoint();
143  ClientInfoClient clientInfoClient = new ClientInfoClient(clientInfoEndpoint);
144  ClientInfoResponse clientInfoResponse = clientInfoClient.execClientInfo(token);
145 
146  if (clientInfoResponse.getErrorType()!=null) {
147  response=getErrorResponse(Response.Status.UNAUTHORIZED, "Invalid token "+ token);
148  log.debug("Error validating access token: {}", clientInfoResponse.getErrorDescription());
149  }
150  }
151  else{
152  log.info("Request is missing authorization header");
153  //see section 3.12 RFC 7644
154  response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "No authorization header found");
155  }
156  return response;
157 
158  }
Logger log
Definition: ScimUmaProtectionService.java:42
OpenIdConfigurationResponse getOpenIdConfiguration()
Definition: OpenIdService.java:66
OpenIdService openIdService
Definition: ScimUmaProtectionService.java:54
String getClientInfoEndpoint()
Definition: OpenIdConfigurationResponse.java:228
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.ScimUmaProtectionService.appConfiguration
private

◆ applianceService

ApplianceService org.gluu.oxtrust.service.uma.ScimUmaProtectionService.applianceService
private

◆ jsonConfigurationService

JsonConfigurationService org.gluu.oxtrust.service.uma.ScimUmaProtectionService.jsonConfigurationService
private

◆ log

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

◆ openIdService

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

◆ serialVersionUID

final long org.gluu.oxtrust.service.uma.ScimUmaProtectionService.serialVersionUID = -5447131971095468865L
staticprivate

◆ umaPermissionService

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

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