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

公開メンバ関数

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

限定公開メンバ関数

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

限定公開変数類

UmaPermissionService umaPermissionService
 

関数

Response processUmaAuthorization (String authorization, ResourceInfo resourceInfo) throws Exception
 

非公開メンバ関数

void retrievePatToken () throws UmaProtectionException
 
boolean isValidPatToken (Token validatePatToken, long validatePatTokenExpiration)
 
List< String > getResourceScopes (String[] scopes)
 

非公開変数類

Logger log
 
EncryptionService encryptionService
 
UmaMetadata umaMetadata
 
AppConfiguration appConfiguration
 
Token umaPat
 
long umaPatAccessTokenExpiration = 0l
 
final ReentrantLock lock = new ReentrantLock()
 

静的非公開変数類

static final long serialVersionUID = -1147131971095468865L
 

詳解

Provide base methods to simplify work with UMA Rest services

著者
Yuriy Movchan Date: 12/06/2016

関数詳解

◆ computeAccessTokenExpirationTime()

long org.gluu.oxtrust.service.uma.BaseUmaProtectionService.computeAccessTokenExpirationTime ( Integer  expiresIn)
inlineprotected
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()

abstract String org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getClientId ( )
abstractprotected

◆ getClientKeyId()

abstract String org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getClientKeyId ( )
abstractprotected

◆ getClientKeyStoreFile()

abstract String org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getClientKeyStoreFile ( )
abstractprotected

◆ getClientKeyStorePassword()

abstract String org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getClientKeyStorePassword ( )
abstractprotected

◆ getErrorResponse()

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

◆ getPatToken()

Token org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getPatToken ( ) throws UmaProtectionException
inline
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)
inline
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

◆ getResourceScopes()

List<String> org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getResourceScopes ( String []  scopes)
inlineprivate
200  {
201  List<String> result = new ArrayList<String>();
202  if ((scopes == null) || (scopes.length == 0)) {
203  return result;
204  }
205 
206  String baseEndpoint = appConfiguration.getBaseEndpoint();
207  if (baseEndpoint.endsWith("/")) {
208  baseEndpoint = baseEndpoint.substring(0, baseEndpoint.length() - 1);
209  }
210 
211  for (String scope : scopes) {
212  String umaIssuerScope = baseEndpoint + scope;
213  result.add(umaIssuerScope);
214  }
215 
216  return result;
217  }
AppConfiguration appConfiguration
Definition: BaseUmaProtectionService.java:50

◆ getUmaResourceId()

abstract String org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getUmaResourceId ( )
abstract

◆ getUmaScope()

abstract String org.gluu.oxtrust.service.uma.BaseUmaProtectionService.getUmaScope ( )
abstract

◆ isEnabled()

abstract boolean org.gluu.oxtrust.service.uma.BaseUmaProtectionService.isEnabled ( )
abstract

◆ isEnabledUmaAuthentication()

boolean org.gluu.oxtrust.service.uma.BaseUmaProtectionService.isEnabledUmaAuthentication ( )
inlineprotected
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 ( )
inline
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

◆ isValidPatToken()

boolean org.gluu.oxtrust.service.uma.BaseUmaProtectionService.isValidPatToken ( Token  validatePatToken,
long  validatePatTokenExpiration 
)
inlineprivate
139  {
140  final long now = System.currentTimeMillis();
141 
142  // Get new access token only if is the previous one is missing or expired
143  return !((validatePatToken == null) || (validatePatToken.getAccessToken() == null) ||
144  (validatePatTokenExpiration <= now));
145  }

◆ processAuthorization()

abstract Response org.gluu.oxtrust.service.uma.BaseUmaProtectionService.processAuthorization ( HttpHeaders  headers,
ResourceInfo  resourceInfo 
)
abstract

◆ processUmaAuthorization()

Response org.gluu.oxtrust.service.uma.BaseUmaProtectionService.processUmaAuthorization ( String  authorization,
ResourceInfo  resourceInfo 
) throws Exception
inlinepackage
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

◆ retrievePatToken()

void org.gluu.oxtrust.service.uma.BaseUmaProtectionService.retrievePatToken ( ) throws UmaProtectionException
inlineprivate
91  {
92  this.umaPat = null;
93  if (umaMetadata == null) {
94  return;
95  }
96 
97  String umaClientKeyStoreFile = getClientKeyStoreFile();
98  String umaClientKeyStorePassword = getClientKeyStorePassword();
99  if (StringHelper.isEmpty(umaClientKeyStoreFile) || StringHelper.isEmpty(umaClientKeyStorePassword)) {
100  throw new UmaProtectionException("UMA JKS keystore path or password is empty");
101  }
102 
103  if (umaClientKeyStorePassword != null) {
104  try {
105  umaClientKeyStorePassword = encryptionService.decrypt(umaClientKeyStorePassword);
106  } catch (EncryptionException ex) {
107  log.error("Failed to decrypt UmaClientKeyStorePassword password", ex);
108  }
109  }
110 
111 
112  try {
113  this.umaPat = UmaClient.requestPat(umaMetadata.getTokenEndpoint(), umaClientKeyStoreFile, umaClientKeyStorePassword, getClientId(), getClientKeyId());
114  if (this.umaPat == null) {
115  this.umaPatAccessTokenExpiration = 0l;
116  } else {
118  }
119  } catch (Exception ex) {
120  throw new UmaProtectionException("Failed to obtain valid UMA PAT token", ex);
121  }
122 
123  if ((this.umaPat == null) || (this.umaPat.getAccessToken() == null)) {
124  throw new UmaProtectionException("Failed to obtain valid UMA PAT token");
125  }
126  }
String decrypt(String encryptedString)
Definition: EncryptionService.java:34
Integer getExpiresIn()
Definition: Token.java:81
EncryptionService encryptionService
Definition: BaseUmaProtectionService.java:41
Token umaPat
Definition: BaseUmaProtectionService.java:52
long computeAccessTokenExpirationTime(Integer expiresIn)
Definition: BaseUmaProtectionService.java:128
Logger log
Definition: BaseUmaProtectionService.java:38
String getTokenEndpoint()
Definition: OAuth2Discovery.java:170
long umaPatAccessTokenExpiration
Definition: BaseUmaProtectionService.java:53
String getAccessToken()
Definition: Token.java:54
UmaMetadata umaMetadata
Definition: BaseUmaProtectionService.java:44

メンバ詳解

◆ appConfiguration

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

◆ encryptionService

EncryptionService org.gluu.oxtrust.service.uma.BaseUmaProtectionService.encryptionService
private

◆ lock

final ReentrantLock org.gluu.oxtrust.service.uma.BaseUmaProtectionService.lock = new ReentrantLock()
private

◆ log

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

◆ serialVersionUID

final long org.gluu.oxtrust.service.uma.BaseUmaProtectionService.serialVersionUID = -1147131971095468865L
staticprivate

◆ umaMetadata

UmaMetadata org.gluu.oxtrust.service.uma.BaseUmaProtectionService.umaMetadata
private

◆ umaPat

Token org.gluu.oxtrust.service.uma.BaseUmaProtectionService.umaPat
private

◆ umaPatAccessTokenExpiration

long org.gluu.oxtrust.service.uma.BaseUmaProtectionService.umaPatAccessTokenExpiration = 0l
private

◆ umaPermissionService

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

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