Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * <copyright>
- * Copyright (c) 2003-2013 SETECH Inc. All Rights Reserved.
- * 903 Industrial Drive, Murfreesboro, TN 37129.
- *
- * This file is part of SETECH MROVelocity Hub
- * </copyright>
- *
- * $Id$
- */
- package com.setech.mrovelocityhub.services.security.model;
- import java.util.List;
- import org.apache.commons.lang3.builder.ToStringBuilder;
- import org.springframework.security.core.GrantedAuthority;
- import com.setech.mrovelocityhub.persistence.security.model.AuthorizationValue;
- /**
- *
- * @version $Revision$
- * @since 7.0.0
- */
- public class SessionUserGrantedAuthority implements GrantedAuthority {
- private static final long serialVersionUID = -3937521692967089258L;
- private String authority;
- private List<Long> values;
- /**
- * @param authority
- */
- public SessionUserGrantedAuthority(String authority, List<Long> values) {
- this.authority = authority;
- this.values = values;
- }
- /* (non-Javadoc)
- * @see org.springframework.security.core.GrantedAuthority#getAuthority()
- */
- @Override
- public String getAuthority() {
- return authority;
- }
- /**
- * @return
- */
- public List<Long> getValues() {
- return values;
- }
- /**
- * @param value
- * @return
- */
- public boolean hasValue(Long value) {
- // No value specified and no values provided for the role,
- // then the user is permitted with no restrictions.
- if(value == null && values.size() == 0)
- return true;
- // if value is null but there are values to restrict the
- // authority, then indicate that the match failed.
- if(value == null)
- return false;
- // If the values contains the ALL indicator, no need to then
- // check the specified value, allow it.
- if(values.contains(AuthorizationValue.ALL))
- return true;
- // check if the value exists in the collection.
- return values.contains((Long)value);
- }
- /**
- * @param values
- * @return
- */
- public boolean hasAllValues(List<Long> values) {
- // if the input is null but values contain values,
- // then indicate that specified values were not
- // found.
- if(values == null && this.values.size() != 0)
- return false;
- // if the input contains the ALL indicator
- if(values.contains(AuthorizationValue.ALL))
- return true;
- // check all specific values match
- for(Long value : values) {
- if(!hasValue(value))
- return false;
- }
- return true;
- }
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return new ToStringBuilder(this)
- .append("authority", authority)
- .append("values", values)
- .toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment