Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/24/10 02:37:56 (14 years ago)
Author:
swagner
Message:

Worked on OKB user authentication (#1167)

Location:
trunk/sources/HeuristicLab.Services.OKB/3.3
Files:
5 deleted
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Services.OKB/3.3/DataService.cs

    r4279 r4298  
    7272    private byte[] GetData(EntityType type, int id) {
    7373      Log("loading data", type, id);
    74       OKBDataContext okb = new OKBDataContext();
    75       switch (type) {
    76         case EntityType.Algorithm:
    77           Algorithm algorithm = okb.Algorithms.Single(a => a.Id == id);
    78           if (algorithm.AlgorithmData == null) {
    79             algorithm.AlgorithmData = new AlgorithmData() {
    80               AlgorithmId = algorithm.Id,
    81               Data = new Binary(new byte[0])
    82             };
    83             okb.SubmitChanges();
    84           }
    85           return algorithm.AlgorithmData.Data.ToArray();
    86           break;
    87         case EntityType.Problem:
    88           Problem problem = okb.Problems.Single(p => p.Id == id);
    89           if (problem.ProblemData == null) {
    90             problem.ProblemData = new ProblemData() {
    91               ProblemId = problem.Id,
    92               Data = new Binary(new byte[0])
    93             };
    94             okb.SubmitChanges();
    95           }
    96           return problem.ProblemData.Data.ToArray();
    97           break;
    98         default:
    99           throw new FaultException("Unsupported EntityType");
     74      using (OKBDataContext okb = new OKBDataContext()) {
     75        switch (type) {
     76          case EntityType.Algorithm:
     77            Algorithm algorithm = okb.Algorithms.Single(a => a.Id == id);
     78            if (algorithm.AlgorithmData == null) {
     79              algorithm.AlgorithmData = new AlgorithmData() {
     80                AlgorithmId = algorithm.Id,
     81                Data = new Binary(new byte[0])
     82              };
     83              okb.SubmitChanges();
     84            }
     85            return algorithm.AlgorithmData.Data.ToArray();
     86            break;
     87          case EntityType.Problem:
     88            Problem problem = okb.Problems.Single(p => p.Id == id);
     89            if (problem.ProblemData == null) {
     90              problem.ProblemData = new ProblemData() {
     91                ProblemId = problem.Id,
     92                Data = new Binary(new byte[0])
     93              };
     94              okb.SubmitChanges();
     95            }
     96            return problem.ProblemData.Data.ToArray();
     97            break;
     98          default:
     99            throw new FaultException("Unsupported EntityType");
     100        }
    100101      }
    101       okb.Dispose();
    102102    }
    103103
  • trunk/sources/HeuristicLab.Services.OKB/3.3/ExperimentKit.cs

    r4297 r4298  
    2121
    2222using System.Runtime.Serialization;
     23using HeuristicLab.Services.OKB.DataAccess;
    2324
    24 namespace HeuristicLab.Services.OKB.DataAccess {
    25 
     25namespace HeuristicLab.Services.OKB {
     26  /// <summary>
     27  /// Contains an <see cref="Algorithm"/> and a <see cref="Problem"/> populated with all
     28  /// required data to execute experiments.
     29  /// </summary>
    2630  [DataContract]
    2731  public class ExperimentKit {
     32    /// <summary>
     33    /// Gets an <see cref="Algorithm"/> populated with all required data to execute
     34    /// experiments.
     35    /// </summary>
     36    /// <value>An <see cref="Algorithm"/>.</value>
    2837    [DataMember]
    2938    public Algorithm Algorithm { get; set; }
    3039
     40    /// <summary>
     41    /// Gets a <see cref="Problem"/> populated with all required data to execute
     42    /// experiments.
     43    /// </summary>
     44    /// <value>A <see cref="Problem"/>.</value>
    3145    [DataMember]
    3246    public Problem Problem { get; set; }
  • trunk/sources/HeuristicLab.Services.OKB/3.3/HeuristicLab.Services.OKB-3.3.csproj

    r4283 r4298  
    120120      <RequiredTargetFramework>3.0</RequiredTargetFramework>
    121121    </Reference>
    122     <Reference Include="System.ServiceModel.Activation" />
    123122    <Reference Include="System.ServiceProcess" />
    124123    <Reference Include="System.Xml.Linq">
     
    134133    <Compile Include="AdminService.cs" />
    135134    <Compile Include="AttributeSelector.cs" />
    136     <Compile Include="CertificateServiceHostFactory.cs" />
    137     <Compile Include="CustomCertificateValidator.cs" />
    138     <Compile Include="CertificateServiceHost.cs" />
    139135    <Compile Include="DataService.cs" />
     136    <Compile Include="ExperimentKit.cs" />
    140137    <Compile Include="Interfaces\IDataService.cs" />
    141138    <Compile Include="Interfaces\ITableService.cs" />
     
    157154  <ItemGroup>
    158155    <None Include="app.config" />
    159     <EmbeddedResource Include="client.cer" />
    160     <EmbeddedResource Include="server.pfx" />
    161156    <None Include="HeuristicLab.snk" />
    162157  </ItemGroup>
  • trunk/sources/HeuristicLab.Services.OKB/3.3/Hoster.cs

    r4279 r4298  
    5353    }
    5454
    55     static ILog logger = log4net.LogManager.GetLogger("HeuristicLab.OKB.Hoster");
     55    static ILog logger = log4net.LogManager.GetLogger("HeuristicLab.Services.OKB.Hoster");
    5656
    5757    static void UnhandledException(object sender, UnhandledExceptionEventArgs e) {
     
    6464
    6565    private static void StartService(Type type) {
    66       ServiceHost host = new CertificateServiceHost(type);
     66      ServiceHost host = new ServiceHost(type);
    6767      try {
    6868        host.Open();
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunnerService.cs

    r4279 r4298  
    142142    public void AddRun(Algorithm algorithm, Problem problem, Project project) {
    143143      Log("adding run for {0}@{1}({2})[{3}, {4}]",
    144         algorithm.Name, problem.Name, project.Name, authentication.User.Name, authentication.Client.Name);
     144        algorithm.Name, problem.Name, project.Name, currentUser.Name, currentClient.Name);
    145145      try {
    146146        using (OKBDataContext okb = new OKBDataContext()) {
    147           var user = okb.Users.Single(u => u.Id == authentication.User.Id);
    148           var client = okb.Clients.Single(c => c.Id == authentication.Client.Id);
    149           Experiment experiment = GetOrCreateExperiment(algorithm, problem, project, authentication.User, okb);
     147          Experiment experiment = GetOrCreateExperiment(algorithm, problem, project, currentUser, okb);
    150148          Run run = new Run() {
    151149            Experiment = experiment,
    152             UserId = authentication.User.Id,
    153             ClientId = authentication.Client.Id,
     150            UserId = currentUser.Id,
     151            ClientId = currentClient.Id,
    154152            FinishedDate = DateTime.Now,
    155153            ResultValues = algorithm.ResultValues
     
    175173        Log("reusing existing experiment");
    176174        Experiment experiment = experimentQuery.First();
    177         if (experiment.ExperimentCreators.Where(ec => ec.UserId == user.Id).Count() == 0) {
    178           experiment.ExperimentCreators.Add(new ExperimentCreator() { UserId = user.Id });
    179         }
    180175        return experiment;
    181176      } else {
     
    187182          ParameterValues = algorithm.ParameterValues
    188183        };
    189         experiment.ExperimentCreators.Add(new ExperimentCreator() { UserId = user.Id });
    190184        okb.Experiments.InsertOnSubmit(experiment);
    191185        return experiment;
     
    292286    /// </summary>
    293287    /// <returns>
    294     ///   <c>true</c> if this instance is connected; otherwise, <c>false</c>.
     288    ///   <c>true</c> if this instance is connected; otherwise, <c>false</c>.
    295289    /// </returns>
    296290    public bool IsConnected() {
    297       return authentication != null;
    298     }
    299 
    300     Authentication authentication = null;
     291      return currentUser != null;
     292    }
     293
     294    User currentUser = null;
     295    Client currentClient = null;
    301296
    302297    /// <summary>
     
    309304    /// <param name="clientname">The clientname.</param>
    310305    /// <returns>
    311     ///   <c>true</c> if the login was successful; <c>false</c> otherwise.
     306    ///   <c>true</c> if the login was successful; <c>false</c> otherwise.
    312307    /// </returns>
    313308    public bool Login(string username, string clientname) {
     
    320315      }
    321316      using (OKBDataContext okb = new OKBDataContext()) {
    322         authentication = new Authentication() {
    323           User = okb.Users.SingleOrDefault(u => u.Name == username),
    324           Client = okb.Clients.SingleOrDefault(c => c.Name == clientname)
    325         };
    326         if (authentication.User == null) {
    327           User user = new User() { Name = username, Id = Guid.NewGuid() };
    328           okb.Users.InsertOnSubmit(user);
    329           authentication.User = user;
     317        currentUser = okb.Users.SingleOrDefault(u => u.Name == username);
     318        currentClient = okb.Clients.SingleOrDefault(c => c.Name == clientname);
     319        if (currentUser == null) {
     320          currentUser = new User() { Name = username, Id = Guid.NewGuid() };
     321          okb.Users.InsertOnSubmit(currentUser);
    330322          okb.SubmitChanges();
    331323        }
    332         if (authentication.Client == null) {
    333           Client client = new Client() { Name = clientname, Id = Guid.NewGuid() };
    334           okb.Clients.InsertOnSubmit(client);
    335           authentication.Client = client;
     324        if (currentClient == null) {
     325          currentClient = new Client() { Name = clientname, Id = Guid.NewGuid() };
     326          okb.Clients.InsertOnSubmit(currentClient);
    336327          okb.SubmitChanges();
    337328        }
    338         Log("  auth = {0}", authentication);
     329        Log("  user = {0}, client = {1}", currentUser, currentClient);
    339330        return true;
    340331      }
     
    346337    public void Logout() {
    347338      Log("Logging out");
    348       authentication = null;
     339      currentUser = null;
     340      currentClient = null;
    349341    }
    350342
  • trunk/sources/HeuristicLab.Services.OKB/3.3/TableService.cs

    r4279 r4298  
    6666    public void UpdateDataTable(DataTable updatedRows, string tableName) {
    6767      logger.Info("updating table: " + tableName);
    68       Type tableType = Assembly.GetAssembly(typeof(Run)).GetType("HeuristicLab.OKB." + tableName, true);
     68      Type tableType = Assembly.GetAssembly(typeof(Run)).GetType("HeuristicLab.Services.OKB.DataAccess." + tableName, true);
    6969      var properties = from p in tableType.GetProperties()
    7070                       where SupportedTypes.Contains(p.PropertyType)
     
    126126    public void DeleteTableRows(int[] ids, string tableName) {
    127127      logger.Info("delete rows from table: " + tableName);
    128       Type tableType = Assembly.GetAssembly(typeof(Run)).GetType("HeuristicLab.OKB." + tableName, true);
     128      Type tableType = Assembly.GetAssembly(typeof(Run)).GetType("HeuristicLab.Services.OKB.DataAccess" + tableName, true);
    129129      OKBDataContext okb = GetDataContext();
    130130      ITable table = okb.GetTable(tableType);
     
    148148    public DataTable PrepareDataTable(string tableName, out int count) {
    149149      logger.Info("preparing data table: " + tableName);
    150       Type tableType = Assembly.GetAssembly(typeof(Run)).GetType("HeuristicLab.OKB." + tableName, true);
     150      Type tableType = Assembly.GetAssembly(typeof(Run)).GetType("HeuristicLab.Services.OKB.DataAccess" + tableName, true);
    151151      properties = from p in tableType.GetProperties()
    152152                   where SupportedTypes.Contains(p.PropertyType)
  • trunk/sources/HeuristicLab.Services.OKB/3.3/app.config

    r4279 r4298  
    11<?xml version="1.0"?>
    22<configuration>
     3  <connectionStrings>
     4    <add name="HeuristicLab.Authentication"
     5         connectionString="data source=localhost;Integrated Security=SSPI;Initial Catalog=HeuristicLab.Authentication"/>
     6    <add name="HeuristicLab.Services.OKB.DataAccess.Properties.Settings.OKBConnectionString"
     7         connectionString="Data Source=localhost;Initial Catalog=HeuristicLab.OKB;Integrated Security=SSPI"
     8         providerName="System.Data.SqlClient" />
     9  </connectionStrings>
     10
     11  <system.web>
     12    <authentication mode="Forms" />
     13    <compilation debug="true" targetFramework="4.0" />
     14
     15    <membership>
     16      <providers>
     17        <clear/>
     18        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="HeuristicLab.Authentication"
     19             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
     20             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
     21             applicationName="HeuristicLab.Authentication" />
     22      </providers>
     23    </membership>
     24
     25    <roleManager enabled="true">
     26      <providers>
     27        <clear/>
     28        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="HeuristicLab.Authentication" applicationName="HeuristicLab.Authentication" />
     29      </providers>
     30    </roleManager>
     31  </system.web>
     32
    333  <system.serviceModel>
    434    <bindings>
    535      <netTcpBinding>
    636        <binding name="LargeMessages" openTimeout="00:00:30" receiveTimeout="00:00:30" sendTimeout="00:00:30" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
    7           <security mode="Transport">
    8             <transport clientCredentialType="Certificate" protectionLevel="EncryptAndSign"/>           
     37          <security mode="Message">
     38            <message clientCredentialType="UserName"/>
    939          </security>
    1040          <readerQuotas maxArrayLength="2147483647"/>
     
    1343      </netTcpBinding>
    1444    </bindings>
     45
    1546    <client/>
     47
    1648    <behaviors>
    1749      <serviceBehaviors>
     
    1951          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/OKB/RunnerMex"/>
    2052          <serviceDebug includeExceptionDetailInFaults="true"/>
     53          <serviceAuthorization principalPermissionMode="UseAspNetRoles"
     54                                roleProviderName="AspNetSqlRoleProvider" />
     55          <serviceCredentials>
     56            <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName" />
     57            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
     58                                    membershipProviderName="AspNetSqlMembershipProvider"/>
     59          </serviceCredentials>
    2160        </behavior>
    2261        <behavior name="AdminServiceBehaviour">
    2362          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/OKB/AdminMex"/>
    2463          <serviceDebug includeExceptionDetailInFaults="true"/>
     64          <serviceAuthorization principalPermissionMode="UseAspNetRoles"
     65                                roleProviderName="AspNetSqlRoleProvider" />
     66          <serviceCredentials>
     67            <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName" />
     68            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
     69                                    membershipProviderName="AspNetSqlMembershipProvider"/>
     70          </serviceCredentials>
    2571        </behavior>
    2672        <behavior name="TableServiceBehaviour">
    2773          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/OKB/TableMex"/>
    2874          <serviceDebug includeExceptionDetailInFaults="true"/>
     75          <serviceAuthorization principalPermissionMode="UseAspNetRoles"
     76                                roleProviderName="AspNetSqlRoleProvider" />
     77          <serviceCredentials>
     78            <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName" />
     79            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
     80                                    membershipProviderName="AspNetSqlMembershipProvider"/>
     81          </serviceCredentials>
    2982        </behavior>
    3083        <behavior name="QueryServiceBehaviour">
    3184          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/OKB/QueryMex"/>
    3285          <serviceDebug includeExceptionDetailInFaults="true"/>
     86          <serviceAuthorization principalPermissionMode="UseAspNetRoles"
     87                                roleProviderName="AspNetSqlRoleProvider" />
     88          <serviceCredentials>
     89            <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName" />
     90            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
     91                                    membershipProviderName="AspNetSqlMembershipProvider"/>
     92          </serviceCredentials>
    3393        </behavior>
    3494        <behavior name="DataServiceBehaviour">
    3595          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/OKB/DataMex"/>
    3696          <serviceDebug includeExceptionDetailInFaults="true"/>
     97          <serviceAuthorization principalPermissionMode="UseAspNetRoles"
     98                                roleProviderName="AspNetSqlRoleProvider" />
     99          <serviceCredentials>
     100            <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName" />
     101            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
     102                                    membershipProviderName="AspNetSqlMembershipProvider"/>
     103          </serviceCredentials>
    37104        </behavior>
    38105      </serviceBehaviors>
    39106    </behaviors>
     107
    40108    <services>
    41       <service behaviorConfiguration="RunnerServiceBehaviour" name="HeuristicLab.OKB.RunnerService">
     109      <service behaviorConfiguration="RunnerServiceBehaviour" name="HeuristicLab.Services.OKB.RunnerService">
    42110        <endpoint address="http://localhost:8000/OKB/RunnerMex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    43         <endpoint address="net.tcp://localhost:8001/OKB/RunnerService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.OKB.IRunnerService">
    44           <identity>
    45             <dns value="HEAL"/>
    46           </identity>
     111        <endpoint address="net.tcp://localhost:8001/OKB/RunnerService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.Services.OKB.IRunnerService">
    47112        </endpoint>
    48113      </service>
    49       <service behaviorConfiguration="AdminServiceBehaviour" name="HeuristicLab.OKB.AdminService">
     114      <service behaviorConfiguration="AdminServiceBehaviour" name="HeuristicLab.Services.OKB.AdminService">
    50115        <endpoint address="http://localhost:8000/OKB/AdminMex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    51         <endpoint address="net.tcp://localhost:8001/OKB/AdminService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.OKB.IAdminService"/>
     116        <endpoint address="net.tcp://localhost:8001/OKB/AdminService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.Services.OKB.IAdminService"/>
    52117      </service>
    53       <service behaviorConfiguration="TableServiceBehaviour" name="HeuristicLab.OKB.TableService">
     118      <service behaviorConfiguration="TableServiceBehaviour" name="HeuristicLab.Services.OKB.TableService">
    54119        <endpoint address="http://localhost:8000/OKB/TableMex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    55         <endpoint address="net.tcp://localhost:8001/OKB/TableService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.OKB.ITableService"/>
     120        <endpoint address="net.tcp://localhost:8001/OKB/TableService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.Services.OKB.ITableService"/>
    56121      </service>
    57       <service behaviorConfiguration="QueryServiceBehaviour" name="HeuristicLab.OKB.QueryService">
     122      <service behaviorConfiguration="QueryServiceBehaviour" name="HeuristicLab.Services.OKB.QueryService">
    58123        <endpoint address="http://localhost:8000/OKB/QueryMex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    59         <endpoint address="net.tcp://localhost:8001/OKB/QueryService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.OKB.IQueryService"/>
     124        <endpoint address="net.tcp://localhost:8001/OKB/QueryService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.Services.OKB.IQueryService"/>
    60125      </service>
    61       <service behaviorConfiguration="DataServiceBehaviour" name="HeuristicLab.OKB.DataService">
     126      <service behaviorConfiguration="DataServiceBehaviour" name="HeuristicLab.Services.OKB.DataService">
    62127        <endpoint address="http://localhost:8000/OKB/DataMex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    63         <endpoint address="net.tcp://localhost:8001/OKB/DataService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.OKB.IDataService"/>
     128        <endpoint address="net.tcp://localhost:8001/OKB/DataService" binding="netTcpBinding" bindingConfiguration="LargeMessages" contract="HeuristicLab.Services.OKB.IDataService"/>
    64129      </service>
    65130    </services>
Note: See TracChangeset for help on using the changeset viewer.