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.

BypassSecuritySystem.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package org.apache.archiva.webdav;
  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.keys.memory.MemoryKeyManager;
  27. import org.apache.archiva.redback.policy.AccountLockedException;
  28. import org.apache.archiva.redback.policy.DefaultUserSecurityPolicy;
  29. import org.apache.archiva.redback.policy.UserSecurityPolicy;
  30. import org.apache.archiva.redback.system.DefaultSecuritySession;
  31. import org.apache.archiva.redback.system.DefaultSecuritySystem;
  32. import org.apache.archiva.redback.system.SecuritySession;
  33. import org.apache.archiva.redback.system.SecuritySystem;
  34. import org.apache.archiva.redback.users.UserManager;
  35. import org.apache.archiva.redback.users.UserNotFoundException;
  36. import org.apache.archiva.redback.users.memory.MemoryUserManager;
  37. import org.springframework.stereotype.Service;
  38. /**
  39. * BypassSecuritySystem - used to bypass the security system for testing reasons and allow
  40. * for every request to respond as success / true.
  41. *
  42. *
  43. */
  44. @Service("securitySystem#bypass")
  45. public class BypassSecuritySystem
  46. extends DefaultSecuritySystem
  47. implements SecuritySystem
  48. {
  49. private KeyManager bypassKeyManager;
  50. private UserSecurityPolicy bypassPolicy;
  51. private UserManager bypassUserManager;
  52. public BypassSecuritySystem()
  53. {
  54. bypassKeyManager = new MemoryKeyManager();
  55. bypassPolicy = new DefaultUserSecurityPolicy();
  56. bypassUserManager = new MemoryUserManager();
  57. }
  58. @Override
  59. public SecuritySession authenticate( AuthenticationDataSource source )
  60. throws AuthenticationException, UserNotFoundException, AccountLockedException
  61. {
  62. AuthenticationResult result = new AuthenticationResult( true, source.getUsername(), null );
  63. return new DefaultSecuritySession( result );
  64. }
  65. @Override
  66. public AuthorizationResult authorize( SecuritySession session, String permission )
  67. throws AuthorizationException
  68. {
  69. return new AuthorizationResult( true, session.getUser(), null );
  70. }
  71. @Override
  72. public AuthorizationResult authorize( SecuritySession session, String permission, String resource )
  73. throws AuthorizationException
  74. {
  75. return new AuthorizationResult( true, session.getUser(), null );
  76. }
  77. @Override
  78. public String getAuthenticatorId()
  79. {
  80. return "bypass-authenticator";
  81. }
  82. @Override
  83. public String getAuthorizerId()
  84. {
  85. return "bypass-authorizer";
  86. }
  87. @Override
  88. public KeyManager getKeyManager()
  89. {
  90. return bypassKeyManager;
  91. }
  92. @Override
  93. public UserSecurityPolicy getPolicy()
  94. {
  95. return bypassPolicy;
  96. }
  97. @Override
  98. public String getUserManagementId()
  99. {
  100. return "bypass-managementid";
  101. }
  102. @Override
  103. public UserManager getUserManager()
  104. {
  105. return bypassUserManager;
  106. }
  107. @Override
  108. public boolean isAuthenticated( AuthenticationDataSource source )
  109. throws AuthenticationException, UserNotFoundException, AccountLockedException
  110. {
  111. // Always true
  112. return true;
  113. }
  114. @Override
  115. public boolean isAuthorized( SecuritySession session, String permission )
  116. throws AuthorizationException
  117. {
  118. // Always true
  119. return true;
  120. }
  121. @Override
  122. public boolean isAuthorized( SecuritySession session, String permission, String resource )
  123. throws AuthorizationException
  124. {
  125. // Always true
  126. return true;
  127. }
  128. @Override
  129. public boolean userManagerReadOnly()
  130. {
  131. return true;
  132. }
  133. }