mitreid-connect
公開メンバ関数 | 静的公開変数類 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.mitre.oauth2.web.IntrospectionEndpoint クラス
org.mitre.oauth2.web.IntrospectionEndpoint 連携図
Collaboration graph

公開メンバ関数

 IntrospectionEndpoint ()
 
 IntrospectionEndpoint (OAuth2TokenEntityService tokenServices)
 
String verify (@RequestParam("token") String tokenValue, @RequestParam(value="token_type_hint", required=false) String tokenType, Authentication auth, Model model)
 

静的公開変数類

static final String URL = "introspect"
 

非公開変数類

OAuth2TokenEntityService tokenServices
 
ClientDetailsEntityService clientService
 
IntrospectionResultAssembler introspectionResultAssembler
 
UserInfoService userInfoService
 
ResourceSetService resourceSetService
 

静的非公開変数類

static final Logger logger = LoggerFactory.getLogger(IntrospectionEndpoint.class)
 

詳解

構築子と解体子

◆ IntrospectionEndpoint() [1/2]

org.mitre.oauth2.web.IntrospectionEndpoint.IntrospectionEndpoint ( )
inline
83  {
84 
85  }

◆ IntrospectionEndpoint() [2/2]

org.mitre.oauth2.web.IntrospectionEndpoint.IntrospectionEndpoint ( OAuth2TokenEntityService  tokenServices)
inline
87  {
89  }
OAuth2TokenEntityService tokenServices
Definition: IntrospectionEndpoint.java:64

関数詳解

◆ verify()

String org.mitre.oauth2.web.IntrospectionEndpoint.verify ( @RequestParam("token") String  tokenValue,
@RequestParam(value="token_type_hint", required=false) String  tokenType,
Authentication  auth,
Model  model 
)
inline
94  {
95 
96  ClientDetailsEntity authClient = null;
97  Set<String> authScopes = new HashSet<>();
98 
99  if (auth instanceof OAuth2Authentication) {
100  // the client authenticated with OAuth, do our UMA checks
101  ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE);
102 
103  // get out the client that was issued the access token (not the token being introspected)
104  OAuth2Authentication o2a = (OAuth2Authentication) auth;
105 
106  String authClientId = o2a.getOAuth2Request().getClientId();
107  authClient = clientService.loadClientByClientId(authClientId);
108 
109  // the owner is the user who authorized the token in the first place
110  String ownerId = o2a.getUserAuthentication().getName();
111 
112  authScopes.addAll(authClient.getScope());
113 
114  // UMA style clients also get a subset of scopes of all the resource sets they've registered
115  Collection<ResourceSet> resourceSets = resourceSetService.getAllForOwnerAndClient(ownerId, authClientId);
116 
117  // collect all the scopes
118  for (ResourceSet rs : resourceSets) {
119  authScopes.addAll(rs.getScopes());
120  }
121 
122  } else {
123  // the client authenticated directly, make sure it's got the right access
124 
125  String authClientId = auth.getName(); // direct authentication puts the client_id into the authentication's name field
126  authClient = clientService.loadClientByClientId(authClientId);
127 
128  // directly authenticated clients get a subset of any scopes that they've registered for
129  authScopes.addAll(authClient.getScope());
130 
131  if (!AuthenticationUtilities.hasRole(auth, "ROLE_CLIENT")
132  || !authClient.isAllowIntrospection()) {
133 
134  // this client isn't allowed to do direct introspection
135 
136  logger.error("Client " + authClient.getClientId() + " is not allowed to call introspection endpoint");
137  model.addAttribute("code", HttpStatus.FORBIDDEN);
138  return HttpCodeView.VIEWNAME;
139 
140  }
141 
142  }
143 
144  // by here we're allowed to introspect, now we need to look up the token in our token stores
145 
146  // first make sure the token is there
147  if (Strings.isNullOrEmpty(tokenValue)) {
148  logger.error("Verify failed; token value is null");
149  Map<String,Boolean> entity = ImmutableMap.of("active", Boolean.FALSE);
150  model.addAttribute(JsonEntityView.ENTITY, entity);
151  return JsonEntityView.VIEWNAME;
152  }
153 
154  OAuth2AccessTokenEntity accessToken = null;
155  OAuth2RefreshTokenEntity refreshToken = null;
156  ClientDetailsEntity tokenClient;
157  UserInfo user;
158 
159  try {
160 
161  // check access tokens first (includes ID tokens)
162  accessToken = tokenServices.readAccessToken(tokenValue);
163 
164  tokenClient = accessToken.getClient();
165 
166  // get the user information of the user that authorized this token in the first place
167  String userName = accessToken.getAuthenticationHolder().getAuthentication().getName();
168  user = userInfoService.getByUsernameAndClientId(userName, tokenClient.getClientId());
169 
170  } catch (InvalidTokenException e) {
171  logger.info("Invalid access token. Checking refresh token.");
172  try {
173 
174  // check refresh tokens next
175  refreshToken = tokenServices.getRefreshToken(tokenValue);
176 
177  tokenClient = refreshToken.getClient();
178 
179  // get the user information of the user that authorized this token in the first place
180  String userName = refreshToken.getAuthenticationHolder().getAuthentication().getName();
181  user = userInfoService.getByUsernameAndClientId(userName, tokenClient.getClientId());
182 
183  } catch (InvalidTokenException e2) {
184  logger.error("Invalid refresh token");
185  Map<String,Boolean> entity = ImmutableMap.of(IntrospectionResultAssembler.ACTIVE, Boolean.FALSE);
186  model.addAttribute(JsonEntityView.ENTITY, entity);
187  return JsonEntityView.VIEWNAME;
188  }
189  }
190 
191  // if it's a valid token, we'll print out information on it
192 
193  if (accessToken != null) {
194  Map<String, Object> entity = introspectionResultAssembler.assembleFrom(accessToken, user, authScopes);
195  model.addAttribute(JsonEntityView.ENTITY, entity);
196  } else if (refreshToken != null) {
197  Map<String, Object> entity = introspectionResultAssembler.assembleFrom(refreshToken, user, authScopes);
198  model.addAttribute(JsonEntityView.ENTITY, entity);
199  } else {
200  // no tokens were found (we shouldn't get here)
201  logger.error("Verify failed; Invalid access/refresh token");
202  Map<String,Boolean> entity = ImmutableMap.of(IntrospectionResultAssembler.ACTIVE, Boolean.FALSE);
203  model.addAttribute(JsonEntityView.ENTITY, entity);
204  return JsonEntityView.VIEWNAME;
205  }
206 
207  return JsonEntityView.VIEWNAME;
208 
209  }
static final Logger logger
Definition: IntrospectionEndpoint.java:81
OAuth2RefreshTokenEntity getRefreshToken(String refreshTokenValue)
UserInfo getByUsernameAndClientId(String username, String clientId)
UserInfoService userInfoService
Definition: IntrospectionEndpoint.java:73
Collection< ResourceSet > getAllForOwnerAndClient(String owner, String authClientId)
ResourceSetService resourceSetService
Definition: IntrospectionEndpoint.java:76
ClientDetailsEntity getClient()
Definition: OAuth2AccessTokenEntity.java:177
IntrospectionResultAssembler introspectionResultAssembler
Definition: IntrospectionEndpoint.java:70
OAuth2TokenEntityService tokenServices
Definition: IntrospectionEndpoint.java:64
ClientDetailsEntity getClient()
Definition: OAuth2RefreshTokenEntity.java:162
ClientDetailsEntity loadClientByClientId(String clientId)
OAuth2AccessTokenEntity readAccessToken(String accessTokenValue)
Map< String, Object > assembleFrom(OAuth2AccessTokenEntity accessToken, UserInfo userInfo, Set< String > authScopes)
ClientDetailsEntityService clientService
Definition: IntrospectionEndpoint.java:67

メンバ詳解

◆ clientService

ClientDetailsEntityService org.mitre.oauth2.web.IntrospectionEndpoint.clientService
private

◆ introspectionResultAssembler

IntrospectionResultAssembler org.mitre.oauth2.web.IntrospectionEndpoint.introspectionResultAssembler
private

◆ logger

final Logger org.mitre.oauth2.web.IntrospectionEndpoint.logger = LoggerFactory.getLogger(IntrospectionEndpoint.class)
staticprivate

Logger for this class

◆ resourceSetService

ResourceSetService org.mitre.oauth2.web.IntrospectionEndpoint.resourceSetService
private

◆ tokenServices

OAuth2TokenEntityService org.mitre.oauth2.web.IntrospectionEndpoint.tokenServices
private

◆ URL

final String org.mitre.oauth2.web.IntrospectionEndpoint.URL = "introspect"
static

◆ userInfoService

UserInfoService org.mitre.oauth2.web.IntrospectionEndpoint.userInfoService
private

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