use of org.apache.oltu.oauth2.common.exception.OAuthProblemException in project dq-easy-cloud by dq-open-cloud.
the class EcAuthorizeController method userInfo.
@RequestMapping("/userInfo")
public HttpEntity userInfo(HttpServletRequest request) throws OAuthSystemException {
try {
// 构建OAuth资源请求
OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request, ParameterStyle.QUERY);
// 获取Access Token
String accessToken = oauthRequest.getAccessToken();
// 验证Access Token
boolean accessTokenFlag = false;
// if (!oAuthService.checkAccessToken(accessToken)) {
if (accessTokenFlag) {
// 如果不存在/过期了,返回未验证错误,需重新验证
OAuthResponse oauthResponse = OAuthRSResponse.errorResponse(HttpServletResponse.SC_UNAUTHORIZED).setRealm("过期了").setError(OAuthError.ResourceResponse.INVALID_TOKEN).buildHeaderMessage();
HttpHeaders headers = new HttpHeaders();
headers.add(OAuth.HeaderType.WWW_AUTHENTICATE, oauthResponse.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE));
return new ResponseEntity(headers, HttpStatus.UNAUTHORIZED);
}
// 返回用户名
// String username = oAuthService.getUsernameByAccessToken(accessToken);
Object username = tokenCache.get(accessToken);
return new ResponseEntity(username, HttpStatus.OK);
} catch (OAuthProblemException e) {
// 检查是否设置了错误码
String errorCode = e.getError();
if (OAuthUtils.isEmpty(errorCode)) {
OAuthResponse oauthResponse = OAuthRSResponse.errorResponse(HttpServletResponse.SC_UNAUTHORIZED).setRealm("server").buildHeaderMessage();
HttpHeaders headers = new HttpHeaders();
headers.add(OAuth.HeaderType.WWW_AUTHENTICATE, oauthResponse.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE));
return new ResponseEntity(headers, HttpStatus.UNAUTHORIZED);
}
OAuthResponse oauthResponse = OAuthRSResponse.errorResponse(HttpServletResponse.SC_UNAUTHORIZED).setRealm("server").setError(e.getError()).setErrorDescription(e.getDescription()).setErrorUri(e.getUri()).buildHeaderMessage();
HttpHeaders headers = new HttpHeaders();
headers.add(OAuth.HeaderType.WWW_AUTHENTICATE, oauthResponse.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE));
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
}
use of org.apache.oltu.oauth2.common.exception.OAuthProblemException in project BIMserver by opensourceBIM.
the class SendUrl method main.
public static void main(String[] args) {
try {
OAuthClientRequest request = OAuthClientRegistrationRequest.location("https://thisisanexperimentalserver.com/oauth/register/", OAuthRegistration.Type.PUSH).setName("Zapier").setUrl("https://zapier.com/dashboard/auth/oauth/return/App56192API").setDescription("App Description").setRedirectURL("https://zapier.com/dashboard/auth/oauth/return/App56192API").buildJSONMessage();
OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new org.bimserver.webservices.impl.URLConnectionClient());
OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
System.out.println(response.getClientId());
System.out.println(response.getClientSecret());
} catch (OAuthSystemException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (OAuthProblemException e) {
e.printStackTrace();
}
}
use of org.apache.oltu.oauth2.common.exception.OAuthProblemException in project BIMserver by opensourceBIM.
the class JsonHandler method getServiceMap.
private ServiceMap getServiceMap(HttpServletRequest httpRequest, BimServer bimServer, String methodName, String token, String oAuthCode) throws UserException {
if (token == null) {
token = httpRequest == null ? null : (String) httpRequest.getSession().getAttribute("token");
}
if (token == null) {
token = oAuthCode;
}
if (token == null) {
if (httpRequest != null) {
try {
OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(httpRequest, ParameterStyle.HEADER);
token = oauthRequest.getAccessToken();
} catch (OAuthSystemException e) {
} catch (OAuthProblemException e) {
}
}
}
if (token == null) {
return null;
}
ServiceMap serviceMap = bimServer.getServiceFactory().get(token, AccessMethod.JSON);
return serviceMap;
}
Aggregations