Previous Topic

Next Topic

Book Contents

Book Index

Simple Login Service

The Simple Login service supports user login to the OSGi Runtime

Overview

The Simple Login service supports user login to the OSGi Runtime and therefore, it is a simple mechanism for authentication to the framework's user management system. After a user successfully logs in, bundles can examine its authorization parameters. The Simple Login service is represented by the com.prosyst.mbs.services.useradmin.SimpleLogin interface. Authorization for this service is delivered by com.prosyst.mbs.services.useradmin.Authorization which extends the org.osgi.service.useradmin.Authorization. In addition to checking the roles of a requester, it allows user logout.

To enable login of miscellaneous users, framework administrators should assign passwords to them as credentials.

Developers can retrieve the format of the password credential from the SimpleLogin.PASSWORD field. The username property is accessible through SimpleLogin.USERNAME.

The code snippet that follows, logs in the initial user admin and checks whether it owns the "administration" role.

                      . . .
  BundleContext bc;
  String userName = "admin";
  String password = "admin";
                      . . .
  ServiceReference sLoginRef = bc.getServiceReference(SimpleLogin.class.getName());
  SimpleLogin sLogin = (SimpleLogin) bc.getService(sLoginRef);
  Authorization autho = sLogin.login(userName, password);
  boolean okFlag = autho.hasRole("administration");  

  if(okFlag) {
    System.out.println("The user is an administrator!");
  }

  autho.logout();

The Simple Login service also allows developers to pass authorization information to bundles that restrict the access to their resources. A carrier of such information can be a data stream or a thread. By using the service, you can attach an Authorization object to an intermediary object that will handle it from the User Admin Extension bundle to another application. The methods you can use for associating Authorization objects are getAuthorization and setAuthorization.

More information you can find from the Status/Services menu of the Web Admin Console.

Registering Bundle

This service is registered by Util Simple Login Bundle.

For more details on the properties of the registering bundles refer to the Util Simple Login Bundle System Properties.