• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java OAuth2TokenValidationServiceStub类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub的典型用法代码示例。如果您正苦于以下问题:Java OAuth2TokenValidationServiceStub类的具体用法?Java OAuth2TokenValidationServiceStub怎么用?Java OAuth2TokenValidationServiceStub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OAuth2TokenValidationServiceStub类属于org.wso2.carbon.identity.oauth2.stub包,在下文中一共展示了OAuth2TokenValidationServiceStub类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setupValidationService

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
/**
 * 
 * @param stub
 * @return receives a non prepared stub and set up it
 */
private OAuth2TokenValidationServiceStub setupValidationService(OAuth2TokenValidationServiceStub stub) {
    AuthProperties props = AuthProperties.inst();

    ServiceClient client = stub._getServiceClient();
    Options options = client.getOptions();

    CarbonUtils.setBasicAccessSecurityHeaders(props.getWso2User(), props.getWso2Password(), true, client);

    options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS);
    options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS);
    options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS);
    options.setCallTransportCleanup(true);
    options.setManageSession(true);

    return stub;
}
 
开发者ID:romulets,项目名称:wso2is-example,代码行数:22,代码来源:TokenValidationService.java


示例2: Oauth2TokenValidator

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
public Oauth2TokenValidator(String identityURL, String userName, String password)
        throws MalformedURLException, AxisFault {

    this.identityURL = identityURL;
    String adminUserName = userName;
    String adminPassword = password;

    //create service client with given url
    String targetEndpointUrl = identityURL + "/services/OAuth2TokenValidationService.OAuth2TokenValidationServiceHttpsSoap12Endpoint/";
    OAuth2TokenValidationServiceStub stub = new OAuth2TokenValidationServiceStub(targetEndpointUrl);
    oAuth2TokenValidationService = stub;

    ServiceClient client = stub._getServiceClient();
    HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
    authenticator.setUsername(adminUserName);
    authenticator.setPassword(adminPassword);
    authenticator.setPreemptiveAuthentication(true);
    Options options = client.getOptions();
    options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);

    client.setOptions(options);
}
 
开发者ID:GruppoFilippetti,项目名称:vertx-mqtt-broker,代码行数:23,代码来源:Oauth2TokenValidator.java


