4 Replies Latest reply on Dec 15, 2006 8:51 AM by Sohil Shah

    Classcast exception in LoginContext.getAttributeNames()

    Nick Woods Newbie

      Me again :-)

      I've implemented my own login provider, and to try to get a better understanding of whats being passed into it I added some debugging.

      However, I added a call to LoginContext.getAttributeNames() and am now getting a ClassCast exception from the getAttributeNames() method :-

      2006-12-14 16:14:06,370 DEBUG [org.jboss.security.valve.PlainSSOAutoLogin] ssoLogin() started provider=si:njw-sso:njw:login
      2006-12-14 16:14:06,401 DEBUG [com.njw.NWLoginProvider] getId() started - returning id="si:njw-sso:njw:login"
      2006-12-14 16:14:06,401 DEBUG [org.jboss.security.valve.PlainSSOAutoLogin] ssoLogin() loginProvider=NWLoginProvider si:njw-sso:njw:login
      2006-12-14 16:14:06,401 DEBUG [com.njw.NWLoginProvider] exists(username) started - username=fgfgfgfgfgfgfgfgfgf
      2006-12-14 16:14:06,401 DEBUG [org.jboss.security.valve.PlainSSOAutoLogin] ssoLogin() success=true
      2006-12-14 16:14:06,417 DEBUG [com.njw.NWLoginProvider] processSSOLoginNotification() logonContext=org.jboss.security.idm.LoginContext@f2ff9b
      2006-12-14 16:14:06,417 ERROR [STDERR] java.lang.ClassCastException: [Ljava.lang.Object;
      2006-12-14 16:14:06,417 ERROR [STDERR] at org.jboss.security.idm.LoginContext.getAttributeNames(LoginContext.java:99)
      2006-12-14 16:14:06,417 ERROR [STDERR] at com.njw.NWLoginProvider.processSSOLoginNotification(NWLoginProvider.java:39)
      2006-12-14 16:14:06,417 ERROR [STDERR] at org.jboss.security.valve.PlainSSOAutoLogin.ssoLogin(PlainSSOAutoLogin.java:322)
      


      my code :-
      public void processSSOLoginNotification(LoginContext argLoginContext) throws IdentityException {
       this.loginContext = argLoginContext;
       log.debug("processSSOLoginNotification() logonContext=" + this.loginContext);
      
       String[] attributes = this.loginContext.getAttributeNames();
      


      decompiled LoginContext code
      public final class LoginContext
       implements Serializable
      {
      
       public LoginContext()
       {
      /* 41*/ contextMap = null;
      /* 67*/ contextMap = new HashMap();
       }
      
       public Object getAttribute(String name)
       {
      /* 78*/ return contextMap.get(name);
       }
      
       public void setAttribute(String name, Object value)
       {
      /* 89*/ contextMap.put(name, value);
       }
      
       public String[] getAttributeNames()
       {
      /* 99*/ return (String[])(String[])contextMap.keySet().toArray();
       }
      
       private Map contextMap;
       public static final String HTTP_REQUEST = "http_request";
       public static final String HTTP_RESPONSE = "http_response";
       public static final String SSO_USER = "jboss_sso_user";
      }
      


      revised code with additional debugging
       public String[] getAttributeNames()
       {
       if (contextMap == null){
       log.debug("no attributes");
       return null;
       }
       else
       {
       log.debug("Attribute count=" + this.contextMap.size() + " keyset=" + contextMap.keySet());
       for (Object key:contextMap.keySet()) {
       log.debug("key=" + key + " value=" + this.contextMap.get(key) );
       }
      
       return (String[])this.contextMap.keySet().toArray();
       }
       }
      
      


      log from revised code
      2006-12-14 16:41:01,677 DEBUG [org.jboss.security.valve.PlainSSOAutoLogin] ssoLogin() started provider=si:njw-sso:njw:login
      2006-12-14 16:41:01,708 DEBUG [com.njw.NWLoginProvider] getId() started - returning id="si:njw-sso:njw:login"
      2006-12-14 16:41:01,708 DEBUG [org.jboss.security.valve.PlainSSOAutoLogin] ssoLogin() loginProvider=NWLoginProvider si:njw-sso:njw:login
      2006-12-14 16:41:01,708 DEBUG [com.njw.NWLoginProvider] exists(username) started - username=kkkkkkkkkk
      2006-12-14 16:41:01,708 DEBUG [org.jboss.security.valve.PlainSSOAutoLogin] ssoLogin() success=true
      2006-12-14 16:41:01,708 DEBUG [org.jboss.security.idm.LoginContext] setAttribute name=http_request value=org.apache.catalina.connector.Request@bfccfc
      2006-12-14 16:41:01,708 DEBUG [org.jboss.security.idm.LoginContext] setAttribute name=http_response value=org.apache.catalina.connector.Response@2ad6a0
      2006-12-14 16:41:01,708 DEBUG [org.jboss.security.idm.LoginContext] setAttribute name=jboss_sso_user value=org.jboss.security.saml.SSOUser@70c242
      2006-12-14 16:41:01,724 DEBUG [com.njw.NWLoginProvider] processSSOLoginNotification() logonContext=org.jboss.security.idm.LoginContext@e1b3b3
      2006-12-14 16:41:01,724 DEBUG [org.jboss.security.idm.LoginContext] Attribute count=3 keyset=[http_request, jboss_sso_user, http_response]
      2006-12-14 16:41:01,724 DEBUG [org.jboss.security.idm.LoginContext] key=http_request value=org.apache.catalina.connector.Request@bfccfc
      2006-12-14 16:41:01,724 DEBUG [org.jboss.security.idm.LoginContext] key=jboss_sso_user value=org.jboss.security.saml.SSOUser@70c242
      2006-12-14 16:41:01,724 DEBUG [org.jboss.security.idm.LoginContext] key=http_response value=org.apache.catalina.connector.Response@2ad6a0
      2006-12-14 16:41:01,724 ERROR [STDERR] java.lang.ClassCastException: [Ljava.lang.Object;
      2006-12-14 16:41:01,755 ERROR [STDERR] at org.jboss.security.idm.LoginContext.getAttributeNames(LoginContext.java:114)