Edition 1
Mono-spaced Bold
To see the contents of the filemy_next_bestselling_novelin your current working directory, enter thecat my_next_bestselling_novelcommand at the shell prompt and press Enter to execute the command.
Press Enter to execute the command.Press Ctrl+Alt+F2 to switch to a virtual terminal.
mono-spaced bold. For example:
File-related classes includefilesystemfor file systems,filefor files, anddirfor directories. Each class has its own associated set of permissions.
Choose → → from the main menu bar to launch Mouse Preferences. In the Buttons tab, click the Left-handed mouse check box and click to switch the primary mouse button from the left to the right (making the mouse suitable for use in the left hand).To insert a special character into a gedit file, choose → → from the main menu bar. Next, choose → from the Character Map menu bar, type the name of the character in the Search field and click . The character you sought will be highlighted in the Character Table. Double-click this highlighted character to place it in the Text to copy field and then click the button. Now switch back to your document and choose → from the gedit menu bar.
Mono-spaced Bold Italic or Proportional Bold Italic
To connect to a remote machine using ssh, typesshat a shell prompt. If the remote machine isusername@domain.nameexample.comand your username on that machine is john, typessh john@example.com.Themount -o remountcommand remounts the named file system. For example, to remount thefile-system/homefile system, the command ismount -o remount /home.To see the version of a currently installed package, use therpm -qcommand. It will return a result as follows:package.package-version-release
Publican is a DocBook publishing system.
mono-spaced roman and presented thus:
books Desktop documentation drafts mss photos stuff svn books_tests Desktop1 downloads images notes scripts svgs
mono-spaced roman but add syntax highlighting as follows:
package org.jboss.book.jca.ex1; import javax.naming.InitialContext; public class ExClient { public static void main(String args[]) throws Exception { InitialContext iniCtx = new InitialContext(); Object ref = iniCtx.lookup("EchoBean"); EchoHome home = (EchoHome) ref; Echo echo = home.create(); System.out.println("Created Echo"); System.out.println("Echo.echo('Hello') = " + echo.echo("Hello")); } }
Belay and the component documentation. The following link will take you to a pre-filled bug report for this product: https://bugzilla.redhat.com/.
Description field. Be as specific as possible when describing the issue; this will help ensure that we can fix it quickly.
Document URL: Section Number and Name: Describe the issue: Suggestions for improvement: Additional information:









