Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hudson.plugins.collabnet.auth;
  
  
  
 
 
 
 
 
 
 public class CollabNetSecurityRealm extends SecurityRealm {
     private String collabNetUrl;
 
     public CollabNetSecurityRealm(String collabNetUrl) {
         this. = collabNetUrl;
     }
 
     public String getCollabNetUrl() {
         return this.;
     }
 
         return new SecurityRealm.SecurityComponents(new CollabNetAuthManager
                                                     (this.getCollabNetUrl()));
     }

    
Override the default createFilter. We want to use one that does not return a 403 on login redirect because that may cause problems when Hudson is run behind a proxy.
 
     @Override
     public Filter createFilter(FilterConfig filterConfig) {
         Binding binding = new Binding();
         SecurityComponents sc = this.createSecurityComponents();
         binding.setVariable("securityComponents"sc);
         BeanBuilder builder = new BeanBuilder(getClass().getClassLoader());
         builder.parse(getClass().
                       getResourceAsStream("CNSecurityFilters.groovy"),binding);
         WebApplicationContext context = builder.createApplicationContext();
         return (Filtercontext.getBean("filter");
     }


    

Returns:
the descriptor for CollabNetSecurityRealm
 
     public Descriptor<SecurityRealmgetDescriptor() {
         return ;
     }

    
Descriptor should be singleton.
 
     public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
    

    
The CollabNetSecurityRealm Descriptor class.
 
     public static final class DescriptorImpl 
         extends Descriptor<SecurityRealm> {
         DescriptorImpl() {
             super(CollabNetSecurityRealm.class);
         }

        

Returns:
string to display for configuration screen.
 
         public String getDisplayName() {
             return "CollabNet Security Realm";
         }

        

Returns:
the url for the help files.
 
         public static String getHelpUrl() {
             return "/plugin/collabnet/auth/";
         }

        

Returns:
the path to the help file.
 
        @Override
        public String getHelpFile() {
            return getHelpUrl() + "help-securityRealm.html";
        }

        

Parameters:
req config page parameters.
Returns:
new CollabNetSecurityRealm object, instantiated from the configuration form vars.
Throws:
hudson.model.Descriptor.FormException
        @Override
        public CollabNetSecurityRealm newInstance(StaplerRequest req
                                                  JSONObject formData
            throws FormException {
            return new CollabNetSecurityRealm((String)formData.
                                              get("collabneturl"));
        }

        
Form validation for the CollabNet URL.

Parameters:
req StaplerRequest which contains parameters from the config.jelly.
rsp contains http response data (unused).
Throws:
java.io.IOException
javax.servlet.ServletException
        public void doCollabNetUrlCheck(StaplerRequest req
                                        StaplerResponse rsp
            throws IOExceptionServletException {
            new FormFieldValidator(req,rsp,true) {
                protected void check() throws IOExceptionServletException {  
                    String collabNetUrl = .getParameter("value");
                    if (collabNetUrl == null || collabNetUrl.equals("")) {
                        error("The CollabNet URL is required.");
                        return;
                    }
                    if (!checkSoapUrl(collabNetUrl)) {
                        error("Invalid CollabNet URL.");
                        return;
                    }
                    ok();           
                }
            }.process();
        }
        
        
Check that a URL has the expected SOAP service.

Parameters:
collabNetUrl for the CollabNet server
Returns:
returns true if we can get a wsdl from the url, which indicates that it's a working CollabNet server.
        private boolean checkSoapUrl(String collabNetUrl) {
            String soapURL = collabNetUrl + . + 
                "CollabNet?wsdl";
            HttpClient client = new HttpClient();
            try {
                GetMethod get = new GetMethod(soapURL);
                int status = client.executeMethod(get);
                if (status == 200) {
                    return true;
                } else {
                    return false;
                }
            } catch (IOException e) {
                return false;
            } catch (IllegalArgumentException iae) {
                return false;
            }
        }    
    }
New to GrepCode? Check out our FAQ X