~dstroppa/juju-core/joyent-provider-storage

« back to all changes in this revision

Viewing changes to state/apiserver/admin.go

  • Committer: Daniele Stroppa
  • Date: 2014-01-08 15:58:10 UTC
  • mfrom: (1953.1.231 juju-core)
  • Revision ID: daniele.stroppa@joyent.com-20140108155810-xecbwrqkb5i0fyoe
Merging trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
                // This can only happen if Login is called concurrently.
71
71
                return errAlreadyLoggedIn
72
72
        }
73
 
        entity0, err := a.root.srv.state.FindEntity(c.AuthTag)
 
73
        entity, err := checkCreds(a.root.srv.state, c)
 
74
        if err != nil {
 
75
                return err
 
76
        }
 
77
        if a.loginCallback != nil {
 
78
                a.loginCallback(entity.Tag())
 
79
        }
 
80
        // We have authenticated the user; now choose an appropriate API
 
81
        // to serve to them.
 
82
        newRoot, err := a.apiRootForEntity(entity, c)
 
83
        if err != nil {
 
84
                return err
 
85
        }
 
86
 
 
87
        a.root.rpcConn.Serve(newRoot, serverError)
 
88
        return nil
 
89
}
 
90
 
 
91
func checkCreds(st *state.State, c params.Creds) (taggedAuthenticator, error) {
 
92
        entity0, err := st.FindEntity(c.AuthTag)
74
93
        if err != nil && !errors.IsNotFoundError(err) {
75
 
                return err
 
94
                return nil, err
76
95
        }
77
96
        // We return the same error when an entity
78
97
        // does not exist as for a bad password, so that
80
99
        // about existing entities.
81
100
        entity, ok := entity0.(taggedAuthenticator)
82
101
        if !ok {
83
 
                return common.ErrBadCreds
 
102
                return nil, common.ErrBadCreds
84
103
        }
85
104
        if err != nil || !entity.PasswordValid(c.Password) {
86
 
                return common.ErrBadCreds
87
 
        }
88
 
        if a.loginCallback != nil {
89
 
                a.loginCallback(entity.Tag())
90
 
        }
91
 
        // We have authenticated the user; now choose an appropriate API
92
 
        // to serve to them.
93
 
        newRoot, err := a.apiRootForEntity(entity, c)
94
 
        if err != nil {
95
 
                return err
96
 
        }
97
 
 
98
 
        a.root.rpcConn.Serve(newRoot, serverError)
99
 
        return nil
 
105
                return nil, common.ErrBadCreds
 
106
        }
 
107
        return entity, nil
100
108
}
101
109
 
102
110
// machinePinger wraps a presence.Pinger.