use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class FileBasedGroupProviderImpl method addChildAsync.
@Override
protected <C extends ConfiguredObject> ListenableFuture<C> addChildAsync(Class<C> childClass, Map<String, Object> attributes) {
if (childClass == Group.class) {
String groupName = (String) attributes.get(ConfiguredObject.NAME);
if (getState() != State.ACTIVE) {
throw new IllegalConfigurationException(String.format("Group provider '%s' is not activated. Cannot create a group.", getName()));
}
_groupDatabase.createGroup(groupName);
Map<String, Object> attrMap = new HashMap<String, Object>();
UUID id = UUID.randomUUID();
attrMap.put(ConfiguredObject.ID, id);
attrMap.put(ConfiguredObject.NAME, groupName);
GroupAdapter groupAdapter = new GroupAdapter(attrMap);
groupAdapter.create();
return Futures.immediateFuture((C) groupAdapter);
} else {
return super.addChildAsync(childClass, attributes);
}
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class QueueArgumentsConverter method convertModelArgsToWire.
public static Map<String, Object> convertModelArgsToWire(Map<String, Object> modelArguments) {
Map<String, Object> wireArguments = new HashMap<>();
for (Map.Entry<String, String> entry : ATTRIBUTE_MAPPINGS.entrySet()) {
if (modelArguments.containsKey(entry.getValue())) {
Object value = modelArguments.get(entry.getValue());
if (value instanceof Enum) {
value = ((Enum) value).name();
} else if (value instanceof ConfiguredObject) {
value = ((ConfiguredObject) value).getName();
}
wireArguments.put(entry.getKey(), value);
}
}
if (MessageGroupType.SHARED_GROUPS.equals(modelArguments.get(Queue.MESSAGE_GROUP_TYPE))) {
wireArguments.put(QPID_SHARED_MSG_GROUP, SHARED_MSG_GROUP_ARG_VALUE);
}
return wireArguments;
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class SpnegoAuthenticator method doAuthenticate.
private AuthenticationResult doAuthenticate(final Subject subject, final byte[] negotiateToken) {
GSSContext context = null;
try {
final int credentialLifetime;
if (String.valueOf(System.getProperty(StandardSystemProperty.JAVA_VENDOR.key())).toUpperCase().contains("IBM")) {
credentialLifetime = GSSCredential.INDEFINITE_LIFETIME;
} else {
credentialLifetime = GSSCredential.DEFAULT_LIFETIME;
}
final GSSManager manager = GSSManager.getInstance();
final PrivilegedExceptionAction<GSSCredential> credentialsAction = () -> manager.createCredential(null, credentialLifetime, new Oid("1.3.6.1.5.5.2"), GSSCredential.ACCEPT_ONLY);
final GSSContext gssContext = manager.createContext(Subject.doAs(subject, credentialsAction));
context = gssContext;
final PrivilegedExceptionAction<byte[]> acceptAction = () -> gssContext.acceptSecContext(negotiateToken, 0, negotiateToken.length);
final byte[] outToken = Subject.doAs(subject, acceptAction);
if (outToken == null) {
LOGGER.debug("Ticket validation failed");
return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR);
}
final PrivilegedAction<String> authenticationAction = () -> {
if (gssContext.isEstablished()) {
GSSName gssName = null;
try {
gssName = gssContext.getSrcName();
} catch (final GSSException e) {
LOGGER.error("Unable to get src name from gss context", e);
}
if (gssName != null) {
return stripRealmNameIfRequired(gssName.toString());
}
}
return null;
};
final String principalName = Subject.doAs(subject, authenticationAction);
if (principalName != null) {
TokenCarryingPrincipal principal = new TokenCarryingPrincipal() {
private Map<String, String> _tokens = Collections.singletonMap(RESPONSE_AUTH_HEADER_NAME, NEGOTIATE_PREFIX + Base64.getEncoder().encodeToString(outToken));
@Override
public Map<String, String> getTokens() {
return _tokens;
}
@Override
public ConfiguredObject<?> getOrigin() {
return _kerberosProvider;
}
@Override
public String getName() {
return principalName;
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof TokenCarryingPrincipal)) {
return false;
}
final TokenCarryingPrincipal that = (TokenCarryingPrincipal) o;
if (!getName().equals(that.getName())) {
return false;
}
if (!getTokens().equals(that.getTokens())) {
return false;
}
return getOrigin() != null ? getOrigin().equals(that.getOrigin()) : that.getOrigin() == null;
}
@Override
public int hashCode() {
int result = getName().hashCode();
result = 31 * result + (getOrigin() != null ? getOrigin().hashCode() : 0);
result = 31 * result + getTokens().hashCode();
return result;
}
};
return new AuthenticationResult(principal);
}
return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR);
} catch (GSSException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ticket validation failed", e);
}
return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
} catch (PrivilegedActionException e) {
final Exception cause = e.getException();
if (cause instanceof GSSException) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Service login failed", e);
}
} else {
LOGGER.error("Service login failed", e);
}
return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
} finally {
if (context != null) {
try {
context.dispose();
} catch (GSSException e) {
// Ignore
}
}
}
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class PortFactoryTest method setUp.
@Before
public void setUp() throws Exception {
SystemConfig systemConfig = mock(SystemConfig.class);
_portNumber = findFreePort();
TaskExecutor executor = CurrentThreadTaskExecutor.newStartedInstance();
when(_authProvider.getName()).thenReturn(_authProviderName);
when(_broker.getChildren(eq(AuthenticationProvider.class))).thenReturn(Collections.singleton(_authProvider));
when(_broker.getCategoryClass()).thenReturn(Broker.class);
when(_broker.getEventLogger()).thenReturn(new EventLogger());
when(_broker.getParent()).thenReturn(systemConfig);
when(_broker.getTypeClass()).thenReturn(Broker.class);
ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
when(_broker.getObjectFactory()).thenReturn(objectFactory);
when(_broker.getModel()).thenReturn(objectFactory.getModel());
when(_authProvider.getModel()).thenReturn(objectFactory.getModel());
when(_authProvider.getObjectFactory()).thenReturn(objectFactory);
when(_authProvider.getCategoryClass()).thenReturn(AuthenticationProvider.class);
when(_authProvider.getMechanisms()).thenReturn(Arrays.asList("PLAIN"));
when(_keyStore.getModel()).thenReturn(objectFactory.getModel());
when(_keyStore.getObjectFactory()).thenReturn(objectFactory);
when(_trustStore.getModel()).thenReturn(objectFactory.getModel());
when(_trustStore.getObjectFactory()).thenReturn(objectFactory);
for (ConfiguredObject obj : new ConfiguredObject[] { _authProvider, _broker, _keyStore, _trustStore }) {
when(obj.getTaskExecutor()).thenReturn(executor);
when(obj.getChildExecutor()).thenReturn(executor);
}
_factory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
_attributes.put(Port.ID, _portId);
_attributes.put(Port.NAME, getTestName());
_attributes.put(Port.PORT, _portNumber);
_attributes.put(Port.TRANSPORTS, _tcpStringSet);
_attributes.put(Port.AUTHENTICATION_PROVIDER, _authProviderName);
_attributes.put(Port.TCP_NO_DELAY, "true");
_attributes.put(Port.BINDING_ADDRESS, "127.0.0.1");
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class AbstractJDBCConfigurationStore method upgradeFromV7.
private void upgradeFromV7(ConfiguredObject<?> parent) throws SQLException {
@SuppressWarnings("serial") Map<String, String> defaultExchanges = new HashMap<String, String>() {
{
put("amq.direct", "direct");
put("amq.topic", "topic");
put("amq.fanout", "fanout");
put("amq.match", "headers");
}
};
Connection connection = newConnection();
try {
String virtualHostName = parent.getName();
UUID virtualHostId = UUIDGenerator.generateVhostUUID(virtualHostName);
String stringifiedConfigVersion = "0." + DEFAULT_CONFIG_VERSION;
boolean tableExists = tableExists(getConfigurationVersionTableName(), connection);
if (tableExists) {
int configVersion = getConfigVersion(connection);
getLogger().debug("Upgrader read existing config version {}", configVersion);
stringifiedConfigVersion = "0." + configVersion;
}
Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
virtualHostAttributes.put("modelVersion", stringifiedConfigVersion);
virtualHostAttributes.put("name", virtualHostName);
ConfiguredObjectRecord virtualHostRecord = new ConfiguredObjectRecordImpl(virtualHostId, "VirtualHost", virtualHostAttributes);
insertConfiguredObject(virtualHostRecord, connection);
getLogger().debug("Upgrader created VirtualHost configuration entry with config version {}", stringifiedConfigVersion);
Map<UUID, Map<String, Object>> bindingsToUpdate = new HashMap<UUID, Map<String, Object>>();
List<UUID> others = new ArrayList<UUID>();
final ObjectMapper objectMapper = ConfiguredObjectJacksonModule.newObjectMapper(true);
PreparedStatement stmt = connection.prepareStatement("SELECT id, object_type, attributes FROM " + getConfiguredObjectsTableName());
try {
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
UUID id = UUID.fromString(rs.getString(1));
String objectType = rs.getString(2);
if ("VirtualHost".equals(objectType)) {
continue;
}
Map<String, Object> attributes = objectMapper.readValue(getBlobAsString(rs, 3), Map.class);
if (objectType.endsWith("Binding")) {
bindingsToUpdate.put(id, attributes);
} else {
if (objectType.equals("Exchange")) {
defaultExchanges.remove((String) attributes.get("name"));
}
others.add(id);
}
}
} catch (IOException e) {
throw new StoreException("Error recovering persistent state: " + e.getMessage(), e);
}
} finally {
stmt.close();
}
stmt = connection.prepareStatement("INSERT INTO " + getConfiguredObjectHierarchyTableName() + " ( child_id, parent_type, parent_id) VALUES (?,?,?)");
try {
for (UUID id : others) {
stmt.setString(1, id.toString());
stmt.setString(2, "VirtualHost");
stmt.setString(3, virtualHostId.toString());
stmt.execute();
}
for (Map.Entry<UUID, Map<String, Object>> bindingEntry : bindingsToUpdate.entrySet()) {
stmt.setString(1, bindingEntry.getKey().toString());
stmt.setString(2, "Queue");
stmt.setString(3, bindingEntry.getValue().remove("queue").toString());
stmt.execute();
stmt.setString(1, bindingEntry.getKey().toString());
stmt.setString(2, "Exchange");
stmt.setString(3, bindingEntry.getValue().remove("exchange").toString());
stmt.execute();
}
} finally {
stmt.close();
}
for (Map.Entry<String, String> defaultExchangeEntry : defaultExchanges.entrySet()) {
UUID id = UUIDGenerator.generateExchangeUUID(defaultExchangeEntry.getKey(), virtualHostName);
Map<String, Object> exchangeAttributes = new HashMap<String, Object>();
exchangeAttributes.put("name", defaultExchangeEntry.getKey());
exchangeAttributes.put("type", defaultExchangeEntry.getValue());
exchangeAttributes.put("lifetimePolicy", "PERMANENT");
Map<String, UUID> parents = Collections.singletonMap("VirtualHost", virtualHostRecord.getId());
ConfiguredObjectRecord exchangeRecord = new org.apache.qpid.server.store.ConfiguredObjectRecordImpl(id, "Exchange", exchangeAttributes, parents);
insertConfiguredObject(exchangeRecord, connection);
}
stmt = connection.prepareStatement("UPDATE " + getConfiguredObjectsTableName() + " set object_type =?, attributes = ? where id = ?");
try {
for (Map.Entry<UUID, Map<String, Object>> bindingEntry : bindingsToUpdate.entrySet()) {
stmt.setString(1, "Binding");
byte[] attributesAsBytes = objectMapper.writeValueAsBytes(bindingEntry.getValue());
ByteArrayInputStream bis = new ByteArrayInputStream(attributesAsBytes);
stmt.setBinaryStream(2, bis, attributesAsBytes.length);
stmt.setString(3, bindingEntry.getKey().toString());
stmt.execute();
}
} catch (IOException e) {
throw new StoreException("Error recovering persistent state: " + e.getMessage(), e);
} finally {
stmt.close();
}
if (tableExists) {
dropConfigVersionTable(connection);
}
connection.commit();
} catch (SQLException e) {
try {
connection.rollback();
} catch (SQLException re) {
}
throw e;
} finally {
connection.close();
}
}
Aggregations