本文整理汇总了Java中org.apache.oltu.oauth2.as.issuer.OAuthIssuer类的典型用法代码示例。如果您正苦于以下问题:Java OAuthIssuer类的具体用法?Java OAuthIssuer怎么用?Java OAuthIssuer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuthIssuer类属于org.apache.oltu.oauth2.as.issuer包,在下文中一共展示了OAuthIssuer类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildAuthenticatedUserResponse
import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; //导入依赖的package包/类
private Response buildAuthenticatedUserResponse(UserVO userVO) throws OAuthSystemException {
OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
OAuthResponse response = OAuthASResponse
.tokenResponse(HttpServletResponse.SC_OK)
.setAccessToken(oauthIssuerImpl.accessToken())
.setExpiresIn("3600")
.buildJSONMessage();
return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
}
示例2: OAuth2Tokens
import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; //导入依赖的package包/类
/**
* Generate Constructor
* @return new OAuth2Tokens Object with newly generated tokens
* @throws Exception
*/
public OAuth2Tokens () throws Exception {
OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator() );
this.authorizationCode = oauthIssuerImpl.authorizationCode();
this.accessToken = oauthIssuerImpl.accessToken();
this.refreshToken = oauthIssuerImpl.refreshToken();
}
示例3: authorize
import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; //导入依赖的package包/类
@POST
@Path("/authz")
@RequiresRoles("agate-user")
public Response authorize(@Context HttpServletRequest servletRequest, @FormParam("grant") boolean grant)
throws URISyntaxException, OAuthSystemException {
return tryBuildResponse(servletRequest, (data) -> {
try {
if(!grant) {
return buildErrorResponse(OAuthProblemException.error("access_denied", "Owner denied authorization."), data.getRequest(), data.getRedirectUri());
}
OAuthIssuer oAuthIssuer = new OAuthIssuerImpl(new MD5Generator());
User user = userService.getCurrentUser();
Authorization authorization = authorizationService.find(user.getName(), data.getClientId());
if(authorization == null) {
authorization = new Authorization(user.getName(), data.getClientId());
}
authorization.setCode(oAuthIssuer.authorizationCode());
authorization.setScopes(data.getRequest().getScopes());
authorization.setRedirectURI(data.getRedirectUri());
authorizationService.save(authorization);
long expiresIn = authorizationService.getExpirationDate(authorization).getMillis() - DateTime.now().getMillis();
OAuthASResponse.OAuthAuthorizationResponseBuilder builder = OAuthASResponse
.authorizationResponse(servletRequest, HttpServletResponse.SC_FOUND) //
.setCode(authorization.getCode()) //
.setExpiresIn(expiresIn / 1000) //
.location(data.getRedirectUri());
setState(builder, data.getRequest());
OAuthResponse response = builder.buildQueryMessage();
return Response.status(response.getResponseStatus()).location(new URI(response.getLocationUri())).build();
} catch(URISyntaxException | OAuthSystemException e) {
throw Throwables.propagate(e);
}
});
}
示例4: token
import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; //导入依赖的package包/类
@RequestMapping("/accessToken")
public HttpEntity<String> token(HttpServletRequest request) throws URISyntaxException, OAuthSystemException {
try {
// 构建OAuth请求
OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);
// 检查提交的客户端id是否正确
if (!oAuthService.checkClientId(oauthRequest.getClientId())) {
return buildInvalidClientIdResponse();
}
// 检查客户端安全KEY是否正确
if (!oAuthService.checkClientSecret(oauthRequest.getClientSecret())) {
return buildInvalidClientSecretResponse();
}
String authCode = oauthRequest.getParam(OAuth.OAUTH_CODE);
// 检查验证类型,此处只检查AUTHORIZATION_CODE类型,其他的还有PASSWORD或REFRESH_TOKEN
if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.AUTHORIZATION_CODE.toString())) {
if (!oAuthService.checkAuthCode(authCode)) {
return buildBadAuthCodeResponse();
}
// TODO 后两种未测试
} else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.PASSWORD.toString())) {
if (!checkUserPassword(oauthRequest.getUsername(), oauthRequest.getPassword())) {
return buildInvalidUserPassResponse();
}
} else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.REFRESH_TOKEN.toString())) {
// https://github.com/zhouyongtao/homeinns-web
if (!oAuthService.checkAuthCode(authCode)) {
return buildInvalidRefreshTokenResponse();
}
}
// 生成Access Token
OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
final String accessToken = oauthIssuerImpl.accessToken();
oAuthService.addAccessToken(accessToken, oAuthService.getUsernameByAuthCode(authCode));
final String refreshToken = oauthIssuerImpl.refreshToken();
oAuthService.addAccessToken(refreshToken, oAuthService.getUsernameByAuthCode(authCode));
// 生成OAuth响应
OAuthResponse response = OAuthASResponse.tokenResponse(HttpServletResponse.SC_OK)
.setAccessToken(accessToken).setExpiresIn(String.valueOf(oAuthService.getExpireIn()))
.setTokenType(TokenType.BEARER.toString()).setRefreshToken(refreshToken).buildJSONMessage();
// 根据OAuthResponse生成ResponseEntity
return new ResponseEntity<String>(response.getBody(), HttpStatus.valueOf(response.getResponseStatus()));
} catch (OAuthProblemException e) {
// 构建错误响应
OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e)
.buildJSONMessage();
return new ResponseEntity<String>(res.getBody(), HttpStatus.valueOf(res.getResponseStatus()));
}
}