JAAS e autenticação de token

0 respostas
luuu

Estou implementando um sistema web que valida o login do usuario através do AuthSub do google ( que retorna um token ).
E através deste token eu queria que meu sistema apenas validasse o retorno dele e desse as credenciais necessárias para acesso.

Eu tentei fazer por aqui mas estou obtendo uma exception do tomcat

02/10/2009 17:37:54 org.apache.catalina.connector.CoyoteAdapter service
SEVERE: An exception or error occurred in the container during the request processing
java.lang.NullPointerException
	at java.util.Hashtable.put(Hashtable.java:396)
	at org.apache.catalina.session.StandardSession.setNote(StandardSession.java:907)
	at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:283)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:417)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	at java.lang.Thread.run(Thread.java:595)

Alguem saberia como resolver?

Meu LoginModule vai abaixo (não implementei nem abort nem logout ainda)


package com.generic.portal.security.auth;

import java.net.PasswordAuthentication;
import java.security.Principal;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;

public class PortalLoginModule implements LoginModule {

	 private User user;  
	 
	 private Set roles = new HashSet();  
	 
	 private boolean commitSucceeded;
	 
	 protected Subject subject;  
	 
	 protected CallbackHandler callbackHandler;  
	 
	 protected Map sharedState;  
	   
	 protected String authType;
	 
	 private String token;
	 
	 public void initialize(Subject subjectArg, CallbackHandler callbackHandlerArg,
			 Map sharedStateArg, Map optionsArg) {
		 
		 this.subject = subjectArg;
		 this.callbackHandler = callbackHandlerArg;
		 
		 this.sharedState = sharedStateArg;
		 
		 this.authType = (String) optionsArg.get("authType");
		 
		 System.out.println("****1");
	}
	 
	public boolean login() throws LoginException {
		if (callbackHandler == null)  
			throw new LoginException("Error: no CallbackHandler available to garner authentication information from the user");  
	  
		System.out.println("subject: "+subject);
		System.out.println("callbackHandler: "+callbackHandler);
		System.out.println("sharedState: "+sharedState);
		System.out.println();
		
		
		System.out.println("****2");
	    Callback[] callbacks = new Callback[1];  
	    callbacks[0] = new NameCallback("Token");  
	    
	    System.out.println("****3");
	    try {  
	        callbackHandler.handle(callbacks);  
	        
	        token = ((NameCallback) callbacks[0]).getName();
	        
	        System.out.println(token);
	        System.out.println("****4");
	        user = new User();
	        user.setName(token);
	        
	    } catch (java.io.IOException ioe) {  
	    	throw new LoginException(ioe.toString());  
	    } catch (UnsupportedCallbackException uce) {  
	        throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information from the user");  
	    }  
	    
	    Role role = new Role("LOGADO");
	    
	    roles.add(role);
	    System.out.println("****5");
	    sharedState.put("javax.security.auth.principal", user);  
	    sharedState.put("javax.security.auth.roles", roles);  
	    
	    System.out.println("****7");
	    return true;
	}
	
	
	public boolean commit() throws LoginException {
		
		System.out.println("****8");
		// adiciona o usuario no principals  
	    if (user != null && !subject.getPrincipals().contains(user)) {  
	    	System.out.println("*** IF ***");
	        subject.getPrincipals().add(user);  
	    }  
	    System.out.println("****9");
	    commitSucceeded = true;  
	    return true;  
	}
	
	public boolean abort() throws LoginException {
		// TODO Auto-generated method stub
		return true;
	}

		

	public boolean logout() throws LoginException {
		// TODO Auto-generated method stub
		return true;
	}

}

Obrigado!

Criado 2 de outubro de 2009
Respostas 0
Participantes 1