当前位置: 首页>>代码示例>>Java>>正文


Java AuthorizationPolicy类代码示例

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


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

示例1: testGetCurrentSystemAgentUriNoAgent

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
/**
 * Gets the System Agent URI to assign to an Event where user has no Agent
 * Should return exception saying the user has no Agent
 **/
@Test
public void testGetCurrentSystemAgentUriNoAgent() throws Exception {
	User user = new User(testUserName2, testUserEmail2);
	user.setAuthKeyUri(testAuthKeyUri2);
	user.setDoRMapAgentSync(false);
	int userId = rmapAuthService.addUser(user);

	ApiKey apiKey = new ApiKey(); 
	apiKey.setUserId(userId);
	apiKey.setLabel("test");
	rmapAuthService.addApiKey(apiKey);
	
	//set up default authpolicy
	AuthorizationPolicy authPolicy2 = new AuthorizationPolicy();
	authPolicy2.setUserName(apiKey.getAccessKey());
	authPolicy2.setPassword(apiKey.getSecret());	
	
	doReturn(authPolicy2).when(spyApiUserService).getCurrentAuthPolicy();
	URI currSystemAgent = spyApiUserService.getCurrentSystemAgentUri();
	assertTrue(currSystemAgent==null);
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:26,代码来源:ApiUserServiceTest.java

示例2: setClientAuthentication

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
private static void setClientAuthentication(Object client, String userName, String password) {
	// Properties p = new Properties(); //PropertiesLoader.getPropertiesFromFile("config.properties");
	ClientConfiguration config = WebClient.getConfig(client);
	HTTPConduit httpConduit = (HTTPConduit) config.getConduit();

	AuthorizationPolicy authorization = new AuthorizationPolicy();
	authorization.setUserName(userName);
	authorization.setPassword(password);
	httpConduit.setAuthorization(authorization);

	TLSClientParameters tlsParams = new TLSClientParameters();
	TrustManager[] trustAllCerts = new TrustManager[] { new TrustManager() };
	tlsParams.setTrustManagers(trustAllCerts);

	// disables verification of the common name (the host for which the certificate has been issued)
	tlsParams.setDisableCNCheck(true);
	httpConduit.setTlsClientParameters(tlsParams);
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:19,代码来源:EaapsServiceClient.java

示例3: handleRequest

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
/**
 * Implementation of RequestHandler.handleRequest method.
 * This method retrieves userName and password from Basic auth header,
 * and tries to authenticate against carbon user store
 *
 * Upon successful authentication allows process to proceed to retrieve requested REST resource
 * Upon invalid credentials returns a HTTP 401 UNAUTHORIZED response to client
 * Upon receiving a userStoreExceptions or IdentityException returns HTTP 500 internal server error to client
 *
 * @param message
 * @param classResourceInfo
 * @return Response
 */
public Response handleRequest(Message message, ClassResourceInfo classResourceInfo) {
    if (log.isDebugEnabled()) {
        log.debug("Registry REST API Basic authentication handler execution started");
    }

    AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
    if (policy != null && HttpAuthHeader.AUTH_TYPE_BASIC.equals(policy.getAuthorizationType())) {
        try {
            if (authenticate(policy.getUserName(), policy.getPassword())) {
                return null;
            }
        } catch (RestApiBasicAuthenticationException e) {
            /* Upon an occurrence of exception log the caught exception
             * and return a HTTP response with 500 server error response */
            log.error("Could not authenticate user : " + policy.getUserName() + "against carbon userStore", e);
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
        }

        return Response.status(Response.Status.UNAUTHORIZED).header("WWW-Authenticate", HttpAuthHeader.AUTH_TYPE_BASIC).build();
    }

    return Response.status(Response.Status.UNAUTHORIZED).header("WWW-Authenticate", HttpAuthHeader.AUTH_TYPE_BASIC).build();
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:37,代码来源:RestApiBasicAuthenticationHandler.java

示例4: handleRequest

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
public Response handleRequest(Message m, ClassResourceInfo resourceClass) {
    AuthorizationPolicy policy = m.get(AuthorizationPolicy.class);
    if (policy != null) {
        String username = policy.getUserName();
        String password = policy.getPassword();
        try {
            session = JcrSessionUtil.createSession(username, password);
            if (isAuthenticated(session)) {
                HttpServletRequest request = (HttpServletRequest) m.get(AbstractHTTPDestination.HTTP_REQUEST);
                request.setAttribute(AuthenticationConstants.HIPPO_SESSION, session);
                return null;
            } else {
                throw new UnauthorizedException();
            }
        } catch (LoginException e) {
            log.debug("Login failed: {}", e);
            throw new UnauthorizedException(e.getMessage());
        }
    }
    throw new UnauthorizedException();
}
 
开发者ID:jreijn,项目名称:hippo-addon-restful-webservices,代码行数:22,代码来源:HippoAuthenticationRequestHandler.java

示例5: basicAuthorization

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
@Bean
public AuthorizationPolicy basicAuthorization() {
  AuthorizationPolicy authorizationPolicy =
      new AuthorizationPolicy();
  authorizationPolicy.setUserName(userName);
  authorizationPolicy.setPassword(password);
  authorizationPolicy.setAuthorizationType("Basic");

  return authorizationPolicy;
}
 
开发者ID:code-not-found,项目名称:cxf-jaxws,代码行数:11,代码来源:ClientConfig.java

示例6: getCurrentAuthPolicy

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
@Override
public AuthorizationPolicy getCurrentAuthPolicy() throws RMapApiException {
	AuthorizationPolicy authorizationPolicy = null;
	Message message = JAXRSUtils.getCurrentMessage();
	authorizationPolicy = message.get(AuthorizationPolicy.class);
    if (authorizationPolicy == null) {
        throw new RMapApiException(ErrorCode.ER_COULD_NOT_RETRIEVE_AUTHPOLICY);
        }
    LOG.debug("Authorization policy retrieved with username {}", authorizationPolicy.getUserName());
    return authorizationPolicy;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:12,代码来源:ApiUserServiceImpl.java

示例7: getCurrentSystemAgentUri

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
public URI getCurrentSystemAgentUri() throws RMapApiException {
    AuthorizationPolicy policy = getCurrentAuthPolicy();
	String key = policy.getUserName();
	String secret = policy.getPassword();
	URI sysAgentUri = getSystemAgentUri(key, secret);
	return sysAgentUri;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:8,代码来源:ApiUserServiceImpl.java

示例8: getApiKeyForEvent

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
@Override
public URI getApiKeyForEvent() throws RMapApiException {
    AuthorizationPolicy policy = getCurrentAuthPolicy();
	String key = policy.getUserName();
	String secret = policy.getPassword();
	return getApiKeyUriForEvent(key, secret);
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:8,代码来源:ApiUserServiceImpl.java

示例9: handleMessage

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
/**
 * Gets basic authentication information from request and validates key
 * throws an error if key is invalid.
 *
 * @param message http message
 */
public void handleMessage(Message message) {

 try {   
 	//only authenticate if you are trying to write to the db... 
 	HttpServletRequest req = (HttpServletRequest) message.get("HTTP.REQUEST");
 	String method = req.getMethod();
 	
 	if (method!=HttpMethod.GET && method!=HttpMethod.OPTIONS && method!=HttpMethod.HEAD){
	 
  	AuthorizationPolicy policy = apiUserService.getCurrentAuthPolicy();
  	String accessKey = policy.getUserName();
  	String secret = policy.getPassword();
  
if (accessKey==null || accessKey.length()==0
		|| secret==null || secret.length()==0)	{
   	throw new RMapApiException(ErrorCode.ER_NO_USER_TOKEN_PROVIDED);
}		
			
apiUserService.validateKey(accessKey, secret);
 	}
 	
 } catch (RMapApiException ex){ 
 	//generate a response to intercept default message
 	Response response = exceptionHandler.toResponse(ex);
 	message.getExchange().put(Response.class, response);   	
 }
		
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:35,代码来源:AuthenticationInterceptor.java

示例10: setUp

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
/**
 * Sets the up.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
	super.setUp(); 
	//going to spy on ApiUserService so that we can simulate basic auth.
	String testAccessKey = "uah2CKDaBsEw3cEQ";
	String testSecret = "NSbdzctrP46ZvhTi";
	AuthorizationPolicy authPolicy = new AuthorizationPolicy();
	authPolicy.setUserName(testAccessKey);
	authPolicy.setPassword(testSecret);	
	spyApiUserService = spy((ApiUserServiceImpl) apiUserService);
	doReturn(authPolicy).when(spyApiUserService).getCurrentAuthPolicy();
	discoResponseManager = new DiscoResponseManager(rmapService, rdfHandler, spyApiUserService, timegate);
	discoResponseManager.setPathUtils(pathUtils);
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:20,代码来源:DiscoResponseManagerTest.java

示例11: setup

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	authPolicy = new AuthorizationPolicy();
	authPolicy.setUserName(testAccessKey);
	authPolicy.setPassword(testSecret);		
	
	spyApiUserService = spy(apiUserService);				
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:9,代码来源:ApiUserServiceTest.java

示例12: getKeyUriForEventWhereIncludeInEventTest

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
/**
 * Tests retrieval of a key URI to be associated with an event.
 * Should retrieve a key URI.
 */
@Test
public void getKeyUriForEventWhereIncludeInEventTest() throws Exception {

	String TESTKEY = "rmap:fakermaptestkey";
	
	//create agent with key that should include uri
	User user = new User(testUserName2, testUserEmail2);
	user.setAuthKeyUri(testAuthKeyUri2);
	user.setDoRMapAgentSync(true);
	int userId = rmapAuthService.addUser(user);

	ApiKey apiKey = new ApiKey(); 
	apiKey.setUserId(userId);
	apiKey.setLabel("test");
	apiKey.setKeyUri(TESTKEY);
	apiKey.setIncludeInEvent(true);
	rmapAuthService.addApiKey(apiKey);

	//set up default authpolicy
	AuthorizationPolicy authPolicy2 = new AuthorizationPolicy();
	authPolicy2.setUserName(apiKey.getAccessKey());
	authPolicy2.setPassword(apiKey.getSecret());	
	
	doReturn(authPolicy2).when(spyApiUserService).getCurrentAuthPolicy();
	URI apiKeyUri = spyApiUserService.getApiKeyForEvent();
	assertTrue(apiKeyUri.toString().equals(TESTKEY));
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:32,代码来源:ApiUserServiceTest.java

示例13: createSupplierPush

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
private SupplierPushInterface createSupplierPush(PushTarget target) {
	SupplierPushService pushService = new SupplierPushService(
			target.getUrl());
	SupplierPushInterface push = pushService.getSupplierPushSoapEndPoint();

	if (target.getUsername() != null) {
		Client client = ClientProxy.getClient(push);
		HTTPConduit http = (HTTPConduit) client.getConduit();
		AuthorizationPolicy authorization = http.getAuthorization();
		authorization.setUserName(target.getUsername());
		authorization.setPassword(target.getPassword());
	}

	return push;
}
 
开发者ID:cdvcz,项目名称:datex2,代码行数:16,代码来源:Pusher.java

示例14: setBasicAuthentication

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
private void setBasicAuthentication(String userName, String password) {
    Client client = ClientProxy.getClient(helloWorldJaxWsProxy);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();

    AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
    authorizationPolicy.setUserName(userName);
    authorizationPolicy.setPassword(password);

    conduit.setAuthorization(authorizationPolicy);
}
 
开发者ID:code-not-found,项目名称:jaxws-cxf,代码行数:11,代码来源:HelloWorldClientImpl.java

示例15: HttpBasicAuthenticator

import org.apache.cxf.configuration.security.AuthorizationPolicy; //导入依赖的package包/类
public HttpBasicAuthenticator(String username, String password) {
    // like the spring beans at http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html
    auth = new AuthorizationPolicy();
    auth.setUserName(username);
    auth.setPassword(password);
    auth.setAuthorizationType("Basic"); // FIXME: use a CXF constant instead
}
 
开发者ID:apifocal,项目名称:wsman4j,代码行数:8,代码来源:HttpBasicAuthenticator.java


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