Example usage for java.security Identity getName

List of usage examples for java.security Identity getName

Introduction

In this page you can find the example usage for java.security Identity getName.

Prototype

public final String getName() 

Source Link

Document

Returns this identity's name.

Usage

From source file:ch.bfh.evoting.alljoyn.BusHandler.java

/**
 * Helper method extracting an identity from a received message
 * @param messageObject the original message received
 *///  w  w  w .  j a  v a  2  s.  co  m
private void extractIdentity(AllJoynMessage messageObject) {
    Log.d(TAG, "Exctracting identity " + messageObject.getMessage());

    //Get the name and its corresponding key key
    StringTokenizer tokenizer = new StringTokenizer(messageObject.getMessage(), MESSAGE_PARTS_SEPARATOR);
    if (tokenizer.countTokens() != 2) {
        //malformed string
        Log.d(TAG, "String was not composed of 2 parts");
        return;
    }

    String peerId = messageObject.getSender();
    //then peerName
    String peerName = (String) tokenizer.nextElement();
    //and finally peerKey
    String peerKey = (String) tokenizer.nextElement();

    Identity newIdentity = new Identity(peerName, messageAuthenticater.decodePublicKey(peerKey));

    //Check if identity is already known
    if (identityMap.containsKey(peerId)) {
        //if yes, check if the same identity as received before
        if (!identityMap.get(peerId).equals(newIdentity)) {
            //If not someone is trying to impersonate somebody else
            Intent intent = new Intent("attackDetected");
            intent.putExtra("type", 1);
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
            Log.e(TAG, "Two different data received for peer " + peerId);
            return;
        }
    } else {
        boolean verification = messageObject.verifyMessage(newIdentity.getPublicKey());
        if (verification) {
            //Save the new identity
            Log.d(TAG, "identity received " + newIdentity.getName());
            identityMap.put(peerId, newIdentity);
            this.sendMyIdentity();
            //Update the UI
            LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("participantStateUpdate"));

            if (peerId.equals(signatureVerificationTask.getSender())) {
                verifySignatureSalt();
            }
        } else {
            Log.e(TAG, "Wrong signature for identiy message from " + peerId);
            return;
        }
    }
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

protected void bindIdentity(GrailsDomainClass domainClass, RootClass root, Mappings mappings,
        Mapping gormMapping, String sessionFactoryBeanName) {

    GrailsDomainClassProperty identifierProp = domainClass.getIdentifier();
    if (gormMapping == null) {
        bindSimpleId(identifierProp, root, mappings, null, sessionFactoryBeanName);
        return;//  w  w w.  j a  v  a2s  .c om
    }

    Object id = gormMapping.getIdentity();
    if (id instanceof CompositeIdentity) {
        bindCompositeId(domainClass, root, (CompositeIdentity) id, mappings, sessionFactoryBeanName);
    } else {
        final Identity identity = (Identity) id;
        String propertyName = identity.getName();
        if (propertyName != null) {
            GrailsDomainClassProperty namedIdentityProp = domainClass.getPropertyByName(propertyName);
            if (namedIdentityProp == null) {
                throw new MappingException("Mapping specifies an identifier property name that doesn't exist ["
                        + propertyName + "]");
            }
            if (!namedIdentityProp.equals(identifierProp)) {
                identifierProp = namedIdentityProp;
            }
        }
        bindSimpleId(identifierProp, root, mappings, identity, sessionFactoryBeanName);
    }
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

public Mapping evaluateMapping(GrailsDomainClass domainClass, Closure<?> defaultMapping, boolean cache) {
    try {/*  w ww  . j a v a 2  s  . c om*/
        Object o = GrailsClassUtils.getStaticPropertyValue(domainClass.getClazz(),
                GrailsDomainClassProperty.MAPPING);
        if (o != null || defaultMapping != null) {
            HibernateMappingBuilder builder = new HibernateMappingBuilder(domainClass.getFullName());
            GrailsApplication application = domainClass.getApplication();
            ApplicationContext ctx = null;
            if (application != null) {
                ctx = application.getMainContext();
                if (ctx == null)
                    ctx = application.getParentContext();
            }

            Mapping m = null;
            if (defaultMapping != null) {
                m = builder.evaluate(defaultMapping, ctx);
            }

            if (o instanceof Closure) {
                m = builder.evaluate((Closure<?>) o, ctx);
            }

            final Object identity = m.getIdentity();
            if (identity instanceof Identity) {
                final Identity identityObject = (Identity) identity;
                final String idName = identityObject.getName();
                if (idName != null && !GrailsDomainClassProperty.IDENTITY.equals(idName)) {
                    GrailsDomainClassProperty persistentProperty = domainClass.getPersistentProperty(idName);
                    if (!persistentProperty.isIdentity()) {
                        if (persistentProperty instanceof DefaultGrailsDomainClassProperty) {
                            ((DefaultGrailsDomainClassProperty) persistentProperty).setIdentity(true); // fixed for 2.2
                        }
                    }
                }
            }

            trackCustomCascadingSaves(m, domainClass.getPersistentProperties());

            if (cache) {
                MAPPING_CACHE.put(domainClass.getClazz(), m);
            }
            return m;
        }
        return null;
    } catch (Exception e) {
        throw new GrailsDomainException("Error evaluating ORM mappings block for domain ["
                + domainClass.getFullName() + "]:  " + e.getMessage(), e);
    }
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

protected void bindIdentity(HibernatePersistentEntity domainClass, RootClass root,
        InFlightMetadataCollector mappings, Mapping gormMapping, String sessionFactoryBeanName) {

    PersistentProperty identifierProp = domainClass.getIdentity();
    if (gormMapping == null) {
        if (identifierProp != null) {
            bindSimpleId(identifierProp, root, mappings, null, sessionFactoryBeanName);
        }//w  w w  .  jav a  2 s. c  om
        return;
    }

    Object id = gormMapping.getIdentity();
    if (id instanceof CompositeIdentity) {
        bindCompositeId(domainClass, root, (CompositeIdentity) id, mappings, sessionFactoryBeanName);
    } else {
        final Identity identity = (Identity) id;
        String propertyName = identity.getName();
        if (propertyName != null) {
            PersistentProperty namedIdentityProp = domainClass.getPropertyByName(propertyName);
            if (namedIdentityProp == null) {
                throw new MappingException("Mapping specifies an identifier property name that doesn't exist ["
                        + propertyName + "]");
            }
            if (!namedIdentityProp.equals(identifierProp)) {
                identifierProp = namedIdentityProp;
            }
        }
        bindSimpleId(identifierProp, root, mappings, identity, sessionFactoryBeanName);
    }
}