Advertisement
Guest User

Untitled

a guest
Dec 21st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. Base class:
  2.  
  3. public abstract class AuthenticationMethod implements Describable<AuthenticationMethod>, Serializable {
  4.  
  5. private static final long serialVersionUID = -6077120270692721571L;
  6.  
  7. public abstract String getType();
  8.  
  9. public boolean isAuthenticationMethod(String method) {
  10. return getType().equalsIgnoreCase(method);
  11. }
  12.  
  13. public abstract static class AuthenticationMethodDescriptor extends Descriptor<AuthenticationMethod> {
  14.  
  15. public static ExtensionList<AuthenticationMethodDescriptor> all() {
  16. return Jenkins.getInstance().getExtensionList(AuthenticationMethodDescriptor.class);
  17. }
  18. }
  19. }
  20.  
  21. User authentication class:
  22.  
  23. public class UsernameAuthenticationMethod extends AuthenticationMethod {
  24. private static final long serialVersionUID = 452156745621333923L;
  25.  
  26. private String username;
  27. private Secret password;
  28.  
  29. @DataBoundConstructor
  30. public UsernameAuthenticationMethod(String username, Secret password) {
  31. this.setUsername(username);
  32. this.setPassword(password);
  33. }
  34.  
  35. public String getUsername() {
  36. return username;
  37. }
  38.  
  39. public void setUsername(String username) {
  40. this.username = username;
  41. }
  42.  
  43. public Secret getPassword() {
  44. return password;
  45. }
  46.  
  47. public void setPassword(Secret password) {
  48. this.password = password;
  49. }
  50.  
  51. @Override
  52. public String getType() {
  53. return "username";
  54. }
  55.  
  56. @Override
  57. public Descriptor<AuthenticationMethod> getDescriptor() {
  58. return Jenkins.getInstance().getDescriptorByType(UsernameAuthenticationMethodDescriptor.class);
  59. }
  60.  
  61. @Extension
  62. public static class UsernameAuthenticationMethodDescriptor extends AuthenticationMethodDescriptor {
  63.  
  64. @Override
  65. public String getDisplayName() {
  66. return null;
  67. }
  68.  
  69. @Override
  70. public UsernameAuthenticationMethod newInstance(StaplerRequest sr, JSONObject jo) {
  71. return new UsernameAuthenticationMethod(jo.getString("user"), Secret.fromString(jo.getString("password")));
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement