Bir sunucuya dağıtılmış bir REST hizmetim var ve bunu WSO2 ESB aracılığıyla açığa çıkarmak (proxy) ve hizmete erişimi güven altına almak için ESB güvenliğini kullanmak (büyük olasılıkla görüntülenen HTTP BASIC kimlik doğrulaması) ESB kullanıcı veritabanında kullanıcı adı ve şifre ile). Nasıl yapılacağını açıklayan iyi bir doküman bulamıyorum. Bu WSO2 ESB kullanarak nasıl yapılabilir?WSO2 kullanarak yeniden çalışmaya başlama ESB
10
A
cevap
4
1
Sen ileriye o bunları kolayca çağırabilir REST API ile teslimat yapıyorsa, WSO2 ESB ref nasıl REST API involoves üzerinde kapsamlı bir anlayış elde edebilirsiniz WSO2 ile, bu amaç için ESB 4.0.2 DİNLENME API kullanabilirsiniz REST API Article
1
Kullanıcılar ile http temel Authenticathion için wso2-esb formu kullanıyorum bu dizileri kullanıyorum.
<sequence xmlns="http://ws.apache.org/ns/synapse" name="ValidacionHttpBasica">
<property name="isAuthorized" value="0" scope="default" type="STRING"/>
<class name="org.wso2.security.HttpBasicAuthOpMediator"/>
<switch source="get-property('isAuthorized')">
<case regex="0">
<property name="HTTP_SC" value="401" scope="axis2" type="STRING"/>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:Server"/>
<reason value="Not Authorized"/>
<role/>
</makefault>
<respond/>
</case>
<default/>
</switch>
</sequence>
org.wso2.security.HttpBasicAuthOpMediator (wso2-esb 4.9.0)
package org.wso2.security;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import org.apache.synapse.MessageContext;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.user.api.UserStoreException;
public class HttpBasicAuthOpMediator extends AbstractMediator {
private static final Logger LOGGER = Logger.getLogger(HttpBasicAuthOpMediator.class);
/* (non-Javadoc)
* @see org.apache.synapse.Mediator#mediate(org.apache.synapse.MessageContext)
*/
public boolean mediate(MessageContext msgctx) {
boolean isOK = true;
try {
//trazearDatos(msgctx);
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) msgctx)
.getAxis2MessageContext();
Map<String,String> mHeaders = (Map<String,String>)axis2MessageContext.getProperty("TRANSPORT_HEADERS");
// 1 - Validacion de cabeceras de seguridad
String securityHeader = mHeaders.get("Authorization");
if (securityHeader==null || securityHeader.trim().length()<7) {
throw new RuntimeException ("Request sin cabecera de Autorizacion");
}
// 2 - Validacion de usuario-contrasenya
String user = validarUsuario(securityHeader);
// 3 - validacion de operacion asociada a un rol
if (msgctx.getProperty("SECURITY_OPERATION")!=null && msgctx.getProperty("SECURITY_OPERATION").toString().equalsIgnoreCase("1")) {
validarOperacion(user, mHeaders.get("SOAPAction"), msgctx);
}
// todo ha ido bien, esta autorizado
msgctx.setProperty("isAuthorized", "1");
} catch (Exception e) {
LOGGER.info("ERROR VALIDACION USUARIO ..." + e.getMessage());
//isOK = false;
}
return isOK;
}
/**
* Comprueba que el usuario tiene los roles asociados a la operacion.
* Si el usuario no tiene los roles, lanza un runtimeExcpetion
* @param operacion, que se obtiene del soapAction de la cabecera http
* @param messageContext
*/
private void validarOperacion(String user, String operacion, MessageContext messageContext) {
operacion = operacion.replaceAll("\"", "");
operacion = operacion.replaceAll("'", "");
//obtener los roles asociados a la operacion
if (messageContext.getProperty("SECURITY_OPERATION_" + operacion)!= null) {
boolean existeRol = false;
try {
String[] rolesOperation = messageContext.getProperty("SECURITY_OPERATION_" + operacion).toString().split(",");
Map<String,String> mRolesUser = toMap(CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager().getRoleListOfUser(user));
for (String rol : rolesOperation) {
if (mRolesUser.containsKey(rol)) {
existeRol = true;
break;
}
}
if (!existeRol) {
throw new RuntimeException("Usuario sin role para ejecutar operacion");
}
} catch (Exception e) {
throw new RuntimeException("ValidaRoleOperacion:" + e.getMessage());
}
}
}
/**
* Valida si la cabecera contiene un usuario-contrsenya valido en wso2.
* Si no lo encuentra lanza un RuntimeExpception.
* @param cabecera http-header que contiene el usuario-contrsenya en base64.
*/
private String validarUsuario(String cabecera) {
String credentials = cabecera.substring(6).trim();
String decodedCredentials = new String(new Base64().decode(credentials.getBytes()));
String userName = decodedCredentials.split(":")[0];
String password = decodedCredentials.split(":")[1];
//CarbonContext ctx = CarbonContext.getCurrentContext();
CarbonContext ctx = CarbonContext.getThreadLocalCarbonContext();
try {
if (!ctx.getUserRealm().getUserStoreManager().authenticate(userName, password)) {
throw new RuntimeException("Usuario-contrasenya incorrecto");
}
} catch (UserStoreException e) {
throw new RuntimeException("UserStoreException:" + e.getMessage());
}
return userName;
}
public void trazearDatos(MessageContext msgctx) {
try {
System.out.println("....INICIO_TRAZEO DATOS...............");
// CABECERAS HTTP para pbtener operacion, user-password. Es un Map<String, String>
if (msgctx.getProperty("TRANSPORT_HEADERS") != null) {
Map<String,String> mHeaders = (Map<String,String>)msgctx.getProperty("TRANSPORT_HEADERS");
for (String key:mHeaders.keySet()) {
System.out.println("HEADER_HTTP..." + key + "==" + mHeaders.get(key));
}
} else {
System.out.println("Es nulo TRANSJPPORT_HEADER, casteamos");
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) msgctx)
.getAxis2MessageContext();
Map<String,String> mHeaders = (Map<String,String>)axis2MessageContext.getProperty("TRANSPORT_HEADERS");
for (String key:mHeaders.keySet()) {
System.out.println("(cast) HEADER_HTTP..." + key + "==" + mHeaders.get(key));
}
}
// PROPERTIES DEL MESSAGE_CONTEXT
String keyMC;
for (Object keyObject : msgctx.getPropertyKeySet()) {
keyMC = (String)keyObject;
System.out.println("PROPERTIES_CONTEXT..." + keyMC + "==" + msgctx.getProperty(keyMC));
}
// pintamos los roles que tiene asignado el usuario
CarbonContext carbonctx = CarbonContext.getThreadLocalCarbonContext();
String[] roles = carbonctx.getUserRealm().getUserStoreManager().getRoleNames();
for(String role:roles) {
System.out.println("ROLE_WSO2..." + role);
}
System.out.println("....FIN_TRAZEO DATOS...............");
} catch (Exception e) {
LOGGER.debug("ERROR TRAZEANDO DATOS VALIDACION USER:" + e.getMessage());
}
}
private Map<String,String> toMap(String[] array) {
Map<String,String> mapa = new HashMap<String,String>();
if (array!=null) {
for (String val : array) {
mapa.put(val, val);
}
}
return mapa;
}
}
İlgili konular
- 1. WSO2 ESB
- 2. OpenID ile çalışmaya başlama
- 3. Web soketleriyle çalışmaya başlama
- 4. Syntaxnet ile çalışmaya başlama
- 5. Elastic ile çalışmaya başlama scala istemcisini kullanarak
- 6. WSO2 ESB: zaman aşımından sonra HTTP isteğini yeniden deneyin
- 7. Computer Vision ile çalışmaya başlama
- 8. Android'de WiFi ile çalışmaya başlama
- 9. jquery datepicker ile çalışmaya başlama
- 10. Checkstyle özel kuralı Hudson/Jenkins'de çalışmaya başlama
- 11. Latex Beamer ile çalışmaya başlama Şablon düzenleme
- 12. Node, Express ve Bootstrap ile çalışmaya başlama
- 13. Önceden Var Olan bir Projede Çalışmaya Başlama
- 14. Sabun web hizmetini wso2 ESB'de Rest haline dönüştürme ESB
- 15. Nasıl WSO2 tarafından json csv dönüştürmek ESB Smook
- 16. Sorunlar Harici CSS dosyalarını ExtJS 6 ile Çalışmaya Başlama
- 17. WSO2 IS ve WSO2 ESB ürünleri için tek bir kurulum var mı?
- 18. MacRuby ve Xcode 4.2 ile çalışmaya başlama 4.2
- 19. Telend ESB benzersiz mesaj numarası
- 20. wso2 ürünlerini nasıl birleştirirsiniz?
- 21. WSO2
- 22. WSO2
- 23. wso2-esb Kümelemeden sonra, her karbon konsolu (yönetim ve çalışan) çalışmıyor
- 24. Wso2 Windows olarak çalıştırılan ürünler Servis
- 25. WSO2 Kimlik Sunucusu Yetkilendirme Hizmeti
- 26. istisna stratejisi Katır ESB
- 27. Zorla durduktan sonra servise başlama
- 28. ajax (WSO2 APIManager1.10) kullanarak belirteç belirleme
- 29. Soğuk Başlama Performansı WPF
- 30. SLIME ve SWANK ile çalışmaya başlama: Lisp bağlantısı beklenmedik şekilde kapatıldı: bağlantı uzak eş tarafından bozuldu
Cevabınız için teşekkür ederim için kod. Güvenlikle ilgili blog yayını, WS için olan ancak REST hizmetleri için olmayan UsernameToken güvenlik profilini açıklıyor. –
Umarım "XACML ile RESTful Hizmetlerine İnce Taneli Yetkilendirme" için yeni bağlantı size bazı yararlı ipuçları verir. –
Yeni bağlantıdaki örnek kullaniciadiToken güvenliği ile mi çalışacak yoksa XACML kullanmalı mıyım? – Ivo