Skip to content

Commit

Permalink
Fix security not work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
phuonghuynh committed Aug 25, 2015
1 parent e7cdca9 commit 7843ac0
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,34 @@

public class SwitchingAuthenticationProvider implements AuthenticationProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(SwitchingAuthenticationProvider.class);

private Map<SocialProvider, AuthenticationProvider> providers;

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
try {
SocialProvider socialProvider = SocialProvider.valueOf(authentication.getCredentials().toString());
if (socialProvider != null) {
AuthenticationProvider delegateTo = providers.get(socialProvider);
return delegateTo.authenticate(authentication);
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}

return providers.get(SocialProvider.VIETNAMWORKS).authenticate(authentication);
}
private static final Logger LOGGER = LoggerFactory.getLogger(SwitchingAuthenticationProvider.class);

public boolean supports(Class<?> authentication) {
return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication);
}
private Map<SocialProvider, AuthenticationProvider> providers;

public Map<SocialProvider, AuthenticationProvider> getProviders() {
return providers;
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
try {
SocialProvider socialProvider = SocialProvider.valueOf(authentication.getCredentials().toString());
if (socialProvider != null) {
AuthenticationProvider delegateTo = providers.get(socialProvider);
return delegateTo.authenticate(authentication);
}
}

public void setProviders(Map<SocialProvider, AuthenticationProvider> providers) {
this.providers = providers;
catch (Exception ex) {
LOGGER.debug(ex.getMessage(), ex);
}

return providers.get(SocialProvider.VIETNAMWORKS).authenticate(authentication);
}

public boolean supports(Class<?> authentication) {
return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication);
}

public Map<SocialProvider, AuthenticationProvider> getProviders() {
return providers;
}

