You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SecuritySystemStub.java 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. package org.apache.archiva.web.rss;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.redback.authentication.AuthenticationDataSource;
  21. import org.apache.archiva.redback.authentication.AuthenticationException;
  22. import org.apache.archiva.redback.authentication.AuthenticationResult;
  23. import org.apache.archiva.redback.authorization.AuthorizationException;
  24. import org.apache.archiva.redback.authorization.AuthorizationResult;
  25. import org.apache.archiva.redback.keys.KeyManager;
  26. import org.apache.archiva.redback.policy.AccountLockedException;
  27. import org.apache.archiva.redback.policy.UserSecurityPolicy;
  28. import org.apache.archiva.redback.system.DefaultSecuritySession;
  29. import org.apache.archiva.redback.system.SecuritySession;
  30. import org.apache.archiva.redback.system.SecuritySystem;
  31. import org.apache.archiva.redback.users.User;
  32. import org.apache.archiva.redback.users.UserManager;
  33. import org.apache.archiva.redback.users.UserManagerException;
  34. import org.apache.archiva.redback.users.UserManagerListener;
  35. import org.apache.archiva.redback.users.UserNotFoundException;
  36. import org.apache.archiva.redback.users.UserQuery;
  37. import org.apache.archiva.redback.users.jdo.JdoUser;
  38. import java.util.ArrayList;
  39. import java.util.Date;
  40. import java.util.HashMap;
  41. import java.util.List;
  42. import java.util.Map;
  43. /**
  44. * SecuritySystem stub used for testing.
  45. */
  46. public class SecuritySystemStub
  47. implements SecuritySystem
  48. {
  49. Map<String, String> users = new HashMap<String, String>();
  50. List<String> repoIds = new ArrayList<>();
  51. public SecuritySystemStub()
  52. {
  53. users.put( "user1", "password1" );
  54. users.put( "user2", "password2" );
  55. users.put( "user3", "password3" );
  56. repoIds.add( "test-repo" );
  57. }
  58. public SecuritySession authenticate( AuthenticationDataSource source )
  59. throws AuthenticationException, UserNotFoundException, AccountLockedException
  60. {
  61. AuthenticationResult result = null;
  62. SecuritySession session = null;
  63. if ( users.get( source.getUsername() ) != null )
  64. {
  65. result = new AuthenticationResult( true, source.getUsername(), null );
  66. User user = new JdoUser();
  67. user.setUsername( source.getUsername() );
  68. user.setPassword( users.get( source.getUsername() ) );
  69. session = new DefaultSecuritySession( result, user );
  70. }
  71. else
  72. {
  73. result = new AuthenticationResult( false, source.getUsername(), null );
  74. session = new DefaultSecuritySession( result );
  75. }
  76. return session;
  77. }
  78. public AuthorizationResult authorize( SecuritySession arg0, String arg1 )
  79. throws AuthorizationException
  80. {
  81. return null;
  82. }
  83. public AuthorizationResult authorize( SecuritySession arg0, String arg1, String arg2 )
  84. throws AuthorizationException
  85. {
  86. AuthorizationResult result = new AuthorizationResult( true, arg1, null );
  87. return result;
  88. }
  89. public String getAuthenticatorId()
  90. {
  91. return null;
  92. }
  93. public String getAuthorizerId()
  94. {
  95. return null;
  96. }
  97. public KeyManager getKeyManager()
  98. {
  99. return null;
  100. }
  101. public UserSecurityPolicy getPolicy()
  102. {
  103. return null;
  104. }
  105. public String getUserManagementId()
  106. {
  107. return null;
  108. }
  109. public UserManager getUserManager()
  110. {
  111. return new UserManager()
  112. {
  113. public String getDescriptionKey()
  114. {
  115. return "French wine is better than Australian wine !";
  116. }
  117. public boolean isFinalImplementation()
  118. {
  119. return false;
  120. }
  121. public void initialize()
  122. {
  123. // no op
  124. }
  125. public boolean isReadOnly()
  126. {
  127. return false;
  128. }
  129. public String getId()
  130. {
  131. return null;
  132. }
  133. public void addUserManagerListener( UserManagerListener listener )
  134. {
  135. // no op
  136. }
  137. public void removeUserManagerListener( UserManagerListener listener )
  138. {
  139. // no op
  140. }
  141. public User createUser( String username, String fullName, String emailAddress )
  142. {
  143. return null;
  144. }
  145. public User createGuestUser()
  146. {
  147. return new User()
  148. {
  149. public String getUsername()
  150. {
  151. return "guest";
  152. }
  153. public void setUsername( String name )
  154. {
  155. }
  156. public String getFullName()
  157. {
  158. return null;
  159. }
  160. public void setFullName( String name )
  161. {
  162. //To change body of implemented methods use File | Settings | File Templates.
  163. }
  164. public String getEmail()
  165. {
  166. return null; //To change body of implemented methods use File | Settings | File Templates.
  167. }
  168. public void setEmail( String address )
  169. {
  170. //To change body of implemented methods use File | Settings | File Templates.
  171. }
  172. public String getPassword()
  173. {
  174. return null; //To change body of implemented methods use File | Settings | File Templates.
  175. }
  176. public void setPassword( String rawPassword )
  177. {
  178. //To change body of implemented methods use File | Settings | File Templates.
  179. }
  180. public String getEncodedPassword()
  181. {
  182. return null; //To change body of implemented methods use File | Settings | File Templates.
  183. }
  184. public void setEncodedPassword( String encodedPassword )
  185. {
  186. //To change body of implemented methods use File | Settings | File Templates.
  187. }
  188. public Date getLastPasswordChange()
  189. {
  190. return null; //To change body of implemented methods use File | Settings | File Templates.
  191. }
  192. public void setLastPasswordChange( Date passwordChangeDate )
  193. {
  194. //To change body of implemented methods use File | Settings | File Templates.
  195. }
  196. public List<String> getPreviousEncodedPasswords()
  197. {
  198. return null; //To change body of implemented methods use File | Settings | File Templates.
  199. }
  200. public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
  201. {
  202. //To change body of implemented methods use File | Settings | File Templates.
  203. }
  204. public void addPreviousEncodedPassword( String encodedPassword )
  205. {
  206. //To change body of implemented methods use File | Settings | File Templates.
  207. }
  208. public boolean isPermanent()
  209. {
  210. return false; //To change body of implemented methods use File | Settings | File Templates.
  211. }
  212. public void setPermanent( boolean permanent )
  213. {
  214. //To change body of implemented methods use File | Settings | File Templates.
  215. }
  216. public boolean isLocked()
  217. {
  218. return false; //To change body of implemented methods use File | Settings | File Templates.
  219. }
  220. public void setLocked( boolean locked )
  221. {
  222. //To change body of implemented methods use File | Settings | File Templates.
  223. }
  224. public boolean isPasswordChangeRequired()
  225. {
  226. return false; //To change body of implemented methods use File | Settings | File Templates.
  227. }
  228. public void setPasswordChangeRequired( boolean changeRequired )
  229. {
  230. //To change body of implemented methods use File | Settings | File Templates.
  231. }
  232. public boolean isValidated()
  233. {
  234. return false; //To change body of implemented methods use File | Settings | File Templates.
  235. }
  236. public void setValidated( boolean valid )
  237. {
  238. //To change body of implemented methods use File | Settings | File Templates.
  239. }
  240. public int getCountFailedLoginAttempts()
  241. {
  242. return 0; //To change body of implemented methods use File | Settings | File Templates.
  243. }
  244. public void setCountFailedLoginAttempts( int count )
  245. {
  246. //To change body of implemented methods use File | Settings | File Templates.
  247. }
  248. public Date getAccountCreationDate()
  249. {
  250. return null; //To change body of implemented methods use File | Settings | File Templates.
  251. }
  252. public void setAccountCreationDate( Date date )
  253. {
  254. //To change body of implemented methods use File | Settings | File Templates.
  255. }
  256. public Date getLastLoginDate()
  257. {
  258. return null; //To change body of implemented methods use File | Settings | File Templates.
  259. }
  260. public void setLastLoginDate( Date date )
  261. {
  262. //To change body of implemented methods use File | Settings | File Templates.
  263. }
  264. public String getUserManagerId()
  265. {
  266. return "mock";
  267. }
  268. };
  269. }
  270. public UserQuery createUserQuery()
  271. {
  272. return null; //To change body of implemented methods use File | Settings | File Templates.
  273. }
  274. public List<User> getUsers()
  275. {
  276. return null; //To change body of implemented methods use File | Settings | File Templates.
  277. }
  278. public List<User> getUsers( boolean orderAscending )
  279. {
  280. return null; //To change body of implemented methods use File | Settings | File Templates.
  281. }
  282. public User addUser( User user )
  283. {
  284. return null; //To change body of implemented methods use File | Settings | File Templates.
  285. }
  286. public User updateUser( User user )
  287. throws UserNotFoundException
  288. {
  289. return null; //To change body of implemented methods use File | Settings | File Templates.
  290. }
  291. public User findUser( String username )
  292. throws UserNotFoundException
  293. {
  294. return null; //To change body of implemented methods use File | Settings | File Templates.
  295. }
  296. @Override
  297. public User findUser( String username, boolean useCache )
  298. throws UserNotFoundException, UserManagerException
  299. {
  300. return null;
  301. }
  302. public User getGuestUser()
  303. throws UserNotFoundException
  304. {
  305. return new User()
  306. {
  307. public String getUsername()
  308. {
  309. return "guest";
  310. }
  311. public void setUsername( String name )
  312. {
  313. }
  314. public String getFullName()
  315. {
  316. return null; //To change body of implemented methods use File | Settings | File Templates.
  317. }
  318. public void setFullName( String name )
  319. {
  320. //To change body of implemented methods use File | Settings | File Templates.
  321. }
  322. public String getEmail()
  323. {
  324. return null; //To change body of implemented methods use File | Settings | File Templates.
  325. }
  326. public void setEmail( String address )
  327. {
  328. //To change body of implemented methods use File | Settings | File Templates.
  329. }
  330. public String getPassword()
  331. {
  332. return null; //To change body of implemented methods use File | Settings | File Templates.
  333. }
  334. public void setPassword( String rawPassword )
  335. {
  336. //To change body of implemented methods use File | Settings | File Templates.
  337. }
  338. public String getEncodedPassword()
  339. {
  340. return null; //To change body of implemented methods use File | Settings | File Templates.
  341. }
  342. public void setEncodedPassword( String encodedPassword )
  343. {
  344. //To change body of implemented methods use File | Settings | File Templates.
  345. }
  346. public Date getLastPasswordChange()
  347. {
  348. return null; //To change body of implemented methods use File | Settings | File Templates.
  349. }
  350. public void setLastPasswordChange( Date passwordChangeDate )
  351. {
  352. //To change body of implemented methods use File | Settings | File Templates.
  353. }
  354. public List<String> getPreviousEncodedPasswords()
  355. {
  356. return null; //To change body of implemented methods use File | Settings | File Templates.
  357. }
  358. public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
  359. {
  360. //To change body of implemented methods use File | Settings | File Templates.
  361. }
  362. public void addPreviousEncodedPassword( String encodedPassword )
  363. {
  364. //To change body of implemented methods use File | Settings | File Templates.
  365. }
  366. public boolean isPermanent()
  367. {
  368. return false; //To change body of implemented methods use File | Settings | File Templates.
  369. }
  370. public void setPermanent( boolean permanent )
  371. {
  372. //To change body of implemented methods use File | Settings | File Templates.
  373. }
  374. public boolean isLocked()
  375. {
  376. return false; //To change body of implemented methods use File | Settings | File Templates.
  377. }
  378. public void setLocked( boolean locked )
  379. {
  380. //To change body of implemented methods use File | Settings | File Templates.
  381. }
  382. public boolean isPasswordChangeRequired()
  383. {
  384. return false; //To change body of implemented methods use File | Settings | File Templates.
  385. }
  386. public void setPasswordChangeRequired( boolean changeRequired )
  387. {
  388. //To change body of implemented methods use File | Settings | File Templates.
  389. }
  390. public boolean isValidated()
  391. {
  392. return false; //To change body of implemented methods use File | Settings | File Templates.
  393. }
  394. public void setValidated( boolean valid )
  395. {
  396. //To change body of implemented methods use File | Settings | File Templates.
  397. }
  398. public int getCountFailedLoginAttempts()
  399. {
  400. return 0; //To change body of implemented methods use File | Settings | File Templates.
  401. }
  402. public void setCountFailedLoginAttempts( int count )
  403. {
  404. //To change body of implemented methods use File | Settings | File Templates.
  405. }
  406. public Date getAccountCreationDate()
  407. {
  408. return null; //To change body of implemented methods use File | Settings | File Templates.
  409. }
  410. public void setAccountCreationDate( Date date )
  411. {
  412. //To change body of implemented methods use File | Settings | File Templates.
  413. }
  414. public Date getLastLoginDate()
  415. {
  416. return null; //To change body of implemented methods use File | Settings | File Templates.
  417. }
  418. public void setLastLoginDate( Date date )
  419. {
  420. //To change body of implemented methods use File | Settings | File Templates.
  421. }
  422. public String getUserManagerId()
  423. {
  424. return "mock";
  425. }
  426. };
  427. }
  428. public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
  429. {
  430. return null; //To change body of implemented methods use File | Settings | File Templates.
  431. }
  432. public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
  433. {
  434. return null; //To change body of implemented methods use File | Settings | File Templates.
  435. }
  436. public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
  437. {
  438. return null; //To change body of implemented methods use File | Settings | File Templates.
  439. }
  440. public List<User> findUsersByQuery( UserQuery query )
  441. {
  442. return null; //To change body of implemented methods use File | Settings | File Templates.
  443. }
  444. public boolean userExists( String principal )
  445. {
  446. return false; //To change body of implemented methods use File | Settings | File Templates.
  447. }
  448. public void deleteUser( String username )
  449. throws UserNotFoundException
  450. {
  451. //To change body of implemented methods use File | Settings | File Templates.
  452. }
  453. public void addUserUnchecked( User user )
  454. {
  455. //To change body of implemented methods use File | Settings | File Templates.
  456. }
  457. public void eraseDatabase()
  458. {
  459. //To change body of implemented methods use File | Settings | File Templates.
  460. }
  461. public User updateUser( User user, boolean passwordChangeRequired )
  462. throws UserNotFoundException
  463. {
  464. return null; //To change body of implemented methods use File | Settings | File Templates.
  465. }
  466. };
  467. }
  468. public boolean isAuthenticated( AuthenticationDataSource arg0 )
  469. throws AuthenticationException, UserNotFoundException, AccountLockedException
  470. {
  471. return false;
  472. }
  473. public boolean isAuthorized( SecuritySession arg0, String arg1 )
  474. throws AuthorizationException
  475. {
  476. return false;
  477. }
  478. public boolean isAuthorized( SecuritySession arg0, String arg1, String arg2 )
  479. throws AuthorizationException
  480. {
  481. if ( repoIds.contains( arg2 ) )
  482. {
  483. return true;
  484. }
  485. return false;
  486. }
  487. public boolean userManagerReadOnly()
  488. {
  489. return true;
  490. }
  491. }