5 Replies Latest reply: Jun 2, 2010 1:34 AM by 807573 RSS

    How to create a user in Opensso Identity Service Webservices api?

    807573
      Hi All,

      I am getting struck with the creation of user in OpenSSO through the webservices api they are providing.
      I used the following wsdl link to create the API's. http://localhost:8080/opensso/identityservices?WSDL

      Now my requirement is, i have to create a user profile through the program which has the api create(identity,admin) created by the WSDL link.
      Here identity is the com.sun.idsvcs.IdentityDetails and admin is the com.sun.idsvcs.Token. I want to append givenName,cn,sn,userPassword in that. But dont have any idea how to given these details in IdentityDetails. If anyone give any sample solution i can follow.

      Any Help Greatly Appreciated.

      Thanks in Advance.

      With Regards,
      Nithya.
        • 1. Re: How to create a user in Opensso Identity Service Webservices api?
          807573
          Hello,

          I'm coding it too...
          Maybe you should pack these properties like attributes, and add them to the identityDetails.getAttributes() list...
          Check it out: http://developers.sun.com/identity/reference/techart/id-svcs3.html

          Shame on you, Sun Inc! You haven't documented such a useful set of operations. You are interested in promoting this OpenSSO product, aren't you...
          • 2. Re: How to create a user in Opensso Identity Service Webservices api?
            807573
            Hey, I've managed to implement OpenSSO user registration through SOAP.

            My code is:
            package ru.vostrets.service.implementation.helper.opensso;
            
            import ru.vostrets.model.person.Person;
            
            
            
            import org.springframework.beans.factory.annotation.Autowired;
            import org.springframework.stereotype.Service;
            
            import ru.vostrets.dao.PropertiesDao;
            import ru.vostrets.exception.FatalError;
            
            import com.sun.identity.idsvcs.opensso.*;
            
            import java.util.HashMap;
            import java.util.Map;
            
            import org.slf4j.LoggerFactory;
            import org.slf4j.Logger;
            import ru.vostrets.exception.ConfigurationError;
            
            /**
             *
             * @author Kuchumov Nikolay
             *
             * email: kuchumovn@gmail.com
             */
            @Service
            public class OpenSsoPersonServiceHelper
            {
                 private enum AttributeName
                 {
                      USER_NAME("uid"),
                      PASS_WORD("userpassword"),
            
                      GIVEN_NAME("givenname"),
                      FAMILY_NAME("sn"),
                      FULL_NAME("cn"),
            
                      EMAIL("mail");
            
                      private final String name;
            
                      AttributeName(String name)
                      {
                           this.name = name;
                      }
            
                      public String getName()
                      {
                           return name;
                      }
                 }
            
                 private static final Logger LOG = LoggerFactory.getLogger(OpenSsoPersonServiceHelper.class);
            
                 private PropertiesDao propertiesDao;
            
                 public void create(Person person)
                 {
                      try
                      {
                           IdentityServicesImplService service = new IdentityServicesImplService();
                           IdentityServicesImpl servicePort = service.getIdentityServicesImplPort();
            
                           /*
                           java.util.List<java.lang.String> attributeNames = null;
                           Token subject = new Token();
                           subject.setId(request.getParameter("token"));
                           UserDetails results = servicePort.attributes(attributeNames, subject);
                           for (Attribute attribute : results.getAttributes())
                           {
                                LOG.info("************ Attribute: Name = " + attribute.getName() + ", Values = " + attribute.getValues());
                           }
                           LOG.info("Roles = " + results.getRoles());
                           */
            
                           IdentityDetails identity = newIdentity
                           (
                                     person.getCredentials().getUserName(),
                                     getAttributes(person)
                           );
            
                           /*
                            * Creates an identity object with the specified attributes.
                            *
                            * @param admin Token identifying the administrator to be used to authorize
                            * the request.
                            * @param identity object containing the attributes of the object
                            * to be created.
                            * @throws NeedMoreCredentials when more credentials are required for
                            * authorization.
                            * @throws DuplicateObject if an object matching the name, type and
                            * realm already exists.
                            * @throws TokenExpired when subject's token has expired.
                            * @throws GeneralFailure on other errors.
                            */
                           servicePort.create
                           (
                                     identity,
                                     authenticateAdministrator()
                           );
                      }
                      /*
                      catch (DuplicateObject_Exception exception)
                      {
                           throw new UserAlreadyExistsError();
                      }
                      */
                      catch (Exception exception)
                      {
                           //GeneralFailure_Exception
                           //NeedMoreCredentials_Exception
                           //TokenExpired_Exception
                           throw new FatalError(exception);
                      }          
                 }
            
                 private Token authenticateAdministrator()
                 {
                      try
                      {
                           IdentityServicesImplService service = new IdentityServicesImplService();
                           IdentityServicesImpl servicePort = service.getIdentityServicesImplPort();
            
                           if (propertiesDao.get().getAuthentication().getOpenSso().getAdministrator().getUserName() == null
                                     || propertiesDao.get().getAuthentication().getOpenSso().getAdministrator().getPassWord() == null)
                           {
                                throw new ConfigurationError("OpenSSO administration properties not initialized");
                           }
            
                           /*
                            * Attempt to authenticate using simple user/password credentials.
                            * @param username Subject's user name.
                            * @param password Subject's password
                            * @param uri Subject's context such as module, organization, etc.
                            * @return Subject's token if authenticated.
                            * @throws UserNotFound if user not found.
                            * @throws InvalidPassword if password is invalid.
                            * @throws NeedMoreCredentials if additional credentials are needed for
                            * authentication.
                            * @throws InvalidCredentials if credentials are invalid.
                            * @throws GeneralFailure on other errors.
                            */
                           Token token = servicePort.authenticate
                           (
                                     propertiesDao.get().getAuthentication().getOpenSso().getAdministrator().getUserName(),
                                     propertiesDao.get().getAuthentication().getOpenSso().getAdministrator().getPassWord(),
                                     ""
                           );
            
                           LOG.info("******************************** Admin token: " + token.getId());
            
                           return token;
                      }
                      catch (Exception exception)
                      {
                           throw new FatalError(exception);
                      }
            
                      /*
                      com.sun.identity.idsvcs.opensso.IdentityServicesImplService service = new com.sun.identity.idsvcs.opensso.IdentityServicesImplService();
            
                      QName portQName = new QName("http://opensso.idsvcs.identity.sun.com/" , "IdentityServicesImplPort");
                      String request = "<authenticate  xmlns=\"http://opensso.idsvcs.identity.sun.com/\"><username>ENTER VALUE</username><password>ENTER VALUE</password><uri>ENTER VALUE</uri></authenticate>";
            
                      try
                      {
                           // Call Web Service Operation
            
                           Dispatch<Source> sourceDispatch = null;
                           sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
                           Source result = sourceDispatch.invoke(new StreamSource(new StringReader(request)));
                      }
                      catch (Exception exception)
                      {
                           // TODO handle custom exceptions here
                      }
                      */
                 }
            
                 private Attribute newAttribute(AttributeName name, Object value)
                 {
                      Attribute attribute = new Attribute();
                      
                      attribute.setName(name.getName());
                      attribute.getValues().add(value.toString());
            
                      return attribute;
                 }
            
                 private Map<AttributeName, Object> fillAttributes(Map<AttributeName, Object> attributes, Person person)
                 {
                      attributes.put(AttributeName.USER_NAME, person.getCredentials().getUserName());
                      attributes.put(AttributeName.PASS_WORD, person.getCredentials().getPassWord());
            
                      attributes.put(AttributeName.GIVEN_NAME, person.getPersonal().getGivenName());
                      attributes.put(AttributeName.FAMILY_NAME, person.getPersonal().getFamilyName());
                      attributes.put(AttributeName.FULL_NAME, person);
            
                      attributes.put(AttributeName.EMAIL, person.getContacts().getEmail());
            
                      return attributes;
                 }
            
                 private Map<AttributeName, Object> getAttributes(Person person)
                 {
                      return fillAttributes(new HashMap<AttributeName, Object>(), person);
                 }
            
                 private IdentityDetails newIdentity(Object name, Map<AttributeName, Object> attributes)
                 {
                      IdentityDetails identity = new IdentityDetails();
            
                      identity.setName(name.toString());
            
                      return fillAttributes(identity, attributes);
                 }
            
                 private IdentityDetails fillAttributes(IdentityDetails identity, Map<AttributeName, Object> rawAttributes)
                 {
                      for (Map.Entry<AttributeName, Object> rawAttribute : rawAttributes.entrySet())
                      {
                           identity.getAttributes().add(
                                     newAttribute(rawAttribute.getKey(), rawAttribute.getValue()));
                      }
            
                      return identity;
                 }
            
                 @Autowired
                 public void setPropertiesDao(PropertiesDao propertiesDao)
                 {
                      this.propertiesDao = propertiesDao;
                 }
            }
            • 3. Re: How to create a user in Opensso Identity Service Webservices api?
              807573
              Error while creating user with Opensso Identity Service Webservices api.
              Please see post http://forums.sun.com/thread.jspa?threadID=5437250
              • 4. Re: How to create a user in Opensso Identity Service Webservices api?
                807573
                am learning opensso
                i need to run 2 application in opensso
                my constraint is tomcat5.6 for idp,tomcat 6.0 application1, tomcat6.0 application1 service provider
                tomcat 6.0 application2, tomcat6.0 application2 service provider

                when i click my application1 it is properly redirecting to idp then its checking in ldap and it giving me application to access. its working fine with ldap

                now i started to write custom authentication

                i dont have basic knowledge also in custom authentication please tell me wat i need to do to create custom authentication.please step by step explain me

                advance thanks for reply.
                • 5. Re: How to create a user in Opensso Identity Service Webservices api?
                  807573
                  am learning opensso
                  i need to run 2 application in opensso
                  my constraint is tomcat5.6 for idp,tomcat 6.0 application1, tomcat6.0 application1 service provider
                  tomcat 6.0 application2, tomcat6.0 application2 service provider

                  when i click my application1 it is properly redirecting to idp then its checking in ldap and it giving me application to access. its working fine with ldap

                  now i started to write custom authentication

                  i dont have basic knowledge also in custom authentication please tell me wat i need to do to create custom authentication.please step by step explain me

                  advance thanks for reply.