示例3: passivateObject

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
@Override
public void passivateObject(Object o) throws Exception {
    if (o instanceof OAuth2TokenValidationServiceStub) {
        OAuth2TokenValidationServiceStub stub = (OAuth2TokenValidationServiceStub) o;
        stub._getServiceClient().cleanupTransport();
    }
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:8,代码来源:OAuthTokenValidationStubFactory.java


示例4: validateToken

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
/**
 * This method gets a string accessToken and validates it and generate the OAuth2ClientApplicationDTO
 * containing the validity and user details if valid.
 *
 * @param token which need to be validated.
 * @return OAuthValidationResponse with the validated results.
 */
public OAuthValidationResponse validateToken(String token) throws RemoteException {
    OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken =
            new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
    accessToken.setTokenType(OauthAuthenticatorConstants.BEARER_TOKEN_TYPE);
    accessToken.setIdentifier(token);
    validationRequest.setAccessToken(accessToken);
    OAuth2TokenValidationServiceStub tokenValidationService =
            new OAuth2TokenValidationServiceStub(hostURL);
    ServiceClient client = tokenValidationService._getServiceClient();
    Options options = client.getOptions();
    List<Header> headerList = new ArrayList<>();
    Header header = new Header();
    header.setName(HTTPConstants.HEADER_AUTHORIZATION);
    header.setValue(OauthAuthenticatorConstants.AUTHORIZATION_HEADER_PREFIX_BASIC + " " + getBasicAuthCredentials());
    headerList.add(header);
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS, headerList);
    client.setOptions(options);
    OAuth2TokenValidationResponseDTO tokenValidationResponse = tokenValidationService.
            findOAuthConsumerIfTokenIsValid(validationRequest).getAccessTokenValidationResponse();
    boolean isValid = tokenValidationResponse.getValid();
    String userName = null;
    String tenantDomain = null;
    if (isValid) {
        userName = MultitenantUtils.getTenantAwareUsername(
                tokenValidationResponse.getAuthorizedUser());
        tenantDomain = MultitenantUtils.
                getTenantDomain(tokenValidationResponse.getAuthorizedUser());
    }
    return new OAuthValidationResponse(userName,tenantDomain,isValid);
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:39,代码来源:ExternalOAuthValidator.java


示例5: OAuthServiceClient

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
/**
 * OAuth2TokenValidationService Admin Service Client
 *
 * @param backendServerURL
 * @param username
 * @param password
 * @param configCtx
 * @throws Exception
 */
public OAuthServiceClient(String backendServerURL, String username, String password,
                          ConfigurationContext configCtx) throws Exception {
    String serviceURL = backendServerURL + "OAuth2TokenValidationService";
    try {
        stub = new OAuth2TokenValidationServiceStub(configCtx, serviceURL);
        CarbonUtils.setBasicAccessSecurityHeaders(username, password, true, stub._getServiceClient());
    } catch (AxisFault e) {
        log.error("Error initializing OAuth2 Client");
        throw new Exception("Error initializing OAuth Client", e);
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:21,代码来源:OAuthServiceClient.java


示例6: ValidationServiceClient

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
public ValidationServiceClient(String backendServerURL, String username, String password) throws Exception {
    String serviceURL = backendServerURL + "OAuth2TokenValidationService";
    try {
        stub = new OAuth2TokenValidationServiceStub(serviceURL);
        CarbonUtils.setBasicAccessSecurityHeaders(username, password, true, stub._getServiceClient());
    } catch (AxisFault e) {
        log.error("Error initializing OAuth2 Client");
        throw new Exception("Error initializing OAuth Client", e);
    }
}
 
开发者ID:apache,项目名称:stratos,代码行数:11,代码来源:ValidationServiceClient.java


示例7: passivateObject

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
/**
 * This is used to clean up the OAuth validation stub and releases to the object pool.
 * @param o object that needs to be released.
 * @throws Exception throws when failed to release to the pool
 */
@Override
public void passivateObject(Object o) throws Exception {
	if (o instanceof OAuth2TokenValidationServiceStub) {
		OAuth2TokenValidationServiceStub stub = (OAuth2TokenValidationServiceStub) o;
		stub._getServiceClient().cleanupTransport();
	}
}
 
开发者ID:wso2,项目名称:carbon-business-messaging,代码行数:13,代码来源:OAuthTokenValidaterStubFactory.java


示例8: DefaultOAuthClient

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
/**
 * OAuth2TokenValidationService Admin Service Client
 *
 * @param auhorizationServerURL
 * @param username
 * @param password
 * @param configCtx
 * @throws Exception
 */
public DefaultOAuthClient(String auhorizationServerURL, String username, String password,
                          ConfigurationContext configCtx) throws AiravataSecurityException {
    try {
        String serviceURL = auhorizationServerURL + "OAuth2TokenValidationService";
        stub = new OAuth2TokenValidationServiceStub(configCtx, serviceURL);
        CarbonUtils.setBasicAccessSecurityHeaders(username, password, true, stub._getServiceClient());
    } catch (AxisFault e) {
        logger.error(e.getMessage(), e);
        throw new AiravataSecurityException("Error initializing OAuth client.");
    }
}
 
开发者ID:apache,项目名称:airavata,代码行数:21,代码来源:DefaultOAuthClient.java


示例9: getValidationService

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
/**
 * 
 * @return validation service ready for use
 * @throws AxisFault
 */
private OAuth2TokenValidationServiceStub getValidationService() throws AxisFault {
    String serviceURL = AuthProperties.inst().getTokenValidationEndpoint();
    OAuth2TokenValidationServiceStub stub = new OAuth2TokenValidationServiceStub(null, serviceURL);
    return setupValidationService(stub);
}
 
开发者ID:romulets,项目名称:wso2is-example,代码行数:11,代码来源:TokenValidationService.java


示例10: testAuthenticate

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
@Test(description = "This method tests the authenticate under different parameters",
        dependsOnMethods = {"testInit"})
public void testAuthenticate() throws Exception {
    Request request = createOauthRequest(BEARER_HEADER);
    Assert.assertEquals(oAuthAuthenticator.authenticate(request, null).getStatus(),
            WebappAuthenticator.Status.CONTINUE, "Authentication status mismatched");
    request = createOauthRequest(BEARER_HEADER + "abc");
    org.apache.coyote.Request coyoteRequest = request.getCoyoteRequest();
    Field uriMB = org.apache.coyote.Request.class.getDeclaredField("uriMB");
    uriMB.setAccessible(true);
    MessageBytes bytes = MessageBytes.newInstance();
    bytes.setString("test");
    uriMB.set(coyoteRequest, bytes);
    request.setCoyoteRequest(coyoteRequest);
    Field tokenValidator = OAuthAuthenticator.class.getDeclaredField("tokenValidator");
    tokenValidator.setAccessible(true);

    GenericObjectPool genericObjectPool = Mockito.mock(GenericObjectPool.class, Mockito.CALLS_REAL_METHODS);
    RemoteOAuthValidator remoteOAuthValidator = Mockito
            .mock(RemoteOAuthValidator.class, Mockito.CALLS_REAL_METHODS);
    tokenValidator.set(oAuthAuthenticator, remoteOAuthValidator);
    Field stubs = RemoteOAuthValidator.class.getDeclaredField("stubs");
    stubs.setAccessible(true);
    stubs.set(remoteOAuthValidator, genericObjectPool);
    OAuth2TokenValidationResponseDTO oAuth2TokenValidationResponseDTO = new OAuth2TokenValidationResponseDTO();
    oAuth2TokenValidationResponseDTO.setValid(true);
    oAuth2TokenValidationResponseDTO.setAuthorizedUser("[email protected]");
    OAuth2ClientApplicationDTO oAuth2ClientApplicationDTO = Mockito
            .mock(OAuth2ClientApplicationDTO.class, Mockito.CALLS_REAL_METHODS);
    Mockito.doReturn(oAuth2TokenValidationResponseDTO).when(oAuth2ClientApplicationDTO)
            .getAccessTokenValidationResponse();
    OAuth2TokenValidationServiceStub oAuth2TokenValidationServiceStub = Mockito
            .mock(OAuth2TokenValidationServiceStub.class, Mockito.CALLS_REAL_METHODS);
    Mockito.doReturn(oAuth2ClientApplicationDTO).when(oAuth2TokenValidationServiceStub)
            .findOAuthConsumerIfTokenIsValid(Mockito.any());
    Mockito.doReturn(oAuth2TokenValidationServiceStub).when(genericObjectPool).borrowObject();
    oAuthAuthenticator.canHandle(request);
    AuthenticationInfo authenticationInfo = oAuthAuthenticator.authenticate(request, null);
    Assert.assertEquals(authenticationInfo.getUsername(), "admin");

}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:42,代码来源:OauthAuthenticatorTest.java


示例11: getAuthenticationInfo

import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; //导入依赖的package包/类
/**
 * This creates an AuthenticationInfo object that is used for authorization. This method will validate the token and
 * sets the required parameters to the object.
 *
 * @param token                      that needs to be validated.
 * @param tokenValidationServiceStub stub that is used to call the external service.
 * @return AuthenticationInfo This contains the information related to authenticated client.
 * @throws RemoteException that triggers when failing to call the external service..
 */
private AuthenticationInfo getAuthenticationInfo(String token,
	OAuth2TokenValidationServiceStub tokenValidationServiceStub) throws RemoteException {
	AuthenticationInfo authenticationInfo = new AuthenticationInfo();
	OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO();
	OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken =
			new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
	accessToken.setTokenType(TOKEN_TYPE);
	accessToken.setIdentifier(token);
	validationRequest.setAccessToken(accessToken);
	boolean authenticated;
	OAuth2TokenValidationResponseDTO tokenValidationResponse;
	tokenValidationResponse = tokenValidationServiceStub.validate(validationRequest);
	if (tokenValidationResponse == null) {
		authenticationInfo.setAuthenticated(false);
		return authenticationInfo;
	}
	authenticated = tokenValidationResponse.getValid();
	if (authenticated) {
		String authorizedUser = tokenValidationResponse.getAuthorizedUser();
		String username = MultitenantUtils.getTenantAwareUsername(authorizedUser);
		String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser);
		authenticationInfo.setUsername(username);
		authenticationInfo.setTenantDomain(tenantDomain);
		authenticationInfo.setProperty(TOKEN_EXPIRY_TIME_IDENTIFIER, tokenValidationResponse.getExpiryTime());
		String validateResponseScope[] = tokenValidationResponse.getScope();
		if (validateResponseScope != null && validateResponseScope.length > 0) {
			List<String> responseScopes = Arrays.asList(validateResponseScope);
			authenticationInfo.setProperty(SCOPE_IDENTIFIER, responseScopes);
		}
	} else {
		if (log.isDebugEnabled()) {
			log.debug("Token validation failed for token: " + token);
		}
	}
	ServiceContext serviceContext = tokenValidationServiceStub._getServiceClient()
			.getLastOperationContext().getServiceContext();
	cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
	authenticationInfo.setAuthenticated(authenticated);
	return authenticationInfo;
}
 
开发者ID:wso2,项目名称:carbon-business-messaging,代码行数:50,代码来源:OAuth2BasedMQTTAuthenticator.java



注:本文中的org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PGL类代码示例发布时间:2022-05-23
下一篇:
Java DataSink类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap