Java Code Examples for org.apache.cxf.configuration.security.AuthorizationPolicy#setPassword()
The following examples show how to use
org.apache.cxf.configuration.security.AuthorizationPolicy#setPassword() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthPolicyValidatingInterceptorTest.java From steady with Apache License 2.0 | 6 votes |
@Test public void testValidateAuthorizationPolicy() throws Exception { AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor(); TestSTSTokenValidator validator = new TestSTSTokenValidator(); in.setValidator(validator); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName("bob"); policy.setPassword("pswd"); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); in.handleMessage(message); assertTrue(validator.isValidated()); }
Example 2
Source File: AuthPolicyValidatingInterceptorTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testValidateAuthorizationPolicy() throws Exception { AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor(); TestSTSTokenValidator validator = new TestSTSTokenValidator(); in.setValidator(validator); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName("bob"); policy.setPassword("pswd"); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); in.handleMessage(message); assertTrue(validator.isValidated()); }
Example 3
Source File: AuthPolicyValidatingInterceptorTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testNoUsername() throws Exception { AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor(); TestSTSTokenValidator validator = new TestSTSTokenValidator(); in.setValidator(validator); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setPassword("pswd"); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); try { in.handleMessage(message); fail("Failure expected with no username"); } catch (SecurityException ex) { // expected } }
Example 4
Source File: HTTPConduitURLEasyMockTest.java From cxf with Apache License 2.0 | 6 votes |
private void setUpHeaders(Message message) { Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); List<String> contentTypes = new ArrayList<>(); contentTypes.add("text/xml;charset=utf8"); headers.put("content-type", contentTypes); List<String> acceptTypes = new ArrayList<>(); acceptTypes.add("text/xml;charset=utf8"); acceptTypes.add("text/plain"); headers.put("Accept", acceptTypes); message.put(Message.PROTOCOL_HEADERS, headers); AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName("BJ"); authPolicy.setPassword("value"); message.put(AuthorizationPolicy.class, authPolicy); }
Example 5
Source File: AuthPolicyValidatingInterceptorTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testInvalidUsernamePassword() throws Exception { AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor(); TestSTSTokenValidator validator = new TestSTSTokenValidator(); in.setValidator(validator); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName("bob"); policy.setPassword("pswd2"); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); in.handleMessage(message); assertFalse(validator.isValidated()); }
Example 6
Source File: AuthPolicyValidatingInterceptorTest.java From steady with Apache License 2.0 | 6 votes |
@Test public void testValidateAuthorizationPolicy() throws Exception { AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor(); TestSTSTokenValidator validator = new TestSTSTokenValidator(); in.setValidator(validator); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName("bob"); policy.setPassword("pswd"); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); in.handleMessage(message); assertTrue(validator.isValidated()); }
Example 7
Source File: AuthPolicyValidatingInterceptorTest.java From steady with Apache License 2.0 | 6 votes |
@Test public void testValidateAuthorizationPolicy() throws Exception { AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor(); TestSTSTokenValidator validator = new TestSTSTokenValidator(); in.setValidator(validator); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName("bob"); policy.setPassword("pswd"); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); in.handleMessage(message); assertTrue(validator.isValidated()); }
Example 8
Source File: UndertowDigestAuthTest.java From cxf with Apache License 2.0 | 5 votes |
public void configure(String name, String address, HTTPConduit c) { AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy(); authorizationPolicy.setUserName("ffang"); authorizationPolicy.setPassword("pswd"); authorizationPolicy.setAuthorizationType("Digest"); c.setAuthorization(authorizationPolicy); }
Example 9
Source File: ClientServerWebSocketTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testBasicAuth() throws Exception { URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl"); assertNotNull(wsdl); SOAPService service = new SOAPService(wsdl, serviceName); Greeter greeter = service.getPort(portName, Greeter.class); updateGreeterAddress(greeter, PORT); try { //try the jaxws way BindingProvider bp = (BindingProvider)greeter; bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "BJ"); bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd"); String s = greeter.greetMe("secure"); assertEquals("Hello BJ", s); bp.getRequestContext().remove(BindingProvider.USERNAME_PROPERTY); bp.getRequestContext().remove(BindingProvider.PASSWORD_PROPERTY); ((Closeable)greeter).close(); greeter = service.getPort(portName, Greeter.class); updateGreeterAddress(greeter, PORT); //try setting on the conduit directly Client client = ClientProxy.getClient(greeter); HTTPConduit httpConduit = (HTTPConduit)client.getConduit(); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName("BJ2"); policy.setPassword("pswd"); httpConduit.setAuthorization(policy); s = greeter.greetMe("secure"); ((Closeable)greeter).close(); assertEquals("Hello BJ2", s); } catch (UndeclaredThrowableException ex) { throw (Exception)ex.getCause(); } }
Example 10
Source File: ClientServerTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testBasicAuth() throws Exception { Service service = Service.create(serviceName); service.addPort(fakePortName, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + PORT + "/SoapContext/SoapPort"); Greeter greeter = service.getPort(fakePortName, Greeter.class); try { //try the jaxws way BindingProvider bp = (BindingProvider)greeter; bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "BJ"); bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd"); String s = greeter.greetMe("secure"); assertEquals("Hello BJ", s); bp.getRequestContext().remove(BindingProvider.USERNAME_PROPERTY); bp.getRequestContext().remove(BindingProvider.PASSWORD_PROPERTY); //try setting on the conduit directly Client client = ClientProxy.getClient(greeter); HTTPConduit httpConduit = (HTTPConduit)client.getConduit(); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName("BJ2"); policy.setPassword("pswd"); httpConduit.setAuthorization(policy); s = greeter.greetMe("secure"); assertEquals("Hello BJ2", s); } catch (UndeclaredThrowableException ex) { throw (Exception)ex.getCause(); } }
Example 11
Source File: JAXRSKerberosBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookWithInterceptor() throws Exception { if (!runTests) { return; } WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/123"); KerberosAuthOutInterceptor kbInterceptor = new KerberosAuthOutInterceptor(); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_NEGOTIATE); policy.setAuthorization("alice"); policy.setUserName("alice"); policy.setPassword("alice"); kbInterceptor.setPolicy(policy); kbInterceptor.setCredDelegation(true); WebClient.getConfig(wc).getOutInterceptors().add(new LoggingOutInterceptor()); WebClient.getConfig(wc).getOutInterceptors().add(kbInterceptor); // Required so as to get it working with our KDC kbInterceptor.setServicePrincipalName("[email protected]"); kbInterceptor.setServiceNameType(GSSName.NT_HOSTBASED_SERVICE); Book b = wc.get(Book.class); Assert.assertEquals(b.getId(), 123); }
Example 12
Source File: JAASResourceOwnerLoginHandler.java From cxf with Apache License 2.0 | 5 votes |
private Message setupMessage(String name, String password) { AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName(name); policy.setPassword(password); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); return message; }
Example 13
Source File: JettyBasicAuthTest.java From cxf with Apache License 2.0 | 5 votes |
public void configure(String name, String address, HTTPConduit c) { AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy(); authorizationPolicy.setUserName("ffang"); authorizationPolicy.setPassword("pswd"); authorizationPolicy.setAuthorizationType("Basic"); c.setAuthorization(authorizationPolicy); }
Example 14
Source File: DigestAuthTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testDigestAuth() throws Exception { URL wsdl = getClass().getResource("../greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter mortimer = service.getPort(mortimerQ, Greeter.class); assertNotNull("Port is null", mortimer); TestUtil.setAddress(mortimer, "http://localhost:" + PORT + "/digestauth/greeter"); Client client = ClientProxy.getClient(mortimer); HTTPConduit http = (HTTPConduit) client.getConduit(); AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setAuthorizationType("Digest"); authPolicy.setUserName("foo"); authPolicy.setPassword("bar"); http.setAuthorization(authPolicy); String answer = mortimer.sayHi(); assertEquals("Unexpected answer: " + answer, "Hi", answer); }
Example 15
Source File: JAXRSClientFactoryBean.java From cxf with Apache License 2.0 | 4 votes |
protected void initClient(AbstractClient client, Endpoint ep, boolean addHeaders) { if (username != null) { AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName(username); authPolicy.setPassword(password); ep.getEndpointInfo().addExtensor(authPolicy); } client.getConfiguration().setConduitSelector(getConduitSelector(ep)); client.getConfiguration().setBus(getBus()); client.getConfiguration().getOutInterceptors().addAll(getOutInterceptors()); client.getConfiguration().getOutInterceptors().addAll(ep.getOutInterceptors()); client.getConfiguration().getInInterceptors().addAll(getInInterceptors()); client.getConfiguration().getInInterceptors().addAll(ep.getInInterceptors()); client.getConfiguration().getInFaultInterceptors().addAll(getInFaultInterceptors()); applyFeatures(client); if (headers != null && addHeaders) { client.headers(headers); } ClientProviderFactory factory = ClientProviderFactory.createInstance(getBus()); setupFactory(factory, ep); final Map<String, Object> theProperties = super.getProperties(); final boolean encodeClientParameters = PropertyUtils.isTrue(theProperties, "url.encode.client.parameters"); if (encodeClientParameters) { final String encodeClientParametersList = (String)getProperties().get("url.encode.client.parameters.list"); factory.registerUserProvider(new ParamConverterProvider() { @SuppressWarnings("unchecked") @Override public <T> ParamConverter<T> getConverter(Class<T> cls, Type t, Annotation[] anns) { if (cls == String.class && AnnotationUtils.getAnnotation(anns, HeaderParam.class) == null && AnnotationUtils.getAnnotation(anns, CookieParam.class) == null) { return (ParamConverter<T>) new UrlEncodingParamConverter(encodeClientParametersList); } return null; } }); } }
Example 16
Source File: HTTPSConduitTest.java From cxf with Apache License 2.0 | 4 votes |
/** * This methods tests a basic https connection to Bethal. * It supplies an authorization policy with premetive user/pass * to avoid the 401. */ @Test public void testHttpsBasicConnection() throws Exception { startServer("Bethal"); URL wsdl = getClass().getResource("greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter bethal = service.getPort(bethalQ, Greeter.class); assertNotNull("Port is null", bethal); updateAddressPort(bethal, getPort("PORT4")); // Okay, I'm sick of configuration files. // This also tests dynamic configuration of the conduit. Client client = ClientProxy.getClient(bethal); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAutoRedirect(false); // If we set any name, but Edward, Mary, or George, // and a password of "password" we will get through // Bethal. AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName("Betty"); authPolicy.setPassword("password"); http.setClient(httpClientPolicy); http.setTlsClientParameters(tlsClientParameters); http.setAuthorization(authPolicy); configureProxy(client); String answer = bethal.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer)); assertProxyRequestCount(0); }
Example 17
Source File: HTTPSConduitTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testHttpsTrust() throws Exception { startServer("Bethal"); URL wsdl = getClass().getResource("greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter bethal = service.getPort(bethalQ, Greeter.class); assertNotNull("Port is null", bethal); updateAddressPort(bethal, getPort("PORT4")); // Okay, I'm sick of configuration files. // This also tests dynamic configuration of the conduit. Client client = ClientProxy.getClient(bethal); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAutoRedirect(false); // If we set any name, but Edward, Mary, or George, // and a password of "password" we will get through // Bethal. AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName("Betty"); authPolicy.setPassword("password"); http.setClient(httpClientPolicy); http.setTlsClientParameters(tlsClientParameters); http.setAuthorization(authPolicy); // Our expected server should be OU=Bethal http.setTrustDecider(new MyHttpsTrustDecider("Bethal")); configureProxy(client); String answer = bethal.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer)); assertProxyRequestCount(0); // Nobody will not equal OU=Bethal MyHttpsTrustDecider trustDecider = new MyHttpsTrustDecider("Nobody"); http.setTrustDecider(trustDecider); try { answer = bethal.sayHi(); fail("Unexpected answer from Bethal: " + answer); } catch (Exception e) { //e.printStackTrace(); //assertTrue("Trust Decider was not called", // 0 > trustDecider.wasCalled()); } assertProxyRequestCount(0); }
Example 18
Source File: HTTPConduitTest.java From cxf with Apache License 2.0 | 4 votes |
/** * This test verifies the precedence of Authorization Information. * Setting authorization information on the Message takes precedence * over a Basic Auth Supplier with preemptive UserPass, and that * followed by setting it directly on the Conduit. */ @Test public void testAuthPolicyPrecedence() throws Exception { Bus bus = new ExtensionManagerBus(); EndpointInfo ei = new EndpointInfo(); ei.setAddress("http://nowhere.com/bar/foo"); HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null); conduit.finalizeConfig(); conduit.getAuthorization().setUserName("Satan"); conduit.getAuthorization().setPassword("hell"); Message message = getNewMessage(); // Test call conduit.prepare(message); Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); assertNotNull("Authorization Header should exist", headers.get("Authorization")); assertEquals("Unexpected Authorization Token", DefaultBasicAuthSupplier.getBasicAuthHeader("Satan", "hell"), headers.get("Authorization").get(0)); // Setting a Basic Auth User Pass should override conduit.setAuthSupplier(new TestAuthSupplier()); message = getNewMessage(); // Test Call conduit.prepare(message); headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); List<String> authorization = headers.get("Authorization"); assertNotNull("Authorization Token must be set", authorization); assertEquals("Wrong Authorization Token", "myauth", authorization.get(0)); conduit.setAuthSupplier(null); // Setting authorization policy on the message should override // conduit setting AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName("Hello"); authPolicy.setPassword("world"); authPolicy.setAuthorizationType("Basic"); message = getNewMessage(); message.put(AuthorizationPolicy.class, authPolicy); conduit.prepare(message); headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); assertEquals("Unexpected Authorization Token", DefaultBasicAuthSupplier.getBasicAuthHeader("Hello", "world"), headers.get("Authorization").get(0)); }
Example 19
Source File: JAASLoginInterceptorTest.java From cxf with Apache License 2.0 | 4 votes |
private void addAuthPolicy(Message message, String username, String password) { AuthorizationPolicy authPol = new AuthorizationPolicy(); authPol.setUserName(username); authPol.setPassword(password); message.put(AuthorizationPolicy.class, authPol); }
Example 20
Source File: ClientProxyFactoryBean.java From cxf with Apache License 2.0 | 4 votes |
/** * Creates a proxy object that can be used to make remote invocations. * * @return the proxy. You must cast the returned object to the appropriate class before using it. */ public synchronized Object create() { ClassLoaderHolder orig = null; ClassLoader loader = null; try { if (getBus() != null) { loader = getBus().getExtension(ClassLoader.class); if (loader != null) { orig = ClassLoaderUtils.setThreadContextClassloader(loader); } } configureObject(); if (properties == null) { properties = new HashMap<>(); } if (username != null) { AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName(username); authPolicy.setPassword(password); properties.put(AuthorizationPolicy.class.getName(), authPolicy); } initFeatures(); clientFactoryBean.setProperties(properties); if (bus != null) { clientFactoryBean.setBus(bus); } if (dataBinding != null) { clientFactoryBean.setDataBinding(dataBinding); } Client c = clientFactoryBean.create(); if (getInInterceptors() != null) { c.getInInterceptors().addAll(getInInterceptors()); } if (getOutInterceptors() != null) { c.getOutInterceptors().addAll(getOutInterceptors()); } if (getInFaultInterceptors() != null) { c.getInFaultInterceptors().addAll(getInFaultInterceptors()); } if (getOutFaultInterceptors() != null) { c.getOutFaultInterceptors().addAll(getOutFaultInterceptors()); } ClientProxy handler = clientClientProxy(c); Class<?>[] classes = getImplementingClasses(); Object obj = ProxyHelper.getProxy(getClassLoader(clientFactoryBean.getServiceClass()), classes, handler); this.getServiceFactory().sendEvent(FactoryBeanListener.Event.PROXY_CREATED, classes, handler, obj); return obj; } finally { if (orig != null) { orig.reset(); } } }