You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 19 Next »

Grouper Web Services

For web services and UI authentication for Grouper v2.5 and above see this page 


High level Grouper Web Services authentication

From a high level, grouper or the servlet container or web server or servlet filter will authenticate the user, and then the user needs to be resolved into a Subject.

Note the default and most popular authentication protocol in grouper-ws is http-basic (Authorization header), so for this and other reasons make sure your deployments of grouper-ws are protected with SSL.  In the v2.5+ container there is a param to enable self-signed SSL certs for quick starts if you dont have a real certificate yet.

Types of authentication

  1. Grouper basic authentication
  2. Apache htpasswd
  3. Apache basic with ldap
  4. Kerberos user/pass
  5. SSL certificates
  6. Rampart (on top of something else)
  7. other?

Types of subject sources

When the authentication happens and the principal name is given to Grouper from the authentication source, it needs to be resolvable as a subject.  There are a few options

  1. Use your existing subject source (e.g. ldap, if it can it hold accounts that represent systems)
  2. Grouper Local Entities
  3. Custom SQL table and source

Configure the default source in the grouper-ws.properties especially if you have subjectId overlap in various sources, but also to help with performance

# If there is an entry here for group name, then all web service client users must be in this group (before the actAs)
#ws.client.user.group.name = etc:webServiceClientUsers

# allow these ids even if not in group, e.g. for testing
# subjectIdOrIdentifier  or  sourceId::::subjectId  or  ::::subjectId  or  sourceId::::::subjectIdentifier  or  ::::::subjectIdentifier
# sourceId::::::::subjectIdOrIdentifier  or  ::::::::subjectIdOrIdentifier
# {valueType: "subject", multiple: true}
ws.client.user.group.subjects.allow = 

# cache the decision to allow a user to user web services, so it doesnt have to be calculated each time
# defaults to 5 minutes: 
# {valueType: "integer", required: true}
ws.client.user.group.cache.minutes = 5

# if you have subject namespace overlap (or not), set the default subject 
# sources (comma-separated) to lookup the user if none specified in user name
# {valueType: "string"}
ws.logged.in.subject.default.source = 

# prepend to the userid this value (e.g. if using local entities, might be:    etc:servicePrincipals:   )
# {valueType: "string"}
ws.security.prependToUserIdForSubjectLookup = 



HTTP basic with kerberos

Grouper-ws comes with an option to authenticate REST or SOAP with HTTP basic auth, but using the user/pass to authenticate to a kerberos kdc.  This exists so that kerberos can be used with REST (for SOAP, ws-security would be more secure), and as an example of how to customize the authentication.  You should use SSL if you use this authentication.  This defeats the purpose of kerberos since it transmits the password over the wire, and it only authenticates to the kdc and not an SSL service, so it might be possible for someone to spoof the kdc.   To use this, make the following settings in the grouper-ws.properties (obviously you need to configure the kerberos settings to fit your institution):

# to provide custom authentication (instead of the default httpServletRequest.getUserPrincipal()
# for non-Rampart authentication.  Class must implement the interface:
# edu.internet2.middleware.grouper.ws.security.WsCustomAuthentication
# class must be fully qualified.  e.g. edu.school.whatever.MyAuthenticator
# blank means use default: edu.internet2.middleware.grouper.ws.security.WsGrouperDefaultAuthentication
ws.security.non-rampart.authentication.class = edu.internet2.middleware.grouper.ws.security.WsGrouperKerberosAuthentication

################# KERBEROS settings, only needed if doing kerberos simple auth ################
# realm, whatever your realm is, e.g. SCHOOL.EDU
kerberos.realm = SCHOOL.EDU
# address of your kdc, e.g. kdc.school.edu
kerberos.kdc.address = kdc.school.edu

HTTP basic with ldap

Grouper-ws comes with an option to authenticate against ldap in 2.1.4+.  Pass the user/pass in basic auth (over SSL), and grouper can bind to an ldap server.  The username will be the subject id or identifier.

You can specify the following in the grouper-loader.properties (might already have this configured, you dont have to configure twice), note you dont have to have a user/pass since it will use the one from the authenticating WS user. Also, pooling is not applicable to this

################################# 
## LDAP connections 
################################# 
# specify the ldap connection with user, pass, url 
# the string after "ldap." is the ID of the connection, and it should not have 
# spaces or other special chars in it. In this case is it "personLdap" 

#note the URL should start with ldap: or ldaps: if it is SSL. 
#It should contain the server and port (optional if not default), and baseDn, 
#e.g. ldaps://ldapserver.school.edu:636/dc=school,dc=edu 
#ldap.personLdap.url = ldaps://ldapserver.school.edu:636/dc=school,dc=edu 

#optional, if you are using tls, set this to true. Generally you will not be using an SSL URL to use TLS... 
#ldap.personLdap.tls = false 

#optional, if using sasl 
#ldap.personLdap.saslAuthorizationId = 
#ldap.personLdap.saslRealm = 

#optional (note, time limit is for search operations, timeout is for connection timeouts), 
#most of these default to vt-ldap defaults. times are in millis 
#validateOnCheckout defaults to true if all other validate methods are false 
#ldap.personLdap.timeout = 

Then you can specify this in the grouper-ws.properties:

# to provide custom authentication (instead of the default httpServletRequest.getUserPrincipal() 
# for non-Rampart authentication. Class must implement the interface: 
# edu.internet2.middleware.grouper.ws.security.WsCustomAuthentication 
# class must be fully qualified. e.g. edu.school.whatever.MyAuthenticator 
# blank means use default: edu.internet2.middleware.grouper.ws.security.WsGrouperDefaultAuthentication 
# kerberos: edu.internet2.middleware.grouper.ws.security.WsGrouperKerberosAuthentication 
# ldap: edu.internet2.middleware.grouper.ws.security.WsGrouperLdapAuthentication 
ws.security.non-rampart.authentication.class = edu.internet2.middleware.grouper.ws.security.WsGrouperLdapAuthentication 

# if ldap authn should cache results 
ws.authn.ldap.cacheResults = true 

# if ldap authn should be used, which ldap connection name in the grouper-loader.properties should 
# be used for the connection to the ldap 
ws.authn.ldap.grouperLoaderLdapConfigId = personLdap 

# if ldap authn should be used, this is the prefix of the userId when connecting to ldap, e.g. uid= 
ws.authn.ldap.loginDnPrefix = 

# if ldap authn should be used, this is the suffix to the userId when connecting to ldap, e.g. ,ou=users,dc=school,dc=edu 
ws.authn.ldap.loginDnSuffix = 

Note, if you want to debug this, put this in the log4j.properties:

log4j.logger.edu.internet2.middleware.grouper.ws.security.WsGrouperLdapAuthentication = DEBUG

Custom authentication plugin

If you want custom authentication (e.g. pass in a token, and decode it), then implement the interface edu.internet2.middleware.grouper.ws.security.WsCustomAuthentication and configure your fully qualified classname in the grouper-ws.properties.  The default is an implementation of this interface as an example: edu.internet2.middleware.grouper.ws.security.WsGrouperDefaultAuthentication, which just gets the user from the container: httpServletRequest.getUserPrincipal().getName()

Rampart 

Rampart is Jakarta's WS-Security implementation.  We have vanilla Rampart authentication working with grouper-ws (thanks to Sanjay Vivek).  Unfortunately it doesnt work out of the box since it seems Rampart and basic auth cannot work together in the web app.  If you want to run basic auth and rampart at the same time, you should deploy two separate web apps.

Note the URL for rampart in grouper-ws is the same, it will look like this: /grouper-ws/services/GrouperService

Also, for Rampart, you need custom logic to authenticate users.  To use rampart, configure the grouper-ws.properties entry: ws.security.rampart.authentication.class.  An example is: edu.internet2.middleware.grouper.ws.security.GrouperWssecSample.  Until you configure that, clients will get a 404 http status code.  This assumes you are using WSPasswordCallback, if not, just provide your own class directly to the services.xml file (and grouper-ws requires you have an implementation of the interface anyway which wont be executed). 

You need to tell grouper that wssec is enabled in the web.xml servlet param (uncomment):

<servlet>
        <servlet-name>AxisServlet</servlet-name>
        <display-name>Apache-Axis Servlet</display-name>
        <servlet-class>edu.internet2.middleware.grouper.ws.GrouperServiceAxisServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    <!-- hint that this is the wssec servlet -->
    <init-param>
      <param-name>wssec</param-name>
      <param-value>true</param-value>
    </init-param>
    </servlet>

Also you need to comment out the container auth in web.xml:

<!--  security-constraint>
        <web-resource-collection>
            <web-resource-name>Web services</web-resource-name>
            <url-pattern>/services/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>grouper_user</role-name>
        </auth-constraint>
    </security-constraint -->

Then you need to enable the correct .aar file. 

  • If you are using a binary grouper-ws.war, just rename the following two files
    • /WEB-INF/services/GrouperService.aar to /WEB-INF/services/GrouperService.aar.ondeck
    • /WEB-INF/services/GrouperServiceWssec.aar.ondeck to /WEB-INF/services/GrouperServiceWssec.aar
  • If you are building, just set the param in the build.properties: webapp.authentication.use.rampart
    Here is a sample client

HTTP basic authentication (use)

 In the web.xml for the grouper-ws project, protect all services:

<security-constraint>
		<web-resource-collection>
			<web-resource-name>Web services</web-resource-name>
			<url-pattern>/services/*</url-pattern>
		</web-resource-collection>
		<auth-constraint>
			<!-- NOTE:  This role is not present in the default users file -->
			<role-name>grouper_user</role-name>
		</auth-constraint>
	</security-constraint>

	<!-- Define the Login Configuration for this Application -->
	<login-config>
		<auth-method>BASIC</auth-method>
		<realm-name>Grouper Application</realm-name>
	</login-config>

	<!-- Security roles referenced by this web application -->
	<security-role>
		<description>
			The role that is required to log in to the Manager
			Application
		</description>
		<role-name>grouper_user</role-name>
	</security-role>
</web-app>

Now send the user and pass in the web service client.
Here is an example with Axis generated clients:

GrouperServiceStub stub = new GrouperServiceStub(
                "http://localhost:8090/grouper-ws/services/GrouperService");
        Options options = stub._getServiceClient().getOptions();
        HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
        auth.setUsername("user");
        auth.setPassword("pass");

        options.setProperty(HTTPConstants.AUTHENTICATE, auth);

Here is an example with a manual HttpClient:

HttpClient httpClient = new HttpClient();
        GetMethod getMethod = new GetMethod(
                "http://localhost:8091/grouper-ws/services/GrouperService/addMemberSimple?groupName=aStem:aGroup&subjectId=10021368&actAsSubjectId=GrouperSystem");

        httpClient.getParams().setAuthenticationPreemptive(true);
        Credentials defaultcreds = new UsernamePasswordCredentials("user", "pass");
        httpClient.getState().setCredentials(new AuthScope("localhost", 8091), defaultcreds);

        httpClient.executeMethod(getMethod);

ActAs configuration

To enable web service users to act as another user (proxy), enable the setting in the grouper-ws grouper.properties

# Web service users who are in the following group can use the actAs field to act as someone else
ws.act.as.group = aStem:aGroup

If you specify a group name in there, you can pass in the actAs field if you connect to the web service as a user who is in the ws.act.as.group group.  Here is an example with the axis generated client.

//set the act as id
        WsSubjectLookup actAsSubject = WsSubjectLookup.class.newInstance();
        actAsSubject.setSubjectId("GrouperSystem");
        addMember.setActAsSubjectLookup(actAsSubject);

There are advanced settings, you can specify multiple groups in the grouper-ws.properties, and you can even limit who the users can act as (in a specific group).

  • No labels