2016-04-07 7 views
0

認証がうまく動作し、チケットIDでクライアント側からユーザー名も取得します。パラメータを取得するには、以下のスクリプトを使用します。私はいくつかの方法で試しましたが、成功はありません。私はいつもユーザーネームを手に入れています。何か案は?新しいパラメータを追加するにはどうしたらいいですか? SQLとLDAPからデータをロードし、それらを属性リストに追加するサンプルがありますが、どれも機能しません。おそらく私の初心者のセットアップで何かがあります。私が追加したい情報はDBやLDAPから来ていないので、私は認証で受信した完全なカスタム情報(使用されているチャネルがそれを転送する)を追加したい。だからそれはカスタム属性が追加されているか、そういうものです。初期のコードは以下の通りです - >属性を追加しようとしていません。単に認証するだけの簡単なコードです。Jasig CAS 3.6 - 認証レスポンスに属性を追加できません

全体の構成は以下のとおりです。私はおそらく完全に欠落している何かあなたがサービスクライアント用のSAML応答メッセージの追加パラメータに追加する方法のアイデアや例を持っている場合... だから、私は:)

protected UserDetails loadUserDetails(Assertion assertion) { 
    ArrayList grantedAuthorities = new ArrayList(); 
    String[] arr$ = this.attributes; 
    int len$ = arr$.length; 

    for(int i$ = 0; i$ < len$; ++i$) { 
     String attribute = arr$[i$]; 
     Object value = assertion.getPrincipal().getAttributes().get(attribute); 
     if(value != null) { 
      if(value instanceof List) { 
       List list = (List)value; 
       Iterator i$1 = list.iterator(); 

       while(i$1.hasNext()) { 
        Object o = i$1.next(); 
        grantedAuthorities.add(new SimpleGrantedAuthority(this.convertToUpperCase?o.toString().toUpperCase():o.toString())); 
       } 
      } else { 
       grantedAuthorities.add(new SimpleGrantedAuthority(this.convertToUpperCase?value.toString().toUpperCase():value.toString())); 
      } 
     } 
    } 

    return new User(assertion.getPrincipal().getName(), "NO_PASSWORD", true, true, true, true, grantedAuthorities); 
} 

deployerConfigContext.xml大幅に感謝するでしょうしね。

<?xml version="1.0" encoding="UTF-8"?> 
... 
<bean id="attributeRepository" class="org.jasig.services.persondir.support.StubPersonAttributeDao"/> 

<bean id="authenticationManager" class="org.jasig.cas.authentication.AuthenticationManagerImpl"> 

    <property name="credentialsToPrincipalResolvers"> 
     <list> 
      <bean id="adPrincipalResolver" class="ee.qubova.cas.security.ad.ADPrincipalResolver"> 
       <property name="attributeRepository" ref="attributeRepository"/> 
      </bean> 
     </list> 
    </property> 
    <property name="authenticationHandlers"> 
     <list> 
      <bean class="ee.qubova.cas.security.CustomAuthenticationHandler"> 
      </bean> 
     </list> 
    </property> 
</bean> 


<sec:user-service id="userDetailsService"> 
    <sec:user name="test" password="test" authorities="ROLE_ADMIN"/> 
</sec:user-service> 


<bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl"> 
    <property name="registeredServices"> 
     <list> 
      <bean class="org.jasig.cas.services.RegisteredServiceImpl"> 
       <property name="id" value="0"/> 
       <property name="name" value="HTTP"/> 
       <property name="description" value="Only Allows HTTP Urls"/> 
       <property name="serviceId" value="http://**"/> 
       <property name="evaluationOrder" value="10000001"/> 
       <property name="allowedAttributes"> 
        <list> 
         <value>username</value> 
         <value>password</value> 
         <value>idCode</value> 
        </list> 
       </property> 
      </bean> 
     </list> 
    </property> 
</bean> 

<bean id="auditTrailManager" class="com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager"/> 
<bean id="healthCheckMonitor" class="org.jasig.cas.monitor.HealthCheckMonitor"> 
    <property name="monitors"> 
     <list> 
      <bean class="org.jasig.cas.monitor.MemoryMonitor" p:freeMemoryWarnThreshold="10"/> 
      <bean class="org.jasig.cas.monitor.SessionMonitor" p:ticketRegistry-ref="ticketRegistry" 
        p:serviceTicketCountWarnThreshold="5000" p:sessionCountWarnThreshold="100000"/> 
     </list> 
    </property> 
</bean> 

<bean id="utils" class="ee.qubova.cas.utils.Utils"> 
    <property name="trustedIssuerDnPattern" value=".*"/> 
</bean> 

<bean id="idCardLoginController" class="ee.qubova.cas.security.idcard.X509Controller"> 
    <property name="centralAuthenticationService" ref="centralAuthenticationService"/> 
    <property name="cookieGenerator" ref="ticketGrantingTicketCookieGenerator"/> 
    <property name="argumentExtractors" ref="argumentExtractors"/> 
    <property name="utils" ref="utils"/> 
</bean> 

<bean id="adLoginController" class="ee.qubova.cas.security.ad.ADLoginController"> 
    <property name="centralAuthenticationService" ref="centralAuthenticationService"/> 
    <property name="cookieGenerator" ref="ticketGrantingTicketCookieGenerator"/> 
    <property name="argumentExtractors" ref="argumentExtractors"/> 
    <property name="utils" ref="utils"/> 
</bean> 

public class ADPrincipalResolver extends AbstractPersonDirectoryCredentialsToPrincipalResolver { 
protected String extractPrincipalId(final Credentials credentials) { 
    final ADCredentials adCredentials = (ADCredentials) credentials; 
    return adCredentials.getIdCode(); 
} 

public boolean supports(final Credentials credentials) { 
    return credentials != null && ADCredentials.class.isAssignableFrom(credentials.getClass()); 
} 

}

public class ADCredentials extends AbstractCASUserProfile { 
private String username; 
private String password; 

public ADCredentials(String idCode, String username, String password) { 
    super.setIdCode(idCode); 
    this.username = username; 
    this.password = password; 
} 


public String getUsername() { 
    return username; 
} 

public void setUsername(String username) { 
    this.username = username; 
} 

public String getPassword() { 
    return password; 
} 

public void setPassword(String password) { 
    this.password = password; 
} 

}

public class CustomAuthenticationHandler implements AuthenticationHandler { 

public boolean authenticate(Credentials credentials) throws AuthenticationException { 
    if (credentials == null) { 
     return false; 
    } 

    if (credentials instanceof ADCredentials) { 
     ADCredentials c = (ADCredentials) credentials; 
     if (StringUtils.hasLength(c.getIdCode())) { 
      return true; 
     } 
    } 
    return false; 
} 

public boolean supports(Credentials credentials) { 
    return credentials != null 
      && credentials instanceof ADCredentials; 
} 

}

とCAS-servlet.xmlで

<bean 
    id="handlerMappingC" 
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
<property name="mappings"> 
    <props> 
    <prop key="/adlogin">adLoginController</prop> 

答えて

0

CAS3は、デフォルトでは、属性を解放しません。これはsamlValidateによってのみ実行されます。 serviceValidateを使用している場合は、最終的なCASレスポンスを生成するJSPファイルを変更し、属性を手動で追加する必要があります。 https://wiki.jasig.org/display/casum/attributes

を参照してください。CAS3はEOLです。将来のバージョンのCASではこれが自動的に行われます。

関連する問題