org.jboss.pressgang.belay.oauth2.resourceserver.service.OAuth2RSAuthService, interface can be implemented to add logic to check the hash against the returned information. The implementation will have to be annotated with @Alternative and listed under alternatives in beans.xml.
pom.xml as follows in the example below. If you are using any other build tool, download the appropriate jar file from the Maven repository and add it as a library.
<project> ... <repositories> <repository> <id>oss-repo</id> <name>OSS repository</name> <url>https://oss.sonatype.org/content/groups/public/</url> </repository> </repositories> ... <dependencies> <dependency> <groupId>org.jboss.pressgang.belay</groupId> <artifactId>gwt-client-provider</artifactId> <version>${belay.version}</version> </dependency> </dependencies> ... </project>
Module.gwt.xml file using the following code:
<inherits name="org.jboss.pressgang.belay.oauth2.gwt.OAuth2GwtClientProvider"/>
import org.jboss.pressgang.belay.oauth2.gwt.client.OAuthHandler; public class App implements EntryPoint { private static final OAuthHandler AUTH_HANDLER = OAuthHandler.get(); }
final AuthorizationRequest request = RequestUtil.openIdAuthorizationRequest("https://mydomain:443 /MyAuthServer/rest/auth/authorize", "appClientId", "gmail.com").withScopes("PERFORM_USER_MANAGEMENT"); AUTH_HANDLER.sendAuthRequest(request, new Callback<String, Throwable>() { @Override public void onSuccess(String result) { // Do something } @Override public void onFailure(Throwable caught) { // Handle error } });
OAuthRequest. The constructor parameters required are:
AUTH_HANDLER.sendRequest(new OAuthRequest(RequestBuilder.GET, "https://mydomain:443 /MyResourceServer/rest/resource"), new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { // Do something } @Override public void onError(Request request, Throwable exception) { // Handle error } });
AUTH_HANDLER.sendRequest(new OAuthRequest(RequestBuilder.GET, "https://mydomain:443 /MyAuthServer/rest/auth/user/queryUser"), new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { // Do something } @Override public void onError(Request request, Throwable exception) { // Handle error } });
RequestUtil class includes helper methods to assist with the creation of an appropriate OAuthRequest for end-user identity association, and the designation of an end-user's primary identity. Here is an example of adding a second identity to an end-user. The second identity must be authorized before the associate request can be made, and the authorization from the first identity must be recorded, as both identities need to be authorized by the Authorization Server in order to be associated. AUTH_HANDLER.getLastTokenResult() is used to retrieve the access token of the first identity before the second identity is authorized (as a forced request) and overwrites this information (as the client application is the same for both). If either identity were already associated with other identities, the entire identity group would end up associated with the same end-user. The parameters used are:
final String originalToken = AUTH_HANDLER.getLastTokenResult(); final AuthorizationRequest authRequest = RequestUtil.openIdAuthorizationRequest("https://mydomain:443 /MyAuthServer/rest/auth/authorize", "appClientId", "http://username.myopenid.com") .withScopes(PERFORM_USER_MANAGEMENT) .forceNewRequest(true); AUTH_HANDLER.sendAuthRequest(authRequest, new Callback<String, Throwable>() { @Override public void onSuccess(String result) { final OAuthRequest request = RequestUtil.associateIdentitiesRequest( RequestBuilder.POST, "https://mydomain:443/MyAuthServer/rest/auth/user/associate", "appClientId", originalToken, false); AUTH_HANDLER.sendRequest(request, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { // Do something } @Override public void onError(Request request, Throwable exception) { // Handle error } }); } @Override public void onFailure(Throwable caught) { // Handle error } });
RequestUtil class includes a helper method to create an OAuthRequest to change an end-user's primary identity. The end-user must be authorized before this request is made, and the identity specified must be associated with the end-user. Here is an example. The parameters used are:
AUTH_HANDLER.sendRequest(RequestUtil.makeIdentityPrimaryRequest(RequestBuilder.GET, "https://mydomain:443/MyAuthServer/rest/auth/user/makeIdentityPrimary", "http://username.myopenid.com"), new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { // Do something } @Override public void onError(Request request, Throwable exception) { // Handle error } });
AUTH_HANDLER.clearAllTokens();
AUTH_HANDLER.sendRequest(RequestUtil.invalidateTokenGrantRequest(RequestBuilder.GET, "https://mydomain:443/MyAuthServer/rest/auth/invalidate", "appClientId"), new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { // Do something } @Override public void onError(Request request, Throwable exception) { // Handle error } });
String accessToken = AUTH_HANDLER.getLastTokenResult(); String accessTokenForSpecificRequest = AUTH_HANDLER.getTokenForRequest(myStoredAuthRequest);
AUTH_HANDLER.encodeUrl("http://myurl");
mvn clean install -DskipTests to build the projects. To deploy the various war files to your JBoss instance, use the command mvn package jboss-as:deploy. You will need to deploy the OpenIdProvider, OAuth2AuthServer, OAuth2SecuredRestApp and OAuth2GwtClientApp projects for all aspects of the GWT Client Application demonstration to function.
functionaltest.properties file in OAuth2GwtClientApp/src/test/resources/functional and add the usernames and passwords of your external OpenID accounts for Google, Yahoo, Fedora etc. Alternatively, you can add these details as arguments when you run mvn using the parameter values in the functionaltest.properties file: ie: mvn clean install -Dgoogle.user=myid@gmail.com -Dgoogle.pass=password.
pom.xml as follows in the example below. If you are using any other build tool, download the appropriate jar file from the Maven repository and add it as a library.
<project> ... <repositories> <repository> <id>oss-repo</id> <name>OSS repository</name> <url>https://oss.sonatype.org/content/groups/public/</url> </repository> </repositories> ... <dependencies> <dependency> <groupId>org.jboss.pressgang.belay</groupId> <artifactId>resource-server-provider</artifactId> <version>${belay.version}</version> </dependency> </dependencies> ... </project>
{project.basedir}/src/main/webapp/WEB-INF, create a datasource XML file for the resource server database, such as oauth2resourceserver-ds.xml. Take note of the JNDI name as it must be included under jta-data-source in your persistence.xml. Adding to your persistence.xml will be continued in later steps. Here is an example datasource configuration file for an in-memory database:
<?xml version="1.0" encoding="UTF-8"?> <datasources xmlns="http://www.jboss.org/ironjacamar/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd"> <datasource jndi-name="java:jboss/datasources/OAuth2ResourceServerDS" pool-name="oauth2resourceserver" enabled="true"use-java-context="true"> <connection-url> jdbc:h2:mem:oauth2resourceserver;DB_CLOSE_ON_EXIT=FALSE </connection-url> <driver>h2</driver> <security> <user-name>sa</user-name> <password>sa</password> </security> </datasource> </datasources>
{project.basedir}/src/main/webapp/WEB-INF, create a file there called beans.xml. Its content should be as follows:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="va.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> </beans>
persistence.xml file under ${project.basedir}/src/main/resources/META-INF, or open your existing one. Add a persistence unit for the data source you defined in step 2, making sure the JTA data source specified matches the JNDI name in your data source XML and that the Resource Server Provider model classes to be used (OAuth2RSScope and OAuth2RSEndpoint) are listed. Here is an example persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="</br> http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="oauth2-resourceserver"> <jta-data-source>java:jboss/datasources/OAuth2ResourceServerDS</jta-data-source> <jar-file>resource-server-provider-1.0-SNAPSHOT.jar</jar-file> <class> org.jboss.pressgang.belay.oauth2.resourceserver.data.model.OAuth2RSScope </class> <class> org.jboss.pressgang.belay.oauth2.resourceserver.data.model.OAuth2RSEndpoint </class> <!-- Demo database settings only. Not suitable for production environment --> <properties> <property name="jboss.entity.manager.factory.jndi.name" value="java:app/OAuth2ResourceServerManagerFactory" /> <property name="hibernate.hbm2ddl.auto" value="create-drop" /> <property name="hibernate.hbm2ddl.import_files" value="resourceserver-import.sql" /> <property name="hibernate.show_sql" value="false" /> </properties> </persistence-unit> </persistence>
${project.basedir}/src/main/resources/META-INF, create a file called resourceserver.properties. This file must be present with all properties set -- other than tokenExpiryExtensionThreshold, which is optional -- in order for the Resource Server Provider library to function. Here is an example resourceserver.properties file with comments explaining each property:
authServerUsername=resourceserver #Basic auth username for the Resource Server, as set on the Auth Server. This is used when the library needs to request information about an OAuth token authServerPassword=password #Basic auth password for the Resource Server, as set on the Auth Server authServerInfoUrl=https://localhost:8443/OAuth2AuthServer/rest/auth/info #The endpoint the Resource Server Provider should query for OAuth2 token information entityManagerFactoryJndiAddress=java:app/OAuth2ResourceServerManagerFactory #The JNDI address of the Resource Server manager factory, as specified in your persistence.xml (see step 4) tokenExpiryExtensionThreshold=300 # If a token used by a public client (which can't access refresh tokens) is within this many seconds of expiring when a request is made, the expiry time will be extended. Defaults to 900 (15 minutes)
resourceserver-import.sql file, placed in ${project.basedir}/src/main/resources to import data to a data source when the application is deployed. Using this sample data, only GET requests are allowed under the DEFAULT scope.
insert into RS_SCOPE (SCOPE_ID, SCOPE_NAME) values (-1, 'DEFAULT') insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-1, 'https://localhost:8443/OAuth2SecuredRestApp/rest/people', 'GET', false) insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-2, 'https://localhost:8443/OAuth2SecuredRestApp/rest/people/[0-9]+', 'GET', true) insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-3, 'https://localhost:8443/OAuth2SecuredRestApp/rest/people', 'POST', false) insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-4, 'https://localhost:8443/OAuth2SecuredRestApp/rest/people', 'PUT', false) insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-5, 'https://localhost:8443/OAuth2SecuredRestApp/rest/people/[0-9]+', 'DELETE', true) insert into RS_SCOPE_RS_ENDPOINT (SCOPE_ID, ENDPOINT_ID) values (-1, -1) insert into RS_SCOPE_RS_ENDPOINT (SCOPE_ID, ENDPOINT_ID) values (-1, -2)
web.xml file. Create a file called web.xml under ${project.basedir}/src/main/webapp/WEB-INF, or open your existing file. You need to add a filter using the org.jboss.pressgang.belay.oauth2.resourceserver.filter.OAuth2RSFilter class and a mapping indicating which URLs should be protected by this filter. You also need to define a context parameter to tell the library which class to use to make the access decisions. Here is an example web.xml that secures all endpoints under and including /rest/people:
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name>PressGang Belay OAuth2-secured App Example</display-name> <filter> <filter-name>OAuth2 Filter</filter-name> <filter-class> org.jboss.pressgang.belay.oauth2.resourceserver.filter.OAuth2RSFilter </filter-class> </filter> <filter-mapping> <filter-name>OAuth2 Filter</filter-name> <url-pattern>/rest/people/*</url-pattern> </filter-mapping> <context-param> <param-name>oauth.rs.provider-class</param-name> <param-value> org.jboss.pressgang.belay.oauth2.resourceserver.filter.OAuth2RSProvider </param-value> </context-param> </web-app>
pom.xml as follows in the example below. If you are using any other build tool, download the appropriate jar file from the Maven repository and add it as a library.
<project> ... <repositories> <repository> <id>oss-repo</id> <name>OSS repository</name> <url>https://oss.sonatype.org/content/groups/public/</url> </repository> </repositories> ... <dependencies> <dependency> <groupId>org.jboss.pressgang.belay</groupId> <artifactId>auth-server-provider</artifactId> <version>${belay.version}</version> </dependency> </dependencies> ... </project>
{project.basedir}/src/main/java in which to keep your web service code. Alternatively, you can define your endpoint paths in your web.xml. This documentation does not discuss this approach. To use the Java EE 6 no-XML approach to activating JAX-RS, in this package, create a class called JaxRsActivator that looks like the following, using your desired web service endpoint base in the @ApplicationPath annotation:
import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; @ApplicationPath("/rest") public class JaxRsActivator extends Application { /* class body intentionally left blank */ }
resourceserver.properties in the directory ${project.basedir}/src/main/resources/META-INF/. This file must be present with the first four properties set if you wish to use the Auth Server endpoint implementations provided by the Auth Server Provider library; the token expiry threshold property is optional. Here is an example resourceserver.properties file with comments explaining each property:
authServerUsername=authserver #Basic auth username for the Auth Server, as set on your server. This is used when the Resource Server Provider library needs to request information about an OAuth token used to access an OAuth2-protected Auth Server endpoint, such as /rest/auth/identity/query authServerPassword=password #Basic auth password for the Auth Server, as set on your server authServerInfoUrl=https://localhost:8443/OAuth2AuthServer/rest/auth/info #The endpoint the Resource Server Provider should query for OAuth2 token information entityManagerFactoryJndiAddress=java:app/OAuth2AuthServerManagerFactory #The JNDI address of the Auth Server manager factory, as specified in your persistence.xml (see step 8) tokenExpiryExtensionThreshold=300 #If a token used by a public client (which can't access refresh tokens) is within this many seconds of expiring when a request is made, the expiry time will be extended. Defaults to 900 (15 minutes)
{project.basedir}/src/main/resource/META-INF you should also create a persistence.xml file. The important things to include are:
resourceserver.properties file for the entityManagerFactoryJndiAddress property. This allows the Resource Server Provider to create an appropriate Entity Manager. The persistence unit name must be oauth2-authserver.
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="oauth2-authserver"> <jta-data-source>java:jboss/datasources/OAuth2AuthServerDS</jta-data-source> <jar-file>resource-server-provider-1.0.jar</jar-file> <jar-file>auth-server-provider-1.0.jar</jar-file> <class> org.jboss.pressgang.belay.oauth2.resourceserver.data.model.OAuth2RSScope </class> <class> org.jboss.pressgang.belay.oauth2.resourceserver.data.model.OAuth2RSEndpoint </class> <class> org.jboss.pressgang.belay.oauth2.authserver.data.model.ClientApplication </class> <class> org.jboss.pressgang.belay.oauth2.authserver.data.model.ClientApproval </class> <class> org.jboss.pressgang.belay.oauth2.authserver.data.model.Identity </class> <class> org.jboss.pressgang.belay.oauth2.authserver.data.model.OpenIdProvider </class> <class> org.jboss.pressgang.belay.oauth2.authserver.data.model.Scope </class> <class> org.jboss.pressgang.belay.oauth2.authserver.data.model.TokenGrant </class> <class> org.jboss.pressgang.belay.oauth2.authserver.data.model.CodeGrant </class> <class> org.jboss.pressgang.belay.oauth2.authserver.data.model.User </class> <!-- Demo database settings only. Not suitable for production environment --> <properties> <property name="jboss.entity.manager.factory.jndi.name" value="java:app/OAuth2AuthServerManagerFactory" /> <property name="hibernate.hbm2ddl.auto" value="create-drop" /> <property name="hibernate.show_sql" value="false" /> </properties> </persistence-unit> </persistence>
import.sql file in ${project.basedir}/src/main/resources to put some data in your database when the Auth Server starts. Whether you are using an in-memory database or a file database, you will need to make sure your database contains the same sort of information as included in the following sample import.sql. The data to import includes:
import.sql file. Note that this data allows clients to perform user management by default; you may wish to put these endpoints under a separate scope:
insert into CLIENT (CLIENT_ID, CLIENT_IDENTIFIER, CLIENT_NAME, CLIENT_REDIRECT_URI, GRANTS_MUST_EXPIRE) values (-1, 'pressgang_belay_id', 'GwtOAuth2Client', true, 'https://localhost:8443/OAuth2GwtClientApp/org.jboss.pressgang.belay.oauth2.gwt .sample.App/oAuthWindow.html') insert into OPENID_PROVIDER (PROVIDER_ID, PROVIDER_NAME, PROVIDER_URL) values (-1, 'Google', 'gmail.com') insert into OPENID_PROVIDER (PROVIDER_ID, PROVIDER_NAME, PROVIDER_URL) values (-2, 'BelayOpenID', 'https://localhost:8443/OpenIdProvider') insert into OPENID_PROVIDER (PROVIDER_ID, PROVIDER_NAME, PROVIDER_URL) values (-3, 'Yahoo', 'me.yahoo.com') insert into OPENID_PROVIDER (PROVIDER_ID, PROVIDER_NAME, PROVIDER_URL) values (-4, 'Facebook', 'facebook.com') insert into OPENID_PROVIDER (PROVIDER_ID, PROVIDER_NAME, PROVIDER_URL) values (-5, 'myOpenID', 'myopenid.com') insert into OPENID_PROVIDER (PROVIDER_ID, PROVIDER_NAME, PROVIDER_URL) values (-6, 'Fedora Account System','admin.fedoraproject.org') insert into SCOPE (SCOPE_ID, SCOPE_NAME) values (-1, 'DEFAULT') insert into RS_SCOPE (SCOPE_ID, SCOPE_NAME) values (-1, 'DEFAULT') insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-1, 'https://localhost:8443/OAuth2AuthServer/rest/auth/user/associate', 'POST', false) insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-2, 'https://localhost:8443/OAuth2AuthServer/rest/auth/user/makeIdentityPrimary', 'GET', false) insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-3, 'https://localhost:8443/OAuth2AuthServer/rest/auth/user/queryIdentity', 'GET, false') insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-4, 'https://localhost:8443/OAuth2AuthServer/rest/auth/user/queryUser', 'GET', false) insert into RS_ENDPOINT (ENDPOINT_ID, ENDPOINT_URL, ENDPOINT_METHOD, URL_REGEX) values (-5, 'https://localhost:8443/OAuth2AuthServer/rest/auth/invalidate', 'GET', false) insert into RS_SCOPE_RS_ENDPOINT (SCOPE_ID, ENDPOINT_ID) values (-2, -1) insert into RS_SCOPE_RS_ENDPOINT (SCOPE_ID, ENDPOINT_ID) values (-2, -2) insert into RS_SCOPE_RS_ENDPOINT (SCOPE_ID, ENDPOINT_ID) values (-2, -3) insert into RS_SCOPE_RS_ENDPOINT (SCOPE_ID, ENDPOINT_ID) values (-2, -4) insert into RS_SCOPE_RS_ENDPOINT (SCOPE_ID, ENDPOINT_ID) values (-1, -5)
{project.basedir}/src/main/webapp/WEB-INF. In this directory, create a file called beans.xml. Its content should be as follows:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> </beans>
{project.basedir}/src/main/webapp/WEB-INF, create a datasource xml file for your database, such as oauth2authserver-ds.xml. Its JNDI name must match the jta-data-source included in your persistence.xml. Here is an example datasource configuration file for an in-memory database:
<?xml version="1.0" encoding="UTF-8"?> <datasources xmlns="http://www.jboss.org/ironjacamar/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd"> <datasource jndi-name="java:jboss/datasources/OAuth2AuthServerDS" pool-name="oauth2authserver" enabled="true" use-java-context="true"> <connection-url> jdbc:h2:mem:oauth2authserver;DB_CLOSE_ON_EXIT=FALSE </connection-url> <driver>h2</driver> <security> <user-name>sa</user-name> <password>sa</password> </security> </datasource> </datasources>
{project.basedir}/src/main/webapp/WEB-INF, create a web.xml file. There are several aspects of the Auth Server set-up to configure here. These are:
web.xml with all of these configured:
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name>PressGang Belay OAuth2 Auth Server</display-name> <!-- Used to override Guice binding in the openid-filter library --> <listener> <listener-class> org.jboss.pressgang.belay.oauth2.authserver.openid .GuiceOverrideServletContextListener </listener-class> <listener> <!-- The OpenID Filter handles identity authentication --> <filter> <filter-name>OpenID Filter</filter-name> <filter-class>com.google.code.openid.RelyingPartyFilter</filter-class> </filter> <!-- This defines the URL that requires OpenID authentication --> <filter-mapping> <filter-name>OpenID Filter</filter-name> <url-pattern>/rest/auth/authorize</url-pattern> </filter-mapping> <filter> <filter-name>OAuth Filter</filter-name> <filter-class> oss.pressgang.belay.oauth2.resourceserver.filter.OAuth2RSFilter </filter-class> </filter> <filter-mapping> <filter-name>OAuth Filter</filter-name> <url-pattern>/rest/auth/user/*</url-pattern> <url-pattern>/rest/auth/invalidate</url-pattern> </filter-mapping> <context-param> <param-name>oauth.rs.provider-class</param-name> <param-value> org.jboss.pressgang.belay.oauth2.resourceserver.filter.OAuth2RSProvider </param-value> </context-param> <context-param> <param-name>oauth.provider.tokens.request</param-name> <param-value>/rest/auth/token</param-value> </context-param> <context-param> <param-name>oauth.provider.tokens.access</param-name> <param-value>/rest/auth/authorize</param-value> </context-param> <context-param> <param-name>oauth.rs.tokens</param-name> <param-value>HEADER</param-value> </context-param> <security-constraint> <web-resource-collection> <web-resource-name>ClientResources</web-resource-name> <url-pattern>/rest/auth/token</url-pattern> <url-pattern>/rest/auth/info</url-pattern> </web-resource-collection> <auth-constraint> <role-name>clientapp</role-name> </auth-constraint> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>ApplicationRealm</realm-name> </login-config> <security-role> <role-name>clientapp</role-name> </security-role> </web-app>
GrantEndpointImpl will be used, which implements the GrantEndpoint interface.
GrantEndpointImpl.
import org.jboss.pressgang.belay.oauth2.authserver.rest.impl.GrantEndpointImpl; import javax.enterprise.context.RequestScoped; import javax.ws.rs.Path: @RequestScoped @Path("/auth/invalidate") public class GrantWebService extends GrantEndpointImpl { /* class body intentionally left blank */ }
UserManagementEndpoint interface, you must override the methods and decorate them with all the required JAX-RS annotations as these will no longer be inherited. Otherwise, the paths defined in the interface will be used, with the base path you defined.
import org.apache.amber.oauth2.common.exception.OAuthProblemException; import org.apache.amber.oauth2.common.exception.OAuthSystemException; import org.jboss.pressgang.belay.oauth2.authserver.rest.impl.UserManagementEndpointImpl; import org.jboss.pressgang.belay.oauth2.shared.data.model.IdentityInfo; import org.jboss.pressgang.belay.oauth2.shared.data.model.UserInfo; import javax.enterprise.context.RequestScoped; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.net.URISyntaxException; @RequestScoped @Path("/auth/user") public class UserManagementWebService extends UserManagementWebServiceImpl { @Override @GET @Produces(MediaType.APPLICATION_JSON) @Path("/myCustomQueryUserPath") public UserInfo getUserInfo(@Context HttpServletRequest request, String identifier) { return super.getPrimaryUserInfo(request, identifier); } @Override @GET @Produces(MediaType.APPLICATION_JSON) @Path("/myCustomQueryIdentityPath") public IdentityInfo getIdentityInfo(@Context HttpServletRequest request, @QueryParam("id") String identifier) { return super.getPrimaryIdentityInfo(request, identifier); } @Override @GET @Path("/myCustomMakeIdentityPrimaryPath") public Response makeIdentityPrimary(@Context HttpServletRequest request, @QueryParam("id") String identifier) { return super.makeIdentityPrimary(request, identifier); } }
TokenEndpoint, UserManagementEndpoint). You can then configure your Auth Server implementation to use your authorization and token endpoints in your web.xml. You should also inform your resource servers and OAuth2 clients where these endpoints are located.
authserver.properties file in ${project.basedir}/src/main/resources/META-INF/ to override Auth Server Provider configurations options. However, this file and every property in it is optional; defaults will be used if the file is not found or a property is not set.
authserver.properties files showing the default values with comments explaining each property available:
oAuthTokenExpiry=3600 #The expiry time of an OAuth2 access token in seconds, set when the token is created. This is also the time used to extend public client access tokens by when their expiry time is pushed out oAuthCodeExpiry=60 #The expiry time of an OAuth2 authorization code in seconds, set when the code is created urlEncoding=UTF-8 #The encoding type specified when encoding or decoding URLs openIdRealm=/OAuth2AuthServer/rest/auth/ #The OpenID realm of the Auth Server restEndpointBasePath=/OAuth2AuthServer/rest #The base path for the Auth Server's RESTful endpoints, as defined by the application name and JAX-RS base path authEndpoint=/auth/authorize #The path to the OAuth2 authorization endpoint, relative to the project's JAX-RS base path openIdReturnUri=/OAuth2AuthServer/rest/auth/authorize #The endpoint to use as the OpenID return URI, which should match the grantEndpoint property but be expressed relative to the server's domain defaultScopeName=DEFAULT #The name of the scope that all users should have upon creation and all token grants are given, capitalized by convention. This must have a matching definition in the database promptEndUserToApproveClientAppOnEveryLogin=false #Boolean true/false. True if you want the end-user to be prompted to approve client access of their auth info and resources on every login endUserConsentUri=/auth/consent #The URI to redirect end-users to give consent for client access to their auth info and resources, relative to the project's JAX-RS base path endUserConsentFormCssLocation= #The URL where a style sheet for the end-user consent page can be found; optional
authserver.properties file has been created and the default configuration options have been overriden.
org.jboss.pressgang.belay.oauth2.authserver.service.TokenIssuer interface decorated with the javax.enterprise.inject.Alternative annotation using the following example code:
import org.apache.amber.oauth2.common.exception.OAuthSystemException; import org.jboss.pressgang.belay.oauth2.authserver.service.TokenIssuer; import javax.ejb.Stateless; import javax.enterprise.inject.Alternative; @Alternative @Stateless public class AlternativeTokenIssuer implements TokenIssuer { @Override public String accessToken() throws OAuthSystemException { return "foo"; } @Override public String refreshToken() throws OAuthSystemException { return "bar"; } @Override public String authorizationCode() throws OAuthSystemException { return "foobar"; } }
beans.xml:
<beans> ... <alternatives> <class> org.jboss.pressgang.belay.oauth2.authserver.sample .service.AlternativeTokenIssuer </class> </alternatives> </beans>
AuthService type for all data access. If you wish to change the underlying data model and data access methods, you can provide an alternative implementation of this interface.
DefaultAuthService implementation, create your own implementation of the org.jboss.pressgang.belay.oauth2.authserver.service.AuthService interface decorated with the javax.enterprise.inject.Alternative annotation.
beans.xml:
<beans> ... <alternatives> <class> org.jboss.pressgang.belay.oauth2.authserver.sample .service.AlternativeAuthService </class> </alternatives> </beans>
| Revision History | |||
|---|---|---|---|
| Revision 1.0-1 | Wed Nov 14 2012 | ||
| |||