~ubuntu-branches/ubuntu/maverick/eucalyptus/maverick

« back to all changes in this revision

Viewing changes to clc/modules/msgs/src/main/java/com/eucalyptus/auth/api/BaseLoginModule.java

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey)
  • Date: 2010-07-21 17:27:10 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20100721172710-7xv07dmdqgivc3t9
Tags: 2.0~bzr1211-0ubuntu1
* New major upstream version merge, 2.0 (r1211).
* debian/patches/:
  - 01-wsdl-stubs.patch, debian/wsdl.md5sums: wsdl stubs updated.
  - 02-Makefile.patch: Updated to reflect new code layout.
  - 07-local_support_euca_conf-in.patch: Updated to reflect new code layout.
  - 08-ubuntu-default-networking.patch: Refreshed.
  - 09-small-128-192MB.patch: Updated to point to new location.
  - 10-disable-iscsi.patch: Refreshed.
  - 11-state-cleanup-memleakfix.patch: Removed, fixed upstream.
  - 15-fix-default-ramdisk.patch: Updated to point to new location.
  - 16-kvm_libvirt_xml_default_use_kvm.patch: Updated to reflect changes.
  - 17-fix_walrus_OOM_errors.patch: Removed, fixed upstream.
  - 18-priv_security.patch: Updated to reflect upstream changes.
  - 20-brute-force-webui.patch: Updated to reflect upstream changes. 
  - 21-eucalyptus-1.7-with-gwt-1.6.4.patch: New patch, allows 
    eucalyptus-1.7 to be built against gwt 1.6.4. Based on patch courtesy 
    of Dmitrii Zagorodnov, upstream. (LP: #597330)
* debian/eucalyptus-java-common.links: 
  - Changed symlink for groovy, point to groovy.all.jar, making compatiable 
    with groovy versions >1.7. (LP: #595421)
  - Added ant.jar & jetty-rewrite-handler.jar as they are now required.
* debian/control
  - & debian/build-jars: Added libjavassist-java and libjetty-extra-java as 
    build dependencies.
  - Added libjetty-extra-java as a dependency of eucalyptus-java-common
* The binary resulting jar's have been renamed from eucalyptus-*-1.6.2.jar
  to eucalyptus-*-main.jar:    
  - debian/eucalyptus-cc.upstart
  - debian/eucalyptus-cloud.install
  - debian/eucalyptus-common.eucalyptus.upstart
  - debian/eucalyptus-java-common.install
  - debian/eucalyptus-network.upstart
  - debian/eucalyptus-sc.install
  - debian/eucalyptus-walrus.install
* debian/eucalyptus-java-common.install: New upstream jars that have been
  installed:
  - eucalyptus-db-hsqldb-ext-main.jar
  - eucalyptus-component-main.jar
* debian/control:
  - Updated Standards Version to 3.8.4 (no change)
  - Updated the upstream Homepage to: http://open.eucalyptus.com/
  - Changed Vcs-Bzr to reflect new location of Ubuntu hosted development branch.
  - Made the Build Dependency of groovy and the binary eucalyptus-java-common
    package depend on version >=1.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.eucalyptus.auth.api;
 
2
 
 
3
import java.util.List;
 
4
import java.util.Map;
 
5
import javax.security.auth.Subject;
 
6
import javax.security.auth.callback.CallbackHandler;
 
7
import javax.security.auth.login.LoginException;
 
8
import javax.security.auth.spi.LoginModule;
 
9
import org.apache.log4j.Logger;
 
10
import com.eucalyptus.auth.Users;
 
11
import com.eucalyptus.auth.login.WrappedCredentials;
 
12
import com.eucalyptus.auth.principal.Group;
 
13
import com.eucalyptus.auth.principal.User;
 
14
import com.eucalyptus.context.Contexts;
 
15
import com.eucalyptus.context.NoSuchContextException;
 
16
import com.google.common.collect.Lists;
 
17
 
 
18
public abstract class BaseLoginModule<CB extends WrappedCredentials> implements LoginModule {
 
19
  private static Logger   LOG           = Logger.getLogger( BaseLoginModule.class );
 
20
  private boolean         authenticated = false;
 
21
  private CallbackHandler callbackHandler;
 
22
  private Object          credential;
 
23
  private List<Group>     groups = Lists.newArrayList( );
 
24
  private User            principal;
 
25
  private Subject         subject;
 
26
  private CB              wrappedCredentials;
 
27
  
 
28
  @Override
 
29
  public boolean abort( ) throws LoginException {
 
30
    LOG.debug( "Login aborted." );
 
31
    this.reset( );
 
32
    return true;
 
33
  }
 
34
  
 
35
  @Override
 
36
  public final boolean commit( ) throws LoginException {
 
37
    if ( !this.isAuthenticated( ) ) {
 
38
      return false;
 
39
    }
 
40
    this.getSubject( ).getPrincipals( ).add( this.getPrincipal( ) );
 
41
    this.getSubject( ).getPrincipals( ).addAll( this.getGroups( ) );
 
42
    this.getSubject( ).getPublicCredentials( ).add( this.getCredential( ) );
 
43
    try {
 
44
      Contexts.lookup( this.getWrappedCredentials( ).getCorrelationId( ) ).setUser( this.getPrincipal( ) );
 
45
      Contexts.lookup( this.getWrappedCredentials( ).getCorrelationId( ) ).setSubject( this.getSubject( ) );
 
46
    } catch ( final NoSuchContextException e ) {
 
47
      BaseLoginModule.LOG.debug( e, e );
 
48
      this.authenticated = false;
 
49
    }
 
50
    return this.authenticated;
 
51
  }
 
52
  
 
53
  public CallbackHandler getCallbackHandler( ) {
 
54
    return this.callbackHandler;
 
55
  }
 
56
  
 
57
  public Object getCredential( ) {
 
58
    return this.credential;
 
59
  }
 
60
  
 
61
  public List<Group> getGroups( ) {
 
62
    return this.groups;
 
63
  }
 
64
  
 
65
  public User getPrincipal( ) {
 
66
    return this.principal;
 
67
  }
 
68
  
 
69
  public Subject getSubject( ) {
 
70
    return this.subject;
 
71
  }
 
72
  
 
73
  public CB getWrappedCredentials( ) {
 
74
    return this.wrappedCredentials;
 
75
  }
 
76
  
 
77
  public abstract boolean accepts( );
 
78
  
 
79
  @Override
 
80
  public void initialize( final Subject subject, final CallbackHandler callbackHandler, final Map<String, ?> sharedState, final Map<String, ?> options ) {
 
81
    this.subject = subject;
 
82
    this.callbackHandler = callbackHandler;
 
83
    if ( this.accepts( ) ) {
 
84
      this.wrappedCredentials = ( CB ) callbackHandler;
 
85
    } else {
 
86
      this.wrappedCredentials = null;
 
87
    }
 
88
  }
 
89
  
 
90
  private boolean isAuthenticated( ) {
 
91
    return this.authenticated;
 
92
  }
 
93
  
 
94
  @Override
 
95
  public boolean login( ) throws LoginException {
 
96
    if ( this.wrappedCredentials == null ) {
 
97
      return false;
 
98
    }
 
99
    try {
 
100
      this.setAuthenticated( this.authenticate( this.wrappedCredentials ) );
 
101
    } catch ( final Exception e ) {
 
102
      LOG.debug( e, e );
 
103
      this.setAuthenticated( false );
 
104
      throw new LoginException( e.getMessage( ) );
 
105
    }
 
106
    return this.isAuthenticated( );
 
107
  }
 
108
  
 
109
  public abstract boolean authenticate( CB credentials ) throws Exception;
 
110
  
 
111
  @Override
 
112
  public boolean logout( ) throws LoginException {
 
113
    this.baseReset( );
 
114
    this.reset( );
 
115
    return true;
 
116
  }
 
117
  
 
118
  public void reset( ) {}
 
119
  
 
120
  private void setAuthenticated( final boolean authenticated ) {
 
121
    this.authenticated = authenticated;
 
122
  }
 
123
  
 
124
  public void setCredential( final Object credential ) {
 
125
    this.credential = credential;
 
126
  }
 
127
  
 
128
  public void setPrincipal( final User principal ) {
 
129
    this.principal = principal;
 
130
  }
 
131
  
 
132
  public void setWrappedCredentials( final CB wrappedCredentials ) {
 
133
    this.wrappedCredentials = wrappedCredentials;
 
134
  }
 
135
  
 
136
  private void baseReset( ) {
 
137
    if ( this.principal != null ) {
 
138
      this.subject.getPrincipals( ).remove( this.principal );
 
139
      this.principal = null;
 
140
    }
 
141
    if ( this.getCredential( ) != null ) {
 
142
      this.getSubject( ).getPublicCredentials( ).remove( this.getCredential( ) );
 
143
      this.credential = null;
 
144
    }
 
145
    this.wrappedCredentials = null;
 
146
    this.authenticated = false;
 
147
    this.callbackHandler = null;
 
148
    this.groups = Lists.newArrayList( );
 
149
  }
 
150
  
 
151
}