This project has retired. For details please refer to its
Attic page.
HttpDigestAuthenticationFilter xref
1 package org.apache.archiva.redback.integration.filter.authentication.digest;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.archiva.redback.authentication.AuthenticationException;
23 import org.apache.archiva.redback.integration.filter.authentication.AbstractHttpAuthenticationFilter;
24 import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
25 import org.apache.archiva.redback.integration.filter.authentication.basic.HttpBasicAuthentication;
26
27 import javax.servlet.FilterChain;
28 import javax.servlet.FilterConfig;
29 import javax.servlet.ServletException;
30 import javax.servlet.ServletRequest;
31 import javax.servlet.ServletResponse;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import java.io.IOException;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class HttpDigestAuthenticationFilter
50 extends AbstractHttpAuthenticationFilter
51 {
52 private HttpDigestAuthentication httpAuthentication;
53
54 @Override
55 public void init( FilterConfig filterConfig )
56 throws ServletException
57 {
58 super.init( filterConfig );
59
60 httpAuthentication =
61 getApplicationContext().getBean( "httpAuthenticator#digest", HttpDigestAuthentication.class );
62
63 }
64
65 public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain )
66 throws IOException, ServletException
67 {
68 if ( !( request instanceof HttpServletRequest ) )
69 {
70 throw new ServletException( "Can only process HttpServletRequest" );
71 }
72
73 if ( !( response instanceof HttpServletResponse ) )
74 {
75 throw new ServletException( "Can only process HttpServletResponse" );
76 }
77
78 HttpServletRequest httpRequest = (HttpServletRequest) request;
79 HttpServletResponse httpResponse = (HttpServletResponse) response;
80
81 try
82 {
83 httpAuthentication.setRealm( getRealmName() );
84 httpAuthentication.authenticate( httpRequest, httpResponse );
85 }
86 catch ( AuthenticationException e )
87 {
88 HttpAuthenticator httpauthn = new HttpBasicAuthentication();
89 httpauthn.challenge( httpRequest, httpResponse, getRealmName(), e );
90 return;
91 }
92
93 chain.doFilter( request, response );
94 }
95
96 }