Thursday, November 20, 2014

Authenticating Users using OPSS API in ADF

OPSS is the underlying security platform that provides security to ADF. In some cases it is required to access OPSS API programmatically. Here is the code snippets for authenticating users using OPSS API :
 

import oracle.security.idm.IMException;
import oracle.security.idm.IdentityStore;
import oracle.security.idm.User;
import oracle.security.idm.UserManager;
import oracle.security.jps.JpsContext;
import oracle.security.jps.JpsContextFactory;
import oracle.security.jps.service.idstore.IdentityStoreService;

public class OpssApiExample
{
  public Boolean isUserAuthenticated(String username, String password) 
  {
    Boolean isAuthenticated = Boolean.FALSE;
    try
    {
      JpsContextFactory ctxf = JpsContextFactory.getContextFactory();
      JpsContext ctx = ctxf.getContext();
      IdentityStoreService storeService =
        ctx.getServiceInstance(IdentityStoreService.class);
      IdentityStore idStore = storeService.getIdmStore();
      UserManager userManager = idStore.getUserManager();
      User authUser =null;
      try
      {
        authUser =
          userManager.authenticateUser(username, password.toCharArray());
        isAuthenticated = Boolean.TRUE;
      }
      catch (IMException ime)
      {        
        //Could not authenticate
        ime.printStackTrace(); //Print the authentication error
      }
    }
    catch (Exception exp)
    {
      exp.printStackTrace();
    }   
    return isAuthenticated;
  }
  
}




No comments:

Post a Comment