public void setProviders(Map<SocialProvider, AuthenticationProvider> providers) {
this.providers = providers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface GoogleCalendarService {

WebinarInfoDto createWebinarInfo(WebinarInfoDto webinarInfoDto, String organiser) throws IOException;

Collection<WebinarInfoDto> findNotExpiredWebinars();
Collection<WebinarInfoDto> findAvailableWebinars();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
import com.techlooper.repository.vnw.VnwUserRepo;
import com.techlooper.service.GoogleCalendarService;
import org.dozer.Mapper;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramBuilder;
import org.elasticsearch.search.facet.datehistogram.DateHistogramFacetBuilder;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.integration.annotation.Aggregator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
Expand All @@ -27,56 +31,56 @@
@Service
public class GoogleCalendarServiceImpl implements GoogleCalendarService {

@Resource
private WebinarRepository webinarRepository;
@Resource
private WebinarRepository webinarRepository;

@Resource
private Mapper dozerMapper;
@Resource
private Mapper dozerMapper;

@Resource
private Calendar googleCalendar;
@Resource
private Calendar googleCalendar;

@Resource
private VnwUserRepo vnwUserRepo;
@Resource
private VnwUserRepo vnwUserRepo;

private static final String CALENDAR_ID = "[email protected]";
private static final String CALENDAR_ID = "[email protected]";

public WebinarInfoDto createWebinarInfo(WebinarInfoDto webinarInfoDto, String organiser) throws IOException {
VnwUser vnwUser = vnwUserRepo.findByUsernameIgnoreCase(organiser);
String organiserEmail = vnwUser != null ? vnwUser.getEmail() : organiser;
public WebinarInfoDto createWebinarInfo(WebinarInfoDto webinarInfoDto, String organiser) throws IOException {
VnwUser vnwUser = vnwUserRepo.findByUsernameIgnoreCase(organiser);
String organiserEmail = vnwUser != null ? vnwUser.getEmail() : organiser;

Event event = new Event()
.setSummary(webinarInfoDto.getName())
.setDescription(webinarInfoDto.getDescription());
Event event = new Event()
.setSummary(webinarInfoDto.getName())
.setDescription(webinarInfoDto.getDescription());

DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("dd/MM/yyyy hh:mm a");
org.joda.time.DateTime startDate = dateTimeFormatter.parseDateTime(webinarInfoDto.getStartDate());
org.joda.time.DateTime endDate = dateTimeFormatter.parseDateTime(webinarInfoDto.getEndDate());
event.setStart(new EventDateTime().setDateTime(new DateTime(startDate.toString())));
event.setEnd(new EventDateTime().setDateTime(new DateTime(endDate.toString())));
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("dd/MM/yyyy hh:mm a");
org.joda.time.DateTime startDate = dateTimeFormatter.parseDateTime(webinarInfoDto.getStartDate());
org.joda.time.DateTime endDate = dateTimeFormatter.parseDateTime(webinarInfoDto.getEndDate());
event.setStart(new EventDateTime().setDateTime(new DateTime(startDate.toString())));
event.setEnd(new EventDateTime().setDateTime(new DateTime(endDate.toString())));

webinarInfoDto.getAttendees().add(organiserEmail);
EventAttendee[] attendees = webinarInfoDto.getAttendees().stream()
.map(attEmail -> new EventAttendee().setEmail(attEmail))
.toArray(EventAttendee[]::new);
webinarInfoDto.getAttendees().add(organiserEmail);
EventAttendee[] attendees = webinarInfoDto.getAttendees().stream()
.map(attEmail -> new EventAttendee().setEmail(attEmail))
.toArray(EventAttendee[]::new);

event.setAttendees(Arrays.asList(attendees));
event.setAttendees(Arrays.asList(attendees));

event = googleCalendar.events().insert(CALENDAR_ID, event).setSendNotifications(true).execute();
event = googleCalendar.events().insert(CALENDAR_ID, event).setSendNotifications(true).execute();

WebinarEntity entity = dozerMapper.map(webinarInfoDto, WebinarEntity.class);
entity.setCalendarUrl(event.getHtmlLink());
entity.setHangoutLink(event.getHangoutLink());
WebinarEntity entity = dozerMapper.map(webinarInfoDto, WebinarEntity.class);
entity.setCalendarUrl(event.getHtmlLink());
entity.setHangoutLink(event.getHangoutLink());

entity.setOrganiser(organiserEmail);
entity.setOrganiser(organiserEmail);

entity = webinarRepository.save(entity);
return dozerMapper.map(entity, WebinarInfoDto.class);
}
entity = webinarRepository.save(entity);
return dozerMapper.map(entity, WebinarInfoDto.class);
}

public Collection<WebinarInfoDto> findNotExpiredWebinars() {
public Collection<WebinarInfoDto> findAvailableWebinars() {
AggregationBuilders.dateHistogram("availableWebinars").field("startDate").format("");


return null;
}
return null;
}
}
10 changes: 10 additions & 0 deletions src/main/webapp/assets/modules/common/json.val.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ techlooper.factory("jsonValue", function () {
name: "rootPage",
url: "/"
},
{
name: "home",
url: "/home",
ignoreIfLastFoot: true
},
{
name: "employerDashboard",
url: "/employer-dashboard",
ignoreIfLastFoot: true
},
{
name: "postEvent",
url: "/post-event",
Expand Down
7 changes: 6 additions & 1 deletion src/main/webapp/assets/modules/common/securityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ techlooper.factory("securityService", function (apiService, $rootScope, $q, util
},

routeByRole: function () {
utils.sendNotification(jsonValue.notifications.loaded);
var lastFoot = localStorageService.get("lastFoot");
if (lastFoot) {
localStorageService.remove("lastFoot");
return $location.url(lastFoot);

var uiView = utils.getUiView(lastFoot);
if (!uiView.ignoreIfLastFoot) {
return $location.url(lastFoot);
}
}

switch ($rootScope.userInfo.roleName) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/assets/modules/common/utils.fac.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ angular.module("Common").factory("utils", function (jsonValue, $location, $rootS

var instance = {

getUiView: function () {
var path = $location.path();
getUiView: function (pth) {
var path = pth || $location.path();
var rs = {};
$.each(jsonValue.uiViews, function (i, view) {
if ((view.regex === undefined && view.url === path) ||
Expand Down

0 comments on commit 7843ac0

Please sign in to comment.