auth

Paddy 2015-04-11 Parent:cf6c1f05eb21 Child:73e12d5a1124

162:6f473576c6ae Go to Latest

auth/session.go

Clean up sessions and tokens after Profile is deleted. Add a terminateSessionsByProfile method to our sessionStore to mark Sessions associated with a Profile as inactive. Implement memstore and postgres implementations of the terminateSessionsByProfile method. Add a TerminateSessionsByProfile wrapper method to Context. Add a revokeTokensByProfileID method to our tokenStore to mark Tokens associated with a Profile as revoked. Implement memstore and postgres implementation of the revokeTokensByProfileID method. Add a RevokeTokensByProfileID wrapper method to Context. Call our RevokeTokensByProfileID and TerminateSessionsByProfile methods after a Profile is deleted, to clean up the Tokens and Sessions associated with it.

History
     1.1 --- a/session.go	Sat Apr 11 17:58:15 2015 -0400
     1.2 +++ b/session.go	Sat Apr 11 19:07:26 2015 -0400
     1.3 @@ -94,6 +94,7 @@
     1.4  	terminateSession(id string) error
     1.5  	removeSession(id string) error
     1.6  	listSessions(profile uuid.ID, before time.Time, num int64) ([]Session, error)
     1.7 +	terminateSessionsByProfile(profile uuid.ID) error
     1.8  }
     1.9  
    1.10  func (m *memstore) createSession(session Session) error {
    1.11 @@ -127,6 +128,23 @@
    1.12  	return nil
    1.13  }
    1.14  
    1.15 +func (m *memstore) terminateSessionsByProfile(profile uuid.ID) error {
    1.16 +	m.sessionLock.RLock()
    1.17 +	defer m.sessionLock.RUnlock()
    1.18 +	var found bool
    1.19 +	for _, session := range m.sessions {
    1.20 +		if profile.Equal(session.ProfileID) {
    1.21 +			session.Active = false
    1.22 +			m.sessions[session.ID] = session
    1.23 +			found = true
    1.24 +		}
    1.25 +	}
    1.26 +	if !found {
    1.27 +		return ErrProfileNotFound
    1.28 +	}
    1.29 +	return nil
    1.30 +}
    1.31 +
    1.32  func (m *memstore) removeSession(id string) error {
    1.33  	m.sessionLock.Lock()
    1.34  	defer m.sessionLock.Unlock()