Example #1
0
 /// <summary>
 /// Creates a new login token for authenticating a specific user for a specific application.
 /// </summary>
 /// <param name="username">The login name of the user requesting authentication.</param>
 /// <param name="applicationID">The unique identifier of the application requesting authentication.</param>
 /// <returns>A new login token if the specified user has access to the specified application; otherwise, null.</returns>
 public Token CreateToken(string username, byte applicationID)
 {
     using (CPSecurityEntities context = new CPSecurityEntities())
     {
         var app = context.SecuritySsoApplications.FirstOrDefault(a => a.ApplicationId == applicationID);
         if (app != null && HasUserRights(username, (CPUserRights)app.UserRights))
         {
             SecuritySsoToken token = new SecuritySsoToken()
             {
                 UserName = username,
                 SecuritySsoApplication = app
             };
             try
             {
                 context.SecuritySsoTokens.AddObject(token);
                 context.SaveChanges();
                 return(TokenFactory.CreateToken(token));
             }
             catch
             {
             }
         }
     }
     return(null);
 }
Example #2
0
 /// <summary>
 /// Creates a new <see cref="Token"/> instance using C-Access Security single sign-on token data.
 /// </summary>
 /// <param name="token">The single sign-on token to use.</param>
 /// <returns>A new token instance using the specified single sign-on data if valid; otherwise, null.</returns>
 public static Token CreateToken(SecuritySsoToken token)
 {
     if (token == null)
     {
         return(null);
     }
     return(new Token(token.TokenId, ApplicationFactory.CreateApplication(token.SecuritySsoApplication), token.UserName, token.Created));
 }