1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.james.nntpserver;
23
24 import org.apache.avalon.framework.configuration.Configuration;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26 import org.apache.avalon.framework.service.ServiceException;
27 import org.apache.avalon.framework.service.ServiceManager;
28 import org.apache.james.api.user.UsersRepository;
29 import org.apache.james.nntpserver.repository.NNTPRepository;
30 import org.apache.james.services.MailServer;
31 import org.apache.james.socket.AbstractJamesService;
32 import org.apache.james.socket.ProtocolHandler;
33
34
35
36
37
38 public class NNTPServer extends AbstractJamesService implements NNTPServerMBean {
39
40
41
42
43 private boolean authRequired = false;
44
45
46
47
48 private NNTPRepository nntpRepository;
49
50
51
52
53 private UsersRepository userRepository = null;
54
55 private MailServer mailServer;
56
57
58
59
60
61
62 public void setUserRepository(UsersRepository userRepository) {
63 this.userRepository = userRepository;
64 }
65
66
67
68
69
70
71 public void setRepository(NNTPRepository nntpRepository) {
72 this.nntpRepository = nntpRepository;
73 }
74
75 public void setMailServer(MailServer mailServer) {
76 this.mailServer = mailServer;
77 }
78
79
80
81
82 private NNTPHandlerConfigurationData theConfigData
83 = new NNTPHandlerConfigurationDataImpl();
84
85
86
87
88 public void service( final ServiceManager componentManager )
89 throws ServiceException {
90 super.service(componentManager);
91 UsersRepository userRepository = (UsersRepository)componentManager.lookup(UsersRepository.ROLE);
92 setUserRepository(userRepository);
93
94 NNTPRepository repo = (NNTPRepository)componentManager
95 .lookup(NNTPRepository.ROLE);
96 setRepository(repo);
97
98 setMailServer((MailServer) componentManager.lookup(MailServer.ROLE));
99 }
100
101
102
103
104 public void configure(final Configuration configuration) throws ConfigurationException {
105 super.configure(configuration);
106 if (isEnabled()) {
107 Configuration handlerConfiguration = configuration.getChild("handler");
108 authRequired =
109 handlerConfiguration.getChild("authRequired").getValueAsBoolean(false);
110 if (getLogger().isDebugEnabled()) {
111 if (authRequired) {
112 getLogger().debug("NNTP Server requires authentication.");
113 } else {
114 getLogger().debug("NNTP Server doesn't require authentication.");
115 }
116 }
117 }
118 }
119
120
121
122
123 protected int getDefaultPort() {
124 return 119;
125 }
126
127
128
129
130 public String getServiceType() {
131 return "NNTP Service";
132 }
133
134
135
136
137 public ProtocolHandler newProtocolHandlerInstance() {
138 return new NNTPHandler();
139 }
140
141
142
143
144 private class NNTPHandlerConfigurationDataImpl
145 implements NNTPHandlerConfigurationData {
146
147
148
149
150 public String getHelloName() {
151 if (NNTPServer.this.helloName == null) {
152 return NNTPServer.this.mailServer.getHelloName();
153 } else {
154 return NNTPServer.this.helloName;
155 }
156 }
157
158
159
160
161 public boolean isAuthRequired() {
162 return NNTPServer.this.authRequired;
163 }
164
165
166
167
168 public UsersRepository getUsersRepository() {
169 return NNTPServer.this.userRepository;
170 }
171
172
173
174
175 public NNTPRepository getNNTPRepository() {
176 return NNTPServer.this.nntpRepository;
177 }
178
179 }
180
181
182
183
184 protected Object getConfigurationData() {
185 return theConfigData;
186 }
187 }