Use ALGO_ID_C14N11_OMIT_COMMENTS in xades4j - canonicalization

I need to sign my documents using ALGO_ID_C14N11_OMIT_COMMENTS and ALGO_ID_C14N11_WITH_COMMENTS canonicalization. Can you tell me what should I change to xades4j to permit this (Isimply need xades_bes and xades_t, no verification by now).
Should I create a wrapper class in xades4j.algorithms like the already present? and then?

You can create the derived class or use the GenericAlgorithm class and pass the algorithm uri.
Then you need to configure the algorithms provider on the signing profile that you're using to create signers. You can define a new provider or maybe extend the default and override the needed methods. To register the provider on the signing profile you use the withAlgorithmsProviderEx method.

Related

Proper way to customize Spark ML estimator (e.g. GaussianMixture) by modified its private method?

My code use apache.ml.clustering.GaussianMixture, but its init method private def initRandom(...) does not work well, so I want to customize a new init method.
At first I want to "extends" class GuassianMixture, but initRandom is a private method.
Then I tried another way, it is to set initial GMM, but sadly source code says that TODO: SPARK-15785 Support users supplied initial GMM.
I've also tried to copy the code of class GuassianMixture for my custom class, but there are too many things attached to it. GaussianMixture.scala comes with sort of classes and traits, some of which are only accessible within ML packages.
I solved it by myself. Here is my solution.
I created class CustomGaussianMixture which extends GaussianMixture from official package org.apache.spark.ml.clustering.
And within my project, I created a new package, also named as org.apache.spark.ml.clustering(to prevent deal with scope of sort of complexity classes/traits/objects in org.apache.spark.ml.clustering). And place my custom class in it.
The next thing is to override the method(fit) call initRandom, a non-private method, so I can override it. Specifically, Just write my new init method in class CustomGaussianMixture, and copy method fit from official source code in GaussianMixture.scala to class CustomGaussianMixture, remember to modify code in CustomGaussianMixture.fit() to call my custom init method.
At last, just use CustomGaussianMixture instead of GaussianMixture when needed.

Can Kafka be provided with custom LoginModule to support LDAP?

Kafka can be configured to use several authentication mechanisms: plaintext username/password, Kerberos or SSL. The first 2 use SASL, where there is a JAAS config file required.
For the plain text auth method, the config looks like (taken from the documentation):
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="admin-secret"
user_admin="admin-secret"
user_alice="alice-secret";
};
I want to authenticate if possible using LDAP. My question is this: if I replace the PlainLoginModule with a class that implements LoginModule and place this class in the broker's classpath, can I implement authentication in any manner I wish (i.e. LDAP)?
I cannot use Kerberos in a reasonable fashion because of the way its principals are defined within the organisation where I'm working, hence I wish to use LDAP as I need to support RBAC.
Yes you can provide Kafka with a custom class that implements LoginModule and have the authentication logic you want in it.
Then update the JAAS file with your class name and make sure it's in the classpath.
You'll need to put some boilerplate code to get everything setup correctly but you can use PlainLoginModule, PlainSaslServerProvider, PlainSaslServerFactory and PlainSaslServer as examples.
Your LoginModule class should have the same logic as PlainLoginModule but instead initialize your Provider implementation (in the static block).
Your Provider class should have the same logic as PlainSaslServerProvider but instead reference your SaslServerFactory implementation.
Your SaslFactory class should again have the same logic as PlainSaslServerFactory but create an instance of your SaslServer implementation.
Finally your SaslServer class should implement the necessary LDAP logic in its evaluateResponse() method. Just be sure to set correctly set this.authorizationId as this will become the user principal and set complete to true (like PlainSaslServer.evaluateResponse() does)

Authenticating/authorizing access to tastypie top level API schema

I know how to setup authentication/authortization for tastypie resources: via settings in the resource Meta class. How do I authenticate/authorize access to the top-level schema though?
For example, I can authenticate/authorize the resource at /api/v1/resource, but how do I authenticate/authorize the schema at /api/v1?
There is no easy way to do this by default with tastypie's default mechanisms. If you look inside api.py file you will see that the top_level method doesn't have the authentication/authorization mechanism applied.
I think the cleanest way to achieve what you want would be by extending the Api class and overriding the top_level method to check that the user is allowed to see the result.
This however may be overcomplicated becuase the Api itself doesn't use the autorisation and authentication methods. So you may want to override the Api's urls method by removing the top_level definition there and putting it inside the urls in your Resources.
I had to solve this problem as well. Here's a code example of Anna's suggestion:
class ApiWithAuth(Api):
def top_level(self, request, api_name=None):
auth = MyAuthentication()
r = auth.is_authenticated(request)
if r != True:
return r
return super(ApiWithAuth, self).top_level(request, api_name)
api = ApiWithAuth(api_name='v2')
api.register(MyResource())
api.register(MyOtherResource())
...

GWT: Replace AbstractPlaceHistoryMapper with a custom mapper using deferred binding

Looks like the class that is generated for PlaceHistoryMapper is hard-coded to use AbstractPlaceHistoryMapper as the super class.
So, I am trying to work around this by trying to replace this AbstractPlaceHistoryMapper with a custom mapper of mine using deferred binding . I am using the following rule in my *.gwt.xml:
<replace-with class="com.google.gwt.place.impl.AbstractPlaceHistoryMapper">
<when-type-is class="com.test.sampleapp.CustomPlaceHistoryMapper" />
</replace-with>
But for some reason the replace does not seem to be happening. CustomPlaceHistoryMapper is not getting kicked in and the generated class still uses AbstractPlaceHistoryMapper.
Any thoughts/pointers as to what might be resulting this behavior are much appreciated.
Note: I have also posted this on the GWT group but haven't received an answer so far.
To make the deferred binding work a class must be created with GWT.create(). However, AbstractPlaceHistoryMapper is only used as an extended class. So it will never be created via GWT.create, but always by instantiation the subclass. And therefor deferred binding won't work in this case. If you want a complete different implementation you have to implement a custom PlaceHistoryMapper, and manage the known tokens yourself. This also means you can't use the History annotations either.
As a side note the classnames in your rule should be swapped. But for the end result this doesn't matter, since it won't work in the first place.
It is absolutely possible to have custom history tokens (eg. #mail or #mail/bla instead of only #mail:inbox) using the out-of-the-box Place-related classes that GWT (2.0) provides.
Instead of replacing AbstractPlaceHistoryMapper you could instantiate the default PlaceHistoryMapper passing in it's constructor your implementation of PlaceHistoryMapper<T> or PlaceHistoryMapperWithFactory<T>.
eg.:
final PlaceHistoryHandler placeHistoryHandler = new PlaceHistoryHandler(new CustomHistoryMapper());
You will be able then to map tokens as you wish.
I personally recommend you to use an unique PlaceTokenizer in you mapper custom implementation so that I dont have to have an inner PlaceTokenizer class in each of your Places.
Hope that helps. Feel free to ask any doubts.

Can I set the Database adapter to use permanently from within a Zend_Db_Table_Abstract Class?

I have 2 databases that my site uses including a central user database that relates to other site-specific databases.
Sometimes it is adequate to call new User(array('db'=>'adapter1')); (but never convenient); other times, though, such as when declaring relationships between tables on different databases, there is no way to do this.
Does anyone know a way to specify which database adapter to use from within the Zend_Db_Table_Abstract class?
Thanks!
Getting back to this pretty late, but none of the answers here quite did it for me. A select few of my database models needed to use 'tdb' and the following code was added to each of those classes to have that happen automatically:
protected function _setupDatabaseAdapter()
{
$this->_db = Zend_Registry::get('tdb');
parent::_setupDatabaseAdapter();
}
I thank you all for your suggestions along the way!
Zend_Db_Table_Abstract provides a static method to set the default database adapter. Do this as follows:
Zend_Db_Table_Abstract::setDefaultAdapter($adapter);
Now, all your Table objects will use your adapter by default.
Note: the online docs sometimes don't make this obvious, so your second best place to check is in the API here: http://framework.zend.com/apidoc/core/
You could set the class variable $_db to the correct adapter in the constructor.
global $adapter1; //There are better ways than using a global variable
$this->_db = $adapter1;
Assuming the adapter object can be referenced in the constructor. That doesn't seem to portable, but I believe it would work.
The init function can be used, it is not used in Zend_Db_Adapter_Abstract, can be used in your class to setup whatever needs to be done. _setAdapter accepts a string naming a Registry Key.
public function init()
{
$this->_setAdapter('tdb');
}