1 package com.atlassian.sal.core.net.auth;
2
3 import com.atlassian.sal.core.trusted.CertificateFactory;
4 import com.atlassian.security.auth.trustedapps.EncryptedCertificate;
5 import org.apache.http.Header;
6 import org.apache.http.HttpRequest;
7 import org.apache.http.auth.AuthenticationException;
8 import org.apache.http.auth.ContextAwareAuthScheme;
9 import org.apache.http.auth.Credentials;
10 import org.apache.http.auth.MalformedChallengeException;
11 import org.apache.http.client.methods.HttpRequestWrapper;
12 import org.apache.http.protocol.BasicHttpContext;
13 import org.apache.http.protocol.HttpContext;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class TrustedTokenScheme implements ContextAwareAuthScheme
18 {
19
20 private static final Logger log = LoggerFactory.getLogger(TrustedTokenScheme.class);
21
22 private final CertificateFactory certificateFactory;
23
24 public TrustedTokenScheme(final CertificateFactory certificateFactory)
25 {
26 this.certificateFactory = certificateFactory;
27 }
28
29 @Override
30 public Header authenticate(final Credentials credentials, final HttpRequest request, final HttpContext context)
31 throws AuthenticationException
32 {
33
34 final String username = credentials.getUserPrincipal().getName();
35 final String url = ((HttpRequestWrapper) request).getOriginal().getRequestLine().getUri();
36
37 EncryptedCertificate certificate = certificateFactory.createCertificate(username, url);
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 return null;
64 }
65
66 @Override
67 public void processChallenge(final Header header) throws MalformedChallengeException
68 {
69 log.warn("Ignoring a call to processChallenge as TrustedTokenScheme is intended for preemptive authentication only.");
70 }
71
72 @Override
73 public String getSchemeName()
74 {
75 return "trustedtoken";
76 }
77
78 @Override
79 public String getParameter(final String name)
80 {
81 throw new UnsupportedOperationException("Not implemented");
82 }
83
84 @Override
85 public String getRealm()
86 {
87 throw new UnsupportedOperationException("Not implemented");
88 }
89
90 @Override
91 public boolean isConnectionBased()
92 {
93 return false;
94 }
95
96 @Override
97 public boolean isComplete()
98 {
99 return true;
100 }
101
102 @Override
103 public Header authenticate(final Credentials credentials, final HttpRequest request) throws AuthenticationException
104 {
105 return authenticate(credentials, request, new BasicHttpContext());
106 }
107
108 }