Created
September 25, 2017 19:48
-
-
Save chongma/ee6836f99b1ba62b79851c9da050c81f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one | |
or more contributor license agreements. See the NOTICE file | |
distributed with this work for additional information | |
regarding copyright ownership. The ASF licenses this file | |
to you under the Apache License, Version 2.0 (the | |
"License"); you may not use this file except in compliance | |
with the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, | |
software distributed under the License is distributed on an | |
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
KIND, either express or implied. See the License for the | |
specific language governing permissions and limitations | |
under the License. | |
--> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:util="http://www.springframework.org/schema/util" | |
xmlns:jaxws="http://cxf.apache.org/jaxws" | |
xsi:schemaLocation=" | |
http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd | |
http://www.springframework.org/schema/util | |
http://www.springframework.org/schema/util/spring-util-4.3.xsd | |
http://cxf.apache.org/jaxws | |
http://cxf.apache.org/schemas/jaxws.xsd"> | |
<util:list id="claimHandlerList"> | |
<ref bean="userClaimsHandler" /> | |
</util:list> | |
<bean id="userClaimsHandler" class="org.apache.cxf.fediz.service.sts.realms.RealmLoginModuleClaimsHandler"> | |
<property name="supportedClaims" ref="supportedClaims" /> | |
<property name="realm" value="REALMA" /> | |
</bean> | |
<util:list id="supportedClaims"> | |
<value>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname</value> | |
<value>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname</value> | |
<value>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress</value> | |
<value>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role</value> | |
</util:list> | |
<jaxws:endpoint id="transportSTS1" implementor="#transportSTSProviderBean" | |
address="/REALMA/STSServiceTransportUT" wsdlLocation="/WEB-INF/wsdl/ws-trust-1.4-service.wsdl" | |
xmlns:ns1="http://docs.oasis-open.org/ws-sx/ws-trust/200512/" | |
serviceName="ns1:SecurityTokenService" endpointName="ns1:TransportUT_Port"> | |
<jaxws:properties> | |
<entry key="ws-security.ut.validator"> | |
<bean class="org.apache.wss4j.dom.validate.JAASUsernameTokenValidator"> | |
<property name="contextName" value="MyLoginModule" /> | |
</bean> | |
</entry> | |
</jaxws:properties> | |
</jaxws:endpoint> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Licensed to the Apache Software Foundation (ASF) under one | |
* or more contributor license agreements. See the NOTICE file | |
* distributed with this work for additional information | |
* regarding copyright ownership. The ASF licenses this file | |
* to you under the Apache License, Version 2.0 (the | |
* "License"); you may not use this file except in compliance | |
* with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, | |
* software distributed under the License is distributed on an | |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
* KIND, either express or implied. See the License for the | |
* specific language governing permissions and limitations | |
* under the License. | |
*/ | |
package org.apache.cxf.fediz.service.sts.realms; | |
import java.security.Principal; | |
import java.net.URI; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.logging.Logger; | |
import org.apache.cxf.common.logging.LogUtils; | |
import org.apache.cxf.rt.security.claims.Claim; | |
import org.apache.cxf.rt.security.claims.ClaimCollection; | |
import org.apache.cxf.sts.claims.ClaimsHandler; | |
import org.apache.cxf.sts.claims.ClaimsParameters; | |
import org.apache.cxf.sts.claims.ProcessedClaim; | |
import org.apache.cxf.sts.claims.ProcessedClaimCollection; | |
/** | |
* A custom ClaimsHandler implementation for use with "jaas.xml" | |
*/ | |
public class RealmLoginModuleClaimsHandler implements ClaimsHandler { | |
private static final Logger LOG = LogUtils.getL7dLogger(RealmLoginModuleClaimsHandler.class); | |
private List<URI> supportedClaims; | |
private String realm; | |
public void setSupportedClaims(List<URI> supportedClaims) { | |
this.supportedClaims = supportedClaims; | |
} | |
public void setRealm(String realm) { | |
this.realm = realm; | |
} | |
public String getRealm() { | |
return realm; | |
} | |
@Override | |
public List<URI> getSupportedClaimTypes() { | |
return Collections.unmodifiableList(this.supportedClaims); | |
} | |
@Override | |
public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claims, | |
ClaimsParameters parameters) { | |
if (parameters.getRealm() == null || !parameters.getRealm().equalsIgnoreCase(getRealm())) { | |
LOG.fine("Realm '" + parameters.getRealm() + "' doesn't match with configured realm '" + getRealm() + "'"); | |
return new ProcessedClaimCollection(); | |
} | |
if (parameters.getPrincipal() == null) { | |
return new ProcessedClaimCollection(); | |
} | |
if (claims == null || claims.isEmpty()) { | |
LOG.fine("No claims requested"); | |
return new ProcessedClaimCollection(); | |
} | |
if (parameters.getRoles() == null || parameters.getRoles().isEmpty()) { | |
LOG.fine("Claims requested for principal '" + parameters.getPrincipal().getName() | |
+ "' but not found"); | |
return new ProcessedClaimCollection(); | |
} | |
LOG.fine("Claims found for principal '" + parameters.getPrincipal().getName() + "'"); | |
if (!claims.isEmpty()) { | |
ProcessedClaimCollection claimCollection = new ProcessedClaimCollection(); | |
for (Claim requestClaim : claims) { | |
for (Principal role : parameters.getRoles()) { | |
if (role.getName().equals(requestClaim.getClaimType().toString())) { | |
ProcessedClaim claim = new ProcessedClaim(); | |
claim.setClaimType(requestClaim.getClaimType()); | |
claim.setIssuer("Test Issuer"); | |
claim.setOriginalIssuer("Original Issuer"); | |
claim.addValue(role.getName()); | |
claimCollection.add(claim); | |
} | |
} | |
} | |
return claimCollection; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment