Example usage for org.springframework.security.core.token Token getExtendedInformation

List of usage examples for org.springframework.security.core.token Token getExtendedInformation

Introduction

In this page you can find the example usage for org.springframework.security.core.token Token getExtendedInformation.

Prototype

String getExtendedInformation();

Source Link

Document

Obtains the extended information associated within the token, which was presented when the token was first created.

Usage

From source file:org.ihtsdo.otf.refset.security.RefsetIdentityService.java

/**
 * Gets a minimal {@link Authentication} object from {@link Token}. 
 * It is only possible if that Token exist. At the moment ROLE_USER is defaulted
 * @return/*from  ww  w.jav a2  s .c  o m*/
 */
protected Authentication getPrincipal(Token token) {

    String info = token.getExtendedInformation();
    String[] details = StringUtils.split(info, ":");

    User user = new User();
    user.setPassword(details[1]);
    user.setUsername(details[0]);
    user.setAuthenticated(true);
    user.setEnabled(true);
    Collection<RefsetRole> roles = new ArrayList<RefsetRole>();

    RefsetRole role = new RefsetRole();
    role.setAuthority(ROLE_USER);
    roles.add(role);

    user.setAuthorities(roles);

    Authentication auth = new UsernamePasswordAuthenticationToken(user, details[1], roles);

    return auth;
}