org.jvnet.hudson.test
Class JenkinsRule.DummySecurityRealm

java.lang.Object
  extended by hudson.model.AbstractDescribableImpl<SecurityRealm>
      extended by hudson.security.SecurityRealm
          extended by hudson.security.AbstractPasswordBasedSecurityRealm
              extended by org.jvnet.hudson.test.JenkinsRule.DummySecurityRealm
All Implemented Interfaces:
ExtensionPoint, Describable<SecurityRealm>, org.acegisecurity.userdetails.UserDetailsService
Enclosing class:
JenkinsRule

public static class JenkinsRule.DummySecurityRealm
extends AbstractPasswordBasedSecurityRealm

See Also:
JenkinsRule.createDummySecurityRealm()

Nested Class Summary
 
Nested classes/interfaces inherited from class hudson.security.SecurityRealm
SecurityRealm.SecurityComponents
 
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
 
Field Summary
 
Fields inherited from class hudson.security.SecurityRealm
AUTHENTICATED_AUTHORITY, LIST, NO_AUTHENTICATION
 
Method Summary
 void addGroups(String username, String... groups)
          Associate some groups with a username.
protected  org.acegisecurity.userdetails.UserDetails authenticate(String username, String password)
          Authenticate a login attempt.
 GroupDetails loadGroupByGroupname(String groupname)
          Retrieves information about a group by its name.
 org.acegisecurity.userdetails.UserDetails loadUserByUsername(String username)
          Retrieves information about an user by its name.
 
Methods inherited from class hudson.security.AbstractPasswordBasedSecurityRealm
createCliAuthenticator, createSecurityComponents
 
Methods inherited from class hudson.security.SecurityRealm
all, allowsSignup, canLogOut, commenceSignup, createFilter, doCaptcha, doLogout, findBean, getAuthenticationGatewayUrl, getCaptchaSupport, getCaptchaSupportDescriptors, getDescriptor, getLoginUrl, getPostLogOutUrl, getSecurityComponents, setCaptchaSupport, validateCaptcha
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

authenticate

protected org.acegisecurity.userdetails.UserDetails authenticate(String username,
                                                                 String password)
                                                          throws org.acegisecurity.AuthenticationException
Description copied from class: AbstractPasswordBasedSecurityRealm
Authenticate a login attempt. This method is the heart of a AbstractPasswordBasedSecurityRealm.

If the user name and the password pair matches, retrieve the information about this user and return it as a UserDetails object. User is a convenient implementation to use, but if your backend offers additional data, you may want to use your own subtype so that the rest of Hudson can use those additional information (such as e-mail address --- see MailAddressResolver.)

Properties like UserDetails.getPassword() make no sense, so just return an empty value from it. The only information that you need to pay real attention is UserDetails.getAuthorities(), which is a list of roles/groups that the user is in. At minimum, this must contain SecurityRealm.AUTHENTICATED_AUTHORITY (which indicates that this user is authenticated and not anonymous), but if your backend supports a notion of groups, you should make sure that the authorities contain one entry per one group. This enables users to control authorization based on groups.

If the user name and the password pair doesn't match, throw AuthenticationException to reject the login attempt.

Specified by:
authenticate in class AbstractPasswordBasedSecurityRealm
Throws:
org.acegisecurity.AuthenticationException

loadUserByUsername

public org.acegisecurity.userdetails.UserDetails loadUserByUsername(String username)
                                                             throws org.acegisecurity.userdetails.UsernameNotFoundException,
                                                                    org.springframework.dao.DataAccessException
Description copied from class: AbstractPasswordBasedSecurityRealm
Retrieves information about an user by its name.

This method is used, for example, to validate if the given token is a valid user name when the user is configuring an ACL. This is an optional method that improves the user experience. If your backend doesn't support a query like this, just always throw UsernameNotFoundException.

Specified by:
loadUserByUsername in interface org.acegisecurity.userdetails.UserDetailsService
Specified by:
loadUserByUsername in class AbstractPasswordBasedSecurityRealm
Returns:
never null.
Throws:
org.acegisecurity.userdetails.UsernameNotFoundException
org.springframework.dao.DataAccessException

loadGroupByGroupname

public GroupDetails loadGroupByGroupname(String groupname)
                                  throws org.acegisecurity.userdetails.UsernameNotFoundException,
                                         org.springframework.dao.DataAccessException
Description copied from class: AbstractPasswordBasedSecurityRealm
Retrieves information about a group by its name. This method is the group version of the AbstractPasswordBasedSecurityRealm.loadUserByUsername(String).

Specified by:
loadGroupByGroupname in class AbstractPasswordBasedSecurityRealm
Throws:
org.acegisecurity.userdetails.UsernameNotFoundException
org.springframework.dao.DataAccessException

addGroups

public void addGroups(String username,
                      String... groups)
Associate some groups with a username.



Copyright © 2004-2013. All Rights Reserved.