<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Developers, Developers, Developers! &#187; security</title>
	<atom:link href="http://maksim.sorokin.dk/it/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://maksim.sorokin.dk/it</link>
	<description>Maksim Sorokin IT Blog</description>
	<lastBuildDate>Sun, 05 Feb 2012 19:37:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Maven + Apache Felix + CXF: Securing a Service with HTTP Basic Authentication</title>
		<link>http://maksim.sorokin.dk/it/2011/08/06/maven-apache-felix-cxf-securing-a-service-with-http-basic-authentication/</link>
		<comments>http://maksim.sorokin.dk/it/2011/08/06/maven-apache-felix-cxf-securing-a-service-with-http-basic-authentication/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 08:35:32 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[basic authentication]]></category>
		<category><![CDATA[CXF]]></category>
		<category><![CDATA[DOSGi]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=808</guid>
		<description><![CDATA[This is another post in series Maven + Apache Felix + CXF + DOSGi Series. Here I will describe how to secure CXF published web services with HTTP basic authentication. You can find the sources on my GitHub account. We will have three projects here. The first one defines an interface for a service. Another [...]]]></description>
			<content:encoded><![CDATA[<p>This is another post in series <a href="http://maksim.sorokin.dk/it/2011/07/19/maven-apache-felix-cxf-dosgi-series/">Maven + Apache Felix + CXF + DOSGi Series</a>. Here I will describe how to secure CXF published web services with HTTP basic authentication. You can find the sources on <a href="https://github.com/mah01/examples/tree/master/dosgiSecurity">my GitHub account</a>.</p>
<p>We will have three projects here. The first one defines an interface for a service. Another one provides implementation for it. And the third one will provide security.</p>
<pre class="brush: plain; title: ;">
dosgiSecurity
    dosgiSecurity-api
    dosgiSecurity-impl
    dosgiSecurity-security
</pre>
<p><code>dosgiSecurity</code> will be just a holder project.</p>
<p>Our interface <code>HelloService</code> in bundle <code>dosgiSecurity-api</code> will be similar to the one we defined in<span id="more-808"></span> previous posts:</p>
<pre class="brush: java; title: ;">
package dk.sorokin.maksim.dosgiSecurity.api;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path(&quot;helloService&quot;)
public interface HelloService {

  @GET
  @Path(&quot;sayHello/{name}&quot;)
  @Produces(MediaType.TEXT_PLAIN)
  String sayHello(@PathParam(&quot;name&quot;) String name);
}
</pre>
<p>And implementation class <code>HelloServiceImpl</code> in bundle <code>dosgiSecurity-impl</code>:</p>
<pre class="brush: java; title: ;">
package dk.sorokin.maksim.dosgiSecurity.impl.internal.service;

import dk.sorokin.maksim.dosgiSecurity.api.HelloService;

public class HelloServiceImpl implements HelloService {

  public String sayHello(String name) {
    return &quot;Hello &quot; + name;
  }
}
</pre>
<p>And <code>SecurityFilter</code> in bundle <code>dosgiSecurity-security</code>, is just a servlet filter. It checks for <code>Authorization</code> header and verifies it:</p>
<pre class="brush: java; title: ;">
package dk.sorokin.maksim.dosgiSecurity.impl.internal.service;

import dk.sorokin.maksim.dosgiSecurity.api.HelloService;

public class HelloServiceImpl implements HelloService {

  public String sayHello(String name) {
    return &quot;Hello &quot; + name;
  }
}
</pre>
<p>The service is published in an <code>Activator</code> in <code>dosgiSecurity.impl</code>:</p>
<pre class="brush: java; title: ;">
package dk.sorokin.maksim.dosgiSecurity.impl.internal;

import java.util.Dictionary;
import java.util.Hashtable;

import javax.servlet.Filter;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import dk.sorokin.maksim.dosgiSecurity.api.HelloService;
import dk.sorokin.maksim.dosgiSecurity.impl.internal.service.HelloServiceImpl;
import dk.sorokin.maksim.dosgiSecurity.security.SecurityFilter;

public class Activator implements BundleActivator {

  public void start(BundleContext context) throws Exception {
    Dictionary&lt;String, String&gt; restProps = new Hashtable&lt;String, String&gt;();

    restProps.put(&quot;service.exported.interfaces&quot;, &quot;*&quot;);
    restProps.put(&quot;service.exported.configs&quot;, &quot;org.apache.cxf.rs&quot;);
    restProps.put(&quot;service.exported.intents&quot;, &quot;HTTP&quot;);
    restProps.put(&quot;org.apache.cxf.rs.httpservice.context&quot;, &quot;/secured&quot;);
    restProps.put(&quot;org.apache.cxf.rs.address&quot;, &quot;http://localhost:8080/&quot;);
    context.registerService(HelloService.class.getName(), new HelloServiceImpl(), restProps);

    Dictionary&lt;String, String&gt; filterProps = new Hashtable&lt;String, String&gt;();
    filterProps.put(&quot;org.apache.cxf.httpservice.filter&quot;, Boolean.TRUE.toString());
    filterProps.put(&quot;servletNames&quot;, &quot;none&quot;);
    context.registerService(Filter.class.getName(), new SecurityFilter(), filterProps);
  }

  public void stop(BundleContext context) throws Exception {
    //
  }
}
</pre>
<p>And a Felix Launcher (refer to the <a href="http://maksim.sorokin.dk/it/2011/07/19/maven-apache-felix-easy-development-and-debugging-with-eclipse/">first post in series</a>) is:</p>
<pre class="brush: plain; title: ;">
felix.auto.deploy.action=install,start
felix.log.level=1

org.osgi.framework.storage.clean=onFirstInit

felix.auto.start.1 = \
 assembly:/C:/projects/dosgiSecurity/dosgiSecurity.security/target/classes \
 assembly:/C:/projects/dosgiSecurity/dosgiSecurity.api/target/classes \
 assembly:/C:/projects/dosgiSecurity/dosgiSecurity.impl/target/classes
</pre>
<p>Now build all that with Maven using <code>mvn clean install</code> and run it (assuming that you have DOSGi Single Bundle Distribution in Felix, as we discussed in previous posts). When Felix is launched, go to <a href="http://localhost:8080/secured/helloService/sayHello/Max">http://localhost:8080/secured/helloService/sayHello/Max</a>. You should see:</p>
<pre class="brush: plain; title: ;">
HTTP ERROR: 403

FORBIDDEN
RequestURI=/secured/helloService/sayHello/Max

Powered by Jetty://
</pre>
<p>Now launch Fiddler2 (or similar program) and build custom request with Request Builder with the same url as shown above. And add the following line in "Request Headers":</p>
<pre class="brush: plain; title: ;">
Authorization: Basic U3V6eTpyb2NrZXQ=
</pre>
<p>You should get:</p>
<pre class="brush: plain; title: ;">
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Tue, 02 Aug 2011 15:15:43 GMT
Content-Length: 9
Server: Jetty(6.1.x)

Hello max
</pre>
<p>Source files can be found <a href="https://github.com/mah01/examples/tree/master/dosgiSecurity">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2011/08/06/maven-apache-felix-cxf-securing-a-service-with-http-basic-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx Basic Authentication on Windows</title>
		<link>http://maksim.sorokin.dk/it/2010/12/26/nginx-basic-authentication-on-windows/</link>
		<comments>http://maksim.sorokin.dk/it/2010/12/26/nginx-basic-authentication-on-windows/#comments</comments>
		<pubDate>Sun, 26 Dec 2010 22:51:49 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[basic authentication]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=470</guid>
		<description><![CDATA[Nginx supports only plain passwords file without any encryption on Windows! Totaly crazy! That means, intead of: mah:6hpon1QBxl45M One has to have plain password: mah:secret]]></description>
			<content:encoded><![CDATA[<p>Nginx supports only plain passwords file without any encryption on Windows! Totaly crazy! That means, intead of:</p>
<pre class="brush: plain; title: ;">
mah:6hpon1QBxl45M
</pre>
<p>One has to have plain password:</p>
<pre class="brush: plain; title: ;">
mah:secret
</pre>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/12/26/nginx-basic-authentication-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Authentication in GlassFish 3</title>
		<link>http://maksim.sorokin.dk/it/2010/10/13/basic-authentication-in-glassfish-3/</link>
		<comments>http://maksim.sorokin.dk/it/2010/10/13/basic-authentication-in-glassfish-3/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 16:23:44 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[basic authentication]]></category>
		<category><![CDATA[GlassFish]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=389</guid>
		<description><![CDATA[Here is asmall basic authentication how-to for a web application in GlassFish 3. Open GlassFish Administrative Console. Go to Security-&#62;Realms-&#62;file. Change Assign Groups to Users. In the top of the page click Manage Users. Click New. Specify User ID and Password. In Group List fill Users. In your web.xml add the following: &#60;web-app&#62; ... &#60;security-constraint&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Here is asmall basic authentication how-to for a web application in GlassFish 3.</p>
<p>Open GlassFish Administrative Console. Go to <span id="more-389"></span><em>Security-&gt;Realms-&gt;file</em>.<br />
Change <em>Assign Groups</em> to <em>Users</em>.<br />
In the top of the page click <em>Manage Users</em>.<br />
Click <em>New</em>. Specify <em>User ID</em> and <em>Password</em>. In <em>Group List</em> fill <em>Users</em>.</p>
<p>In your <code>web.xml</code> add the following:</p>
<pre class="brush: xml; title: ;">
&lt;web-app&gt;
...

  &lt;security-constraint&gt;
    &lt;web-resource-collection&gt;
        &lt;web-resource-name&gt;Secure Application&lt;/web-resource-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
        &lt;http-method&gt;GET&lt;/http-method&gt;
        &lt;http-method&gt;POST&lt;/http-method&gt;
    &lt;/web-resource-collection&gt;

    &lt;auth-constraint&gt;
        &lt;role-name&gt;Users&lt;/role-name&gt;
    &lt;/auth-constraint&gt;
  &lt;/security-constraint&gt;

  &lt;login-config&gt;
    &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
	&lt;realm-name&gt;file&lt;/realm-name&gt;
  &lt;/login-config&gt;

  &lt;security-role&gt;
	&lt;role-name&gt;Users&lt;/role-name&gt;
  &lt;/security-role&gt;
...
&lt;/web-app&gt;
</pre>
<p>If you do not have <code>sun-web.xml</code> file, create one and place it the same folder as <code>web.xml</code>.<br />
Define the following in <code>sun-web.xml</code>:</p>
<pre class="brush: xml; title: ;">
&lt;sun-web-app error-url=&quot;&quot;&gt;
...
  &lt;security-role-mapping&gt;
    &lt;role-name&gt;Users&lt;/role-name&gt;
    &lt;group-name&gt;Users&lt;/group-name&gt;
  &lt;/security-role-mapping&gt;
&lt;/sun-web-app&gt;
</pre>
<p>Note, that <code>sun-web.xml</code> has additional section <code>security-role-mapping</code>.</p>
<p>UPD.: Thanks to user "chrome" for clarifying needed section in <code>sun-web.xml</code> file.</p>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/10/13/basic-authentication-in-glassfish-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Enable Directory Listings in GlassFish</title>
		<link>http://maksim.sorokin.dk/it/2010/07/03/enable-directory-listings-in-glassfish/</link>
		<comments>http://maksim.sorokin.dk/it/2010/07/03/enable-directory-listings-in-glassfish/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 08:24:30 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[GlassFish]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=268</guid>
		<description><![CDATA[There is a default-web.xml file in GlassFish which configure some stuff behind the scenes. This file can be found in domains-&#62;domain-&#62;config folder. By default, in GlassFish v3 directory listing is disabled. But one can easily enable it by modifying default-web.xml file: &#60;init-param&#62; &#60;param-name&#62;debug&#60;/param-name&#62; &#60;param-value&#62;0&#60;/param-value&#62; &#60;/init-param&#62; Or if there is no possibility to modify the default-web.xml [...]]]></description>
			<content:encoded><![CDATA[<p>There is a <code>default-web.xml</code> file in GlassFish which configure some stuff behind the scenes. This file can be found in domains-&gt;domain-&gt;config folder.</p>
<p>By default, in GlassFish v3 directory listing is disabled. But one can easily enable it by modifying <code>default-web.xml</code> file:</p>
<pre class="brush: xml; title: ;">
&lt;init-param&gt;
  &lt;param-name&gt;debug&lt;/param-name&gt;
  &lt;param-value&gt;0&lt;/param-value&gt;
&lt;/init-param&gt;
</pre>
<p>Or if there is no possibility to modify the <code>default-web.xml</code> directly, <span id="more-268"></span>add the following to your <code>web.xml</code>:</p>
<pre class="brush: xml; title: ;">
  &lt;!-- Allow directory listing --&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;default&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.apache.catalina.servlets.DefaultServlet&lt;/servlet-class&gt;
    &lt;init-param&gt;
      &lt;param-name&gt;debug&lt;/param-name&gt;
      &lt;param-value&gt;0&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;init-param&gt;
      &lt;param-name&gt;listings&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;default&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/07/03/enable-directory-listings-in-glassfish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A New Book About GlassFish Security</title>
		<link>http://maksim.sorokin.dk/it/2010/05/20/a-new-book-about-glassfish-security/</link>
		<comments>http://maksim.sorokin.dk/it/2010/05/20/a-new-book-about-glassfish-security/#comments</comments>
		<pubDate>Thu, 20 May 2010 11:05:21 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[GlassFish]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE 6]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=195</guid>
		<description><![CDATA[I was granted a book from Packt about GlassFish Security. And that is something we want to improve in our products! The book is about security in Java EE with EJB, Application Client modules and all the friends. Security in GlassFish is a central point of this book. And what is more, there are plenty [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://maksim.sorokin.dk/it/wp-content/uploads/2010/05/glassfish_security_cover.png"><img class="alignleft size-full wp-image-196" src="http://maksim.sorokin.dk/it/wp-content/uploads/2010/05/glassfish_security_cover.png" alt="GlassFish Security Cover" width="125" height="152" /></a></p>
<p>I was granted a <a href="http://www.packtpub.com/glassfish-security-with-java-ee/book?utm_source=maksim.sorokin.dk&amp;utm_medium=bookrev&amp;utm_content=blog&amp;utm_campaign=mdb_003418">book</a> from <a href="http://www.packtpub.com/">Packt</a> about GlassFish Security. And that is something we want to improve in our products!</p>
<p>The book is about security in Java EE with EJB, Application Client modules and all the friends. Security in GlassFish is a central point of this book. And what is more, there are plenty of real world code and configuration samples. More information about the book can be found on <a href="http://www.packtpub.com/glassfish-security-with-java-ee/book?utm_source=maksim.sorokin.dk&amp;utm_medium=bookrev&amp;utm_content=blog&amp;utm_campaign=mdb_003418">dedicated page on Packt website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/05/20/a-new-book-about-glassfish